Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ typedef struct JSVarDef {
uint8_t is_const : 1;
uint8_t is_lexical : 1;
uint8_t is_captured : 1;
uint8_t is_static_private : 1; /* only used during private class field parsing */
uint8_t var_kind : 4; /* see JSVarKindEnum */
/* only used during compilation: function pool index for lexical
variables with var_kind =
Expand Down Expand Up @@ -20098,7 +20099,7 @@ static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,

/* add a private field variable in the current scope */
static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
JSAtom name, JSVarKindEnum var_kind)
JSAtom name, JSVarKindEnum var_kind, BOOL is_static)
{
JSContext *ctx = s->ctx;
JSVarDef *vd;
Expand All @@ -20110,6 +20111,7 @@ static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
vd = &fd->vars[idx];
vd->is_lexical = 1;
vd->is_const = 1;
vd->is_static_private = is_static;
return idx;
}

Expand Down Expand Up @@ -21139,20 +21141,23 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
JSFunctionDef *method_fd;

if (is_private) {
int idx, var_kind;
int idx, var_kind, is_static1;
idx = find_private_class_field(ctx, fd, name, fd->scope_level);
if (idx >= 0) {
var_kind = fd->vars[idx].var_kind;
is_static1 = fd->vars[idx].is_static_private;
if (var_kind == JS_VAR_PRIVATE_FIELD ||
var_kind == JS_VAR_PRIVATE_METHOD ||
var_kind == JS_VAR_PRIVATE_GETTER_SETTER ||
var_kind == (JS_VAR_PRIVATE_GETTER + is_set)) {
var_kind == (JS_VAR_PRIVATE_GETTER + is_set) ||
(var_kind == (JS_VAR_PRIVATE_GETTER + 1 - is_set) &&
is_static != is_static1)) {
goto private_field_already_defined;
}
fd->vars[idx].var_kind = JS_VAR_PRIVATE_GETTER_SETTER;
} else {
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_GETTER + is_set) < 0)
JS_VAR_PRIVATE_GETTER + is_set, is_static) < 0)
goto fail;
}
if (add_brand(s, &class_fields[is_static]) < 0)
Expand All @@ -21178,7 +21183,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
emit_atom(s, setter_name);
ret = add_private_class_field(s, fd, setter_name,
JS_VAR_PRIVATE_SETTER);
JS_VAR_PRIVATE_SETTER, is_static);
JS_FreeAtom(ctx, setter_name);
if (ret < 0)
goto fail;
Expand Down Expand Up @@ -21213,7 +21218,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto private_field_already_defined;
}
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_FIELD) < 0)
JS_VAR_PRIVATE_FIELD, is_static) < 0)
goto fail;
emit_op(s, OP_private_symbol);
emit_atom(s, name);
Expand Down Expand Up @@ -21328,7 +21333,7 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
goto fail;
}
if (add_private_class_field(s, fd, name,
JS_VAR_PRIVATE_METHOD) < 0)
JS_VAR_PRIVATE_METHOD, is_static) < 0)
goto fail;
emit_op(s, OP_set_home_object);
emit_op(s, OP_set_name);
Expand Down Expand Up @@ -23022,6 +23027,8 @@ static __exception int js_parse_delete(JSParseState *s)
case OP_scope_get_private_field:
return js_parse_error(s, "cannot delete a private class field");
case OP_get_super_value:
fd->byte_code.size = fd->last_opcode_pos;
fd->last_opcode_pos = -1;
emit_op(s, OP_throw_error);
emit_atom(s, JS_ATOM_NULL);
emit_u8(s, JS_THROW_ERROR_DELETE_SUPER);
Expand Down Expand Up @@ -28382,12 +28389,13 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
is_arg_scope = (scope_idx == ARG_SCOPE_END);
if (!is_arg_scope) {
/* add unscoped variables */
/* XXX: propagate is_const and var_kind too ? */
for(i = 0; i < fd->arg_count; i++) {
vd = &fd->args[i];
if (vd->var_name != JS_ATOM_NULL) {
get_closure_var(ctx, s, fd,
TRUE, i, vd->var_name, FALSE, FALSE,
JS_VAR_NORMAL);
TRUE, i, vd->var_name, FALSE,
vd->is_lexical, JS_VAR_NORMAL);
}
}
for(i = 0; i < fd->var_count; i++) {
Expand All @@ -28397,8 +28405,8 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
vd->var_name != JS_ATOM__ret_ &&
vd->var_name != JS_ATOM_NULL) {
get_closure_var(ctx, s, fd,
FALSE, i, vd->var_name, FALSE, FALSE,
JS_VAR_NORMAL);
FALSE, i, vd->var_name, FALSE,
vd->is_lexical, JS_VAR_NORMAL);
}
}
} else {
Expand All @@ -28407,8 +28415,8 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
/* do not close top level last result */
if (vd->scope_level == 0 && is_var_in_arg_scope(vd)) {
get_closure_var(ctx, s, fd,
FALSE, i, vd->var_name, FALSE, FALSE,
JS_VAR_NORMAL);
FALSE, i, vd->var_name, FALSE,
vd->is_lexical, JS_VAR_NORMAL);
}
}
}
Expand Down Expand Up @@ -49713,7 +49721,7 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx,
{
JSObject *p, *src_buffer;
JSTypedArray *ta;
JSValue ctor, obj, buffer;
JSValue obj, buffer;
uint32_t len, i;
int size_log2;
JSArrayBuffer *src_abuf, *abuf;
Expand All @@ -49730,19 +49738,9 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx,
len = p->u.array.count;
src_buffer = ta->buffer;
src_abuf = src_buffer->u.array_buffer;
if (!src_abuf->shared) {
ctor = JS_SpeciesConstructor(ctx, JS_MKPTR(JS_TAG_OBJECT, src_buffer),
JS_UNDEFINED);
if (JS_IsException(ctor))
goto fail;
} else {
/* force ArrayBuffer default constructor */
ctor = JS_UNDEFINED;
}
size_log2 = typed_array_size_log2(classid);
buffer = js_array_buffer_constructor1(ctx, ctor,
buffer = js_array_buffer_constructor1(ctx, JS_UNDEFINED,
(uint64_t)len << size_log2);
JS_FreeValue(ctx, ctor);
if (JS_IsException(buffer))
goto fail;
/* necessary because it could have been detached */
Expand Down
12 changes: 0 additions & 12 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js
test262/test/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js:18: strict mode: Test262Error: typeof Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArray/prototype/with/not-a-constructor.js:25: strict mode: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/TypedArrayConstructors/ctors/no-species.js:16: Test262Error: unreachable
test262/test/built-ins/TypedArrayConstructors/ctors/no-species.js:16: strict mode: Test262Error: unreachable
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: Test262Error: (Testing with BigInt64Array.)
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js:46: strict mode: Test262Error: (Testing with BigInt64Array.)
test262/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js:40: Test262Error: Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return true Expected SameValue(«false», «true») to be true (Testing with BigInt64Array.)
Expand Down Expand Up @@ -98,8 +96,6 @@ test262/test/language/expressions/assignment/target-member-computed-reference-nu
test262/test/language/expressions/assignment/target-member-computed-reference-null.js:32: strict mode: Test262Error: Expected a DummyError but got a TypeError
test262/test/language/expressions/assignment/target-member-computed-reference-undefined.js:32: Test262Error: Expected a DummyError but got a TypeError
test262/test/language/expressions/assignment/target-member-computed-reference-undefined.js:32: strict mode: Test262Error: Expected a DummyError but got a TypeError
test262/test/language/expressions/delete/super-property-null-base.js:26: Test262Error: Expected a ReferenceError but got a TypeError
test262/test/language/expressions/delete/super-property-null-base.js:26: strict mode: Test262Error: Expected a ReferenceError but got a TypeError
test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: TypeError: $DONE() not called
test262/test/language/expressions/dynamic-import/usage-from-eval.js:26: strict mode: TypeError: $DONE() not called
test262/test/language/expressions/function/static-init-await-binding.js:16: SyntaxError: 'await' is a reserved identifier
Expand All @@ -121,13 +117,5 @@ test262/test/language/statements/class/elements/private-method-double-initialisa
test262/test/language/statements/class/elements/private-method-double-initialisation-set.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
test262/test/language/statements/class/elements/private-method-double-initialisation.js:32: strict mode: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
test262/test/language/statements/class/private-non-static-getter-static-setter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-non-static-getter-static-setter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-non-static-setter-static-getter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-non-static-setter-static-getter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-static-getter-non-static-setter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-static-getter-non-static-setter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-static-setter-non-static-getter-early-error.js:13: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/class/private-static-setter-non-static-getter-early-error.js:13: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/statements/for-of/head-lhs-async-invalid.js:14: strict mode: unexpected error type: Test262: This statement should not be evaluated.
14 changes: 14 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ function test_eval2()
f1(g);
f2(g);
assert(g_call_count, 2);
var e;
try {
new class extends Object {
constructor() {
(() => {
for (const _ in this);
eval("");
})();
}
};
} catch (_e) {
e = _e;
}
assert(e?.message, "this is not initialized");
}

function test_eval()
Expand Down