Fix computed reference on null or undefined

This commit is contained in:
Saúl Ibarra Corretgé 2024-10-07 16:46:53 +02:00
parent acc0dd9273
commit 52e0f24048
2 changed files with 20 additions and 10 deletions

View file

@ -8159,9 +8159,11 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj,
{ {
JSAtom atom; JSAtom atom;
JSValue ret; JSValue ret;
uint32_t tag;
if (likely(JS_VALUE_GET_TAG(this_obj) == JS_TAG_OBJECT && tag = JS_VALUE_GET_TAG(this_obj);
JS_VALUE_GET_TAG(prop) == JS_TAG_INT)) { if (likely(tag == JS_TAG_OBJECT)) {
if (JS_VALUE_GET_TAG(prop) == JS_TAG_INT) {
JSObject *p = JS_VALUE_GET_OBJ(this_obj); JSObject *p = JS_VALUE_GET_OBJ(this_obj);
uint32_t idx = JS_VALUE_GET_INT(prop); uint32_t idx = JS_VALUE_GET_INT(prop);
JSValue val; JSValue val;
@ -8169,6 +8171,16 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj,
if (js_get_fast_array_element(ctx, p, idx, &val)) if (js_get_fast_array_element(ctx, p, idx, &val))
return val; return val;
} }
} else {
switch(tag) {
case JS_TAG_NULL:
JS_FreeValue(ctx, prop);
return JS_ThrowTypeError(ctx, "cannot read property of null");
case JS_TAG_UNDEFINED:
JS_FreeValue(ctx, prop);
return JS_ThrowTypeError(ctx, "cannot read property of undefined");
}
}
atom = JS_ValueToAtom(ctx, prop); atom = JS_ValueToAtom(ctx, prop);
JS_FreeValue(ctx, prop); JS_FreeValue(ctx, prop);
if (unlikely(atom == JS_ATOM_NULL)) if (unlikely(atom == JS_ATOM_NULL))

View file

@ -628,7 +628,5 @@ test262/test/language/expressions/assignment/target-super-computed-reference.js:
test262/test/language/expressions/assignment/target-super-computed-reference.js:20: strict mode: Test262Error: Expected a DummyError but got a Test262Error test262/test/language/expressions/assignment/target-super-computed-reference.js:20: strict mode: Test262Error: Expected a DummyError but got a Test262Error
test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: unexpected error type: Test262: This statement should not be evaluated. test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: strict mode: unexpected error type: Test262: This statement should not be evaluated. test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/expressions/member-expression/computed-reference-null-or-undefined.js:28: Test262Error: Expected a TypeError but got a Test262Error
test262/test/language/expressions/member-expression/computed-reference-null-or-undefined.js:28: strict mode: Test262Error: Expected a TypeError but got a Test262Error
test262/test/language/module-code/top-level-await/async-module-does-not-block-sibling-modules.js:13: SyntaxError: Could not find export 'check' in module 'test262/test/language/module-code/top-level-await/async-module-sync_FIXTURE.js' test262/test/language/module-code/top-level-await/async-module-does-not-block-sibling-modules.js:13: SyntaxError: Could not find export 'check' in module 'test262/test/language/module-code/top-level-await/async-module-sync_FIXTURE.js'
test262/test/staging/top-level-await/tla-hang-entry.js:10: TypeError: $DONE() not called test262/test/staging/top-level-await/tla-hang-entry.js:10: TypeError: $DONE() not called