mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibJS: Set the bound |this| value to the |this| value of the current
scope for arrow functions
This commit is contained in:
parent
c12125fa81
commit
45ccd9f8d9
3 changed files with 16 additions and 4 deletions
|
@ -53,7 +53,7 @@ ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyStr
|
|||
}
|
||||
|
||||
ScriptFunction::ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function)
|
||||
: Function(prototype)
|
||||
: Function(prototype, is_arrow_function ? interpreter().this_value() : Value(), {})
|
||||
, m_name(name)
|
||||
, m_body(body)
|
||||
, m_parameters(move(parameters))
|
||||
|
|
|
@ -102,9 +102,8 @@ try {
|
|||
// assert(strictIdentity.bind(undefined)() === undefined);
|
||||
// })();
|
||||
|
||||
// FIXME: Uncomment me when arrow functions have the correct |this| value.
|
||||
// // Arrow functions can not have their |this| value set.
|
||||
// assert((() => this).bind("foo")() === globalThis)
|
||||
// Arrow functions can not have their |this| value set.
|
||||
assert((() => this).bind("foo")() === globalThis)
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -64,6 +64,19 @@ try {
|
|||
assert(foo === undefined);
|
||||
assert(bar === undefined);
|
||||
|
||||
function FooBar() {
|
||||
this.x = {
|
||||
y: () => this,
|
||||
z: function () {
|
||||
return (() => this)();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var foobar = new FooBar();
|
||||
assert(foobar.x.y() === foobar);
|
||||
assert(foobar.x.z() === foobar.x);
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
assert(isStrictMode());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue