Skip to content

Commit

Permalink
Fix computed reference on null or undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Oct 7, 2024
1 parent acc0dd9 commit 52e0f24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 20 additions & 8 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8159,15 +8159,27 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValue this_obj,
{
JSAtom atom;
JSValue ret;
uint32_t tag;

if (likely(JS_VALUE_GET_TAG(this_obj) == JS_TAG_OBJECT &&
JS_VALUE_GET_TAG(prop) == JS_TAG_INT)) {
JSObject *p = JS_VALUE_GET_OBJ(this_obj);
uint32_t idx = JS_VALUE_GET_INT(prop);
JSValue val;
/* fast path for array and typed array access */
if (js_get_fast_array_element(ctx, p, idx, &val))
return val;
tag = JS_VALUE_GET_TAG(this_obj);
if (likely(tag == JS_TAG_OBJECT)) {
if (JS_VALUE_GET_TAG(prop) == JS_TAG_INT) {
JSObject *p = JS_VALUE_GET_OBJ(this_obj);
uint32_t idx = JS_VALUE_GET_INT(prop);
JSValue val;
/* fast path for array and typed array access */
if (js_get_fast_array_element(ctx, p, idx, &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);
JS_FreeValue(ctx, prop);
Expand Down
2 changes: 0 additions & 2 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/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/staging/top-level-await/tla-hang-entry.js:10: TypeError: $DONE() not called

0 comments on commit 52e0f24

Please sign in to comment.