mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
LibJS: Don't crash when attempting to load from an invalid reference
Previously, attempting to load a value from an invalid reference would cause a crash. We now return a CodeGenerationError rather than hitting an assertion. This is not a complete solution, as ideally we would want to return a ReferenceError, but this now matches the behavior we see when we attempt to store something to an invalid reference.
This commit is contained in:
parent
53273e2037
commit
6c31f2a68a
2 changed files with 11 additions and 1 deletions
|
@ -268,7 +268,10 @@ CodeGenerationErrorOr<Optional<Generator::ReferenceRegisters>> Generator::emit_l
|
||||||
}
|
}
|
||||||
return Optional<ReferenceRegisters> {};
|
return Optional<ReferenceRegisters> {};
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
return CodeGenerationError {
|
||||||
|
&node,
|
||||||
|
"Unimplemented/invalid node used a reference"sv
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeGenerationErrorOr<void> Generator::emit_store_to_reference(JS::ASTNode const& node)
|
CodeGenerationErrorOr<void> Generator::emit_store_to_reference(JS::ASTNode const& node)
|
||||||
|
|
|
@ -5,6 +5,13 @@ test.xfail("assignment to function call", () => {
|
||||||
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
|
}).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.xfail("Postfix operator after function call", () => {
|
||||||
|
expect(() => {
|
||||||
|
function foo() {}
|
||||||
|
foo()++;
|
||||||
|
}).toThrow(ReferenceError);
|
||||||
|
});
|
||||||
|
|
||||||
test("assignment to function call in strict mode", () => {
|
test("assignment to function call in strict mode", () => {
|
||||||
expect("'use strict'; foo() = 'foo'").toEval();
|
expect("'use strict'; foo() = 'foo'").toEval();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue