Skip to content

Commit 86527db

Browse files
committed
WIP
1 parent c391ac0 commit 86527db

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

amalgam.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const quickjs_h = loadFile("quickjs.h")
1616
const quickjs_libc_c = loadFile("quickjs-libc.c")
1717
const quickjs_libc_h = loadFile("quickjs-libc.h")
1818
const quickjs_opcode_h = loadFile("quickjs-opcode.h")
19+
const xsum_c = loadFile("xsum.c")
20+
const xsum_h = loadFile("xsum.h")
1921
const gen_builtin_array_fromasync_h = loadFile("gen/builtin-array-fromasync.h")
2022

2123
let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n"
@@ -27,11 +29,13 @@ let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU
2729
+ libunicode_h // exports lre_is_id_start, used by libregexp.h
2830
+ libregexp_h
2931
+ libunicode_table_h
32+
+ xsum_h
3033
+ quickjs_h
3134
+ quickjs_c
3235
+ cutils_c
3336
+ libregexp_c
3437
+ libunicode_c
38+
+ xsum_c
3539
+ "#ifdef QJS_BUILD_LIBC\n"
3640
+ quickjs_libc_h
3741
+ quickjs_libc_c

fuzz.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cutils.c"
55
#include "libregexp.c"
66
#include "libunicode.c"
7+
#include "xsum.c"
78
#include <stdlib.h>
89

910
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ qjs_srcs = files(
135135
'libregexp.c',
136136
'libunicode.c',
137137
'quickjs.c',
138+
'xsum.c'
138139
)
139140
qjs_hdrs = files(
140141
'quickjs.h',

quickjs.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13781,7 +13781,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
1378113781
break;
1378213782
case OP_neg:
1378313783
if (v64 == 0) {
13784-
sp[-1] = __JS_NewFloat64(-0.0);
13784+
sp[-1] = js_float64(-0.0);
1378513785
return 0;
1378613786
} else {
1378713787
v64 = -v64;
@@ -13877,7 +13877,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx,
1387713877
default:
1387813878
abort();
1387913879
}
13880-
sp[-1] = __JS_NewFloat64(d);
13880+
sp[-1] = js_float64(d);
1388113881
}
1388213882
break;
1388313883
}
@@ -14019,28 +14019,28 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1401914019
case OP_mul:
1402014020
v = (int64_t)v1 * (int64_t)v2;
1402114021
if (v == 0 && (v1 | v2) < 0) {
14022-
sp[-2] = __JS_NewFloat64(-0.0);
14022+
sp[-2] = js_float64(-0.0);
1402314023
return 0;
1402414024
}
1402514025
break;
1402614026
case OP_div:
14027-
sp[-2] = JS_NewFloat64(ctx, (double)v1 / (double)v2);
14027+
sp[-2] = js_number((double)v1 / (double)v2);
1402814028
return 0;
1402914029
case OP_mod:
1403014030
if (v1 < 0 || v2 <= 0) {
14031-
sp[-2] = JS_NewFloat64(ctx, fmod(v1, v2));
14031+
sp[-2] = js_number(fmod(v1, v2));
1403214032
return 0;
1403314033
} else {
1403414034
v = (int64_t)v1 % (int64_t)v2;
1403514035
}
1403614036
break;
1403714037
case OP_pow:
14038-
sp[-2] = JS_NewFloat64(ctx, js_math_pow(v1, v2));
14038+
sp[-2] = js_number(js_math_pow(v1, v2));
1403914039
return 0;
1404014040
default:
1404114041
abort();
1404214042
}
14043-
sp[-2] = JS_NewInt64(ctx, v);
14043+
sp[-2] = js_int64(v);
1404414044
} else if ((tag1 == JS_TAG_SHORT_BIG_INT || tag1 == JS_TAG_BIG_INT) &&
1404514045
(tag2 == JS_TAG_SHORT_BIG_INT || tag2 == JS_TAG_BIG_INT)) {
1404614046
JSBigInt *p1, *p2, *r;
@@ -14111,7 +14111,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1411114111
default:
1411214112
abort();
1411314113
}
14114-
sp[-2] = __JS_NewFloat64(dr);
14114+
sp[-2] = js_float64(dr);
1411514115
}
1411614116
return 0;
1411714117
exception:
@@ -14135,7 +14135,7 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp)
1413514135
double d1, d2;
1413614136
d1 = JS_VALUE_GET_FLOAT64(op1);
1413714137
d2 = JS_VALUE_GET_FLOAT64(op2);
14138-
sp[-2] = __JS_NewFloat64(d1 + d2);
14138+
sp[-2] = js_float64(d1 + d2);
1413914139
return 0;
1414014140
}
1414114141
/* fast path for short bigint */
@@ -14227,7 +14227,7 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp)
1422714227
}
1422814228
if (JS_ToFloat64Free(ctx, &d2, op2))
1422914229
goto exception;
14230-
sp[-2] = __JS_NewFloat64(d1 + d2);
14230+
sp[-2] = js_float64(d1 + d2);
1423114231
}
1423214232
return 0;
1423314233
exception:
@@ -14388,7 +14388,7 @@ static no_inline __exception int js_binary_logic_slow(JSContext *ctx,
1438814388
default:
1438914389
abort();
1439014390
}
14391-
sp[-2] = JS_NewInt32(ctx, r);
14391+
sp[-2] = js_int32(r);
1439214392
}
1439314393
return 0;
1439414394
exception:

0 commit comments

Comments
 (0)