1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +00:00

LibJS: Remove implicit wrapping/unwrapping of completion records

This is an editorial change in the ECMA-262 spec, with similar changes
in some proposals.

See:
- 7575f74
- df899eb
- 9eb5a12
- c81f527
This commit is contained in:
Linus Groh 2022-05-02 20:54:39 +02:00
parent 15f32379bb
commit 9f3f3b0864
88 changed files with 792 additions and 735 deletions

View file

@ -171,7 +171,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
auto body_string = String::formatted("\n{}\n", body_arg.has_value() ? TRY(body_arg->to_string(global_object)) : "");
// 17. Let sourceString be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), ") {", bodyString, and "}".
// 18. Let sourceText be ! StringToCodePoints(sourceString).
// 18. Let sourceText be StringToCodePoints(sourceString).
auto source_text = String::formatted("{} anonymous({}\n) {{{}}}", prefix, parameters_string, body_string);
u8 parse_options = FunctionNodeParseOptions::CheckForFunctionAndName;
@ -180,7 +180,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
if (kind == FunctionKind::Generator || kind == FunctionKind::AsyncGenerator)
parse_options |= FunctionNodeParseOptions::IsGeneratorFunction;
// 19. Let parameters be ParseText(! StringToCodePoints(P), parameterSym).
// 19. Let parameters be ParseText(StringToCodePoints(P), parameterSym).
i32 function_length = 0;
auto parameters_parser = Parser { Lexer { parameters_string } };
auto parameters = parameters_parser.parse_formal_parameters(function_length, parse_options);
@ -191,7 +191,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
return vm.throw_completion<SyntaxError>(global_object, error.to_string());
}
// 21. Let body be ParseText(! StringToCodePoints(bodyString), bodySym).
// 21. Let body be ParseText(StringToCodePoints(bodyString), bodySym).
bool contains_direct_call_to_eval = false;
auto body_parser = Parser { Lexer { body_string } };
// Set up some parser state to accept things like return await, and yield in the plain function body.
@ -234,7 +234,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 30. Let privateEnv be null.
PrivateEnvironment* private_environment = nullptr;
// 31. Let F be ! OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv).
// 31. Let F be OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv).
auto* function = ECMAScriptFunctionObject::create(global_object, "anonymous", *prototype, move(source_text), expr->body(), expr->parameters(), expr->function_length(), environment, private_environment, expr->kind(), expr->is_strict_mode(), expr->might_need_arguments_object(), contains_direct_call_to_eval);
// FIXME: Remove the name argument from create() and do this instead.
@ -242,19 +242,19 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 33. If kind is generator, then
if (kind == FunctionKind::Generator) {
// a. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
// a. Let prototype be OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%).
prototype = Object::create(global_object, global_object.generator_prototype());
// b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
// b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
}
// 34. Else if kind is asyncGenerator, then
else if (kind == FunctionKind::AsyncGenerator) {
// FIXME: We only have %AsyncGeneratorFunction.prototype%, not %AsyncGeneratorFunction.prototype.prototype%!
// a. Let prototype be ! OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
// a. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorFunction.prototype.prototype%).
// prototype = Object::create(global_object, global_object.async_generator_prototype());
// b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
// b. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
// function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable);
}
// 35. Else if kind is normal, perform MakeConstructor(F).