mirror of
https://github.com/RGBCube/serenity
synced 2025-06-14 03:42:10 +00:00
LibJS: Update ShadowRealm AO parameter declaration notations
This is an editorial change in the ShadowRealm spec.
See: f5013fe
This commit is contained in:
parent
e20efaa083
commit
73a43e7cba
1 changed files with 40 additions and 50 deletions
|
@ -91,19 +91,15 @@ ThrowCompletionOr<void> copy_name_and_length(GlobalObject& global_object, Functi
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.3 PerformShadowRealmEval ( sourceText, callerRealm, evalRealm ), https://tc39.es/proposal-shadowrealm/#sec-performshadowrealmeval
|
// 3.1.3 PerformShadowRealmEval ( sourceText: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, ), https://tc39.es/proposal-shadowrealm/#sec-performshadowrealmeval
|
||||||
ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Assert: Type(sourceText) is String.
|
// 1. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
|
||||||
// 2. Assert: callerRealm is a Realm Record.
|
|
||||||
// 3. Assert: evalRealm is a Realm Record.
|
|
||||||
|
|
||||||
// 4. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
|
|
||||||
// FIXME: We don't have this host-defined abstract operation yet.
|
// FIXME: We don't have this host-defined abstract operation yet.
|
||||||
|
|
||||||
// 5. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection:
|
// 2. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection:
|
||||||
|
|
||||||
// a. Let script be ParseText(! StringToCodePoints(sourceText), Script).
|
// a. Let script be ParseText(! StringToCodePoints(sourceText), Script).
|
||||||
auto parser = Parser(Lexer(source_text));
|
auto parser = Parser(Lexer(source_text));
|
||||||
|
@ -125,118 +121,114 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
|
||||||
// g. If body Contains SuperCall is true, throw a SyntaxError exception.
|
// g. If body Contains SuperCall is true, throw a SyntaxError exception.
|
||||||
// FIXME: Implement these, we probably need a generic way of scanning the AST for certain nodes.
|
// FIXME: Implement these, we probably need a generic way of scanning the AST for certain nodes.
|
||||||
|
|
||||||
// 6. Let strictEval be IsStrict of script.
|
// 3. Let strictEval be IsStrict of script.
|
||||||
auto strict_eval = program->is_strict_mode();
|
auto strict_eval = program->is_strict_mode();
|
||||||
|
|
||||||
// 7. Let runningContext be the running execution context.
|
// 4. Let runningContext be the running execution context.
|
||||||
// NOTE: This would be unused due to step 11 and is omitted for that reason.
|
// NOTE: This would be unused due to step 11 and is omitted for that reason.
|
||||||
|
|
||||||
// 8. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]).
|
// 5. Let lexEnv be NewDeclarativeEnvironment(evalRealm.[[GlobalEnv]]).
|
||||||
Environment* lexical_environment = new_declarative_environment(eval_realm.global_environment());
|
Environment* lexical_environment = new_declarative_environment(eval_realm.global_environment());
|
||||||
|
|
||||||
// 9. Let varEnv be evalRealm.[[GlobalEnv]].
|
// 6. Let varEnv be evalRealm.[[GlobalEnv]].
|
||||||
Environment* variable_environment = &eval_realm.global_environment();
|
Environment* variable_environment = &eval_realm.global_environment();
|
||||||
|
|
||||||
// 10. If strictEval is true, set varEnv to lexEnv.
|
// 7. If strictEval is true, set varEnv to lexEnv.
|
||||||
if (strict_eval)
|
if (strict_eval)
|
||||||
variable_environment = lexical_environment;
|
variable_environment = lexical_environment;
|
||||||
|
|
||||||
// 11. If runningContext is not already suspended, suspend runningContext.
|
// 8. If runningContext is not already suspended, suspend runningContext.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 12. Let evalContext be a new ECMAScript code execution context.
|
// 9. Let evalContext be a new ECMAScript code execution context.
|
||||||
auto eval_context = ExecutionContext { vm.heap() };
|
auto eval_context = ExecutionContext { vm.heap() };
|
||||||
|
|
||||||
// 13. Set evalContext's Function to null.
|
// 10. Set evalContext's Function to null.
|
||||||
eval_context.function = nullptr;
|
eval_context.function = nullptr;
|
||||||
|
|
||||||
// 14. Set evalContext's Realm to evalRealm.
|
// 11. Set evalContext's Realm to evalRealm.
|
||||||
eval_context.realm = &eval_realm;
|
eval_context.realm = &eval_realm;
|
||||||
|
|
||||||
// 15. Set evalContext's ScriptOrModule to null.
|
// 12. Set evalContext's ScriptOrModule to null.
|
||||||
// Note: This is already the default value.
|
// Note: This is already the default value.
|
||||||
|
|
||||||
// 16. Set evalContext's VariableEnvironment to varEnv.
|
// 13. Set evalContext's VariableEnvironment to varEnv.
|
||||||
eval_context.variable_environment = variable_environment;
|
eval_context.variable_environment = variable_environment;
|
||||||
|
|
||||||
// 17. Set evalContext's LexicalEnvironment to lexEnv.
|
// 14. Set evalContext's LexicalEnvironment to lexEnv.
|
||||||
eval_context.lexical_environment = lexical_environment;
|
eval_context.lexical_environment = lexical_environment;
|
||||||
|
|
||||||
// Non-standard
|
// Non-standard
|
||||||
eval_context.is_strict_mode = strict_eval;
|
eval_context.is_strict_mode = strict_eval;
|
||||||
|
|
||||||
// 18. Push evalContext onto the execution context stack; evalContext is now the running execution context.
|
// 15. Push evalContext onto the execution context stack; evalContext is now the running execution context.
|
||||||
TRY(vm.push_execution_context(eval_context, eval_realm.global_object()));
|
TRY(vm.push_execution_context(eval_context, eval_realm.global_object()));
|
||||||
|
|
||||||
// 19. Let result be EvalDeclarationInstantiation(body, varEnv, lexEnv, null, strictEval).
|
// 16. Let result be EvalDeclarationInstantiation(body, varEnv, lexEnv, null, strictEval).
|
||||||
auto eval_result = eval_declaration_instantiation(vm, eval_realm.global_object(), program, variable_environment, lexical_environment, nullptr, strict_eval);
|
auto eval_result = eval_declaration_instantiation(vm, eval_realm.global_object(), program, variable_environment, lexical_environment, nullptr, strict_eval);
|
||||||
|
|
||||||
Completion result;
|
Completion result;
|
||||||
|
|
||||||
// 20. If result.[[Type]] is normal, then
|
// 17. If result.[[Type]] is normal, then
|
||||||
if (!eval_result.is_throw_completion()) {
|
if (!eval_result.is_throw_completion()) {
|
||||||
// TODO: Optionally use bytecode interpreter?
|
// TODO: Optionally use bytecode interpreter?
|
||||||
// a. Set result to the result of evaluating body.
|
// a. Set result to the result of evaluating body.
|
||||||
result = program->execute(vm.interpreter(), eval_realm.global_object());
|
result = program->execute(vm.interpreter(), eval_realm.global_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 21. If result.[[Type]] is normal and result.[[Value]] is empty, then
|
// 18. If result.[[Type]] is normal and result.[[Value]] is empty, then
|
||||||
if (result.type() == Completion::Type::Normal && !result.value().has_value()) {
|
if (result.type() == Completion::Type::Normal && !result.value().has_value()) {
|
||||||
// a. Set result to NormalCompletion(undefined).
|
// a. Set result to NormalCompletion(undefined).
|
||||||
result = normal_completion(js_undefined());
|
result = normal_completion(js_undefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22. Suspend evalContext and remove it from the execution context stack.
|
// 19. Suspend evalContext and remove it from the execution context stack.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
vm.pop_execution_context();
|
vm.pop_execution_context();
|
||||||
|
|
||||||
// 23. Resume the context that is now on the top of the execution context stack as the running execution context.
|
// 20. Resume the context that is now on the top of the execution context stack as the running execution context.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 24. If result.[[Type]] is not normal, throw a TypeError exception.
|
// 21. If result.[[Type]] is not normal, throw a TypeError exception.
|
||||||
if (result.type() != Completion::Type::Normal)
|
if (result.type() != Completion::Type::Normal)
|
||||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmEvaluateAbruptCompletion);
|
||||||
|
|
||||||
// 25. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
// 22. Return ? GetWrappedValue(callerRealm, result.[[Value]]).
|
||||||
return get_wrapped_value(global_object, caller_realm, *result.value());
|
return get_wrapped_value(global_object, caller_realm, *result.value());
|
||||||
|
|
||||||
// NOTE: Also see "Editor's Note" in the spec regarding the TypeError above.
|
// NOTE: Also see "Editor's Note" in the spec regarding the TypeError above.
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.4 ShadowRealmImportValue ( specifierString, exportNameString, callerRealm, evalRealm, evalContext ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
// 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
|
||||||
ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context)
|
ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm, ExecutionContext& eval_context)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Assert: Type(specifierString) is String.
|
// 1. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
|
||||||
// 2. Assert: Type(exportNameString) is String.
|
|
||||||
// 3. Assert: callerRealm is a Realm Record.
|
|
||||||
// 4. Assert: evalRealm is a Realm Record.
|
|
||||||
// 5. Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
|
|
||||||
|
|
||||||
// 6. Let innerCapability be ! NewPromiseCapability(%Promise%).
|
// 2. Let innerCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto inner_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
|
auto inner_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
|
||||||
|
|
||||||
// 7. Let runningContext be the running execution context.
|
// 3. Let runningContext be the running execution context.
|
||||||
// 8. If runningContext is not already suspended, suspend runningContext.
|
// 4. If runningContext is not already suspended, suspend runningContext.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 9. Push evalContext onto the execution context stack; evalContext is now the running execution context.
|
// 5. Push evalContext onto the execution context stack; evalContext is now the running execution context.
|
||||||
TRY(vm.push_execution_context(eval_context, eval_realm.global_object()));
|
TRY(vm.push_execution_context(eval_context, eval_realm.global_object()));
|
||||||
|
|
||||||
// 10. Perform ! HostImportModuleDynamically(null, specifierString, innerCapability).
|
// 6. Perform ! HostImportModuleDynamically(null, specifierString, innerCapability).
|
||||||
vm.host_import_module_dynamically(Empty {}, ModuleRequest { move(specifier_string) }, inner_capability);
|
vm.host_import_module_dynamically(Empty {}, ModuleRequest { move(specifier_string) }, inner_capability);
|
||||||
|
|
||||||
// 11. Suspend evalContext and remove it from the execution context stack.
|
// 7. Suspend evalContext and remove it from the execution context stack.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
vm.pop_execution_context();
|
vm.pop_execution_context();
|
||||||
|
|
||||||
// 12. Resume the context that is now on the top of the execution context stack as the running execution context.
|
// 8. Resume the context that is now on the top of the execution context stack as the running execution context.
|
||||||
// NOTE: We don't support this concept yet.
|
// NOTE: We don't support this concept yet.
|
||||||
|
|
||||||
// 13. Let steps be the steps of an ExportGetter function as described below.
|
// 9. Let steps be the steps of an ExportGetter function as described below.
|
||||||
// 14. Let onFulfilled be ! CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
|
// 10. Let onFulfilled be ! CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
|
||||||
// 15. Set onFulfilled.[[ExportNameString]] to exportNameString.
|
// 11. Set onFulfilled.[[ExportNameString]] to exportNameString.
|
||||||
// FIXME: Support passing a realm to NativeFunction::create()
|
// FIXME: Support passing a realm to NativeFunction::create()
|
||||||
(void)caller_realm;
|
(void)caller_realm;
|
||||||
auto* on_fulfilled = NativeFunction::create(
|
auto* on_fulfilled = NativeFunction::create(
|
||||||
|
@ -274,7 +266,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
on_fulfilled->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
on_fulfilled->define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
||||||
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
|
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, String::empty()), Attribute::Configurable);
|
||||||
|
|
||||||
// 16. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
|
auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
|
||||||
|
|
||||||
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
// NOTE: Even though the spec tells us to use %ThrowTypeError%, it's not observable if we actually do.
|
||||||
|
@ -283,18 +275,16 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
||||||
return vm.template throw_completion<TypeError>(global_object, vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
return vm.template throw_completion<TypeError>(global_object, vm.argument(0).as_object().get_without_side_effects(vm.names.message).as_string().string());
|
||||||
});
|
});
|
||||||
|
|
||||||
// 17. Return ! PerformPromiseThen(innerCapability.[[Promise]], onFulfilled, callerRealm.[[Intrinsics]].[[%ThrowTypeError%]], promiseCapability).
|
// 13. Return ! PerformPromiseThen(innerCapability.[[Promise]], onFulfilled, callerRealm.[[Intrinsics]].[[%ThrowTypeError%]], promiseCapability).
|
||||||
return verify_cast<Promise>(inner_capability.promise)->perform_then(on_fulfilled, throw_type_error, promise_capability);
|
return verify_cast<Promise>(inner_capability.promise)->perform_then(on_fulfilled, throw_type_error, promise_capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3.1.5 GetWrappedValue ( callerRealm, value ), https://tc39.es/proposal-shadowrealm/#sec-getwrappedvalue
|
// 3.1.5 GetWrappedValue ( callerRealm: a Realm Record, value: unknown, ), https://tc39.es/proposal-shadowrealm/#sec-getwrappedvalue
|
||||||
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& caller_realm, Value value)
|
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& caller_realm, Value value)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
// 1. Assert: callerRealm is a Realm Record.
|
// 1. If Type(value) is Object, then
|
||||||
|
|
||||||
// 2. If Type(value) is Object, then
|
|
||||||
if (value.is_object()) {
|
if (value.is_object()) {
|
||||||
// a. If IsCallable(value) is false, throw a TypeError exception.
|
// a. If IsCallable(value) is false, throw a TypeError exception.
|
||||||
if (!value.is_function())
|
if (!value.is_function())
|
||||||
|
@ -304,7 +294,7 @@ ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& c
|
||||||
return TRY(WrappedFunction::create(global_object, caller_realm, value.as_function()));
|
return TRY(WrappedFunction::create(global_object, caller_realm, value.as_function()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Return value.
|
// 2. Return value.
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue