mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:37:45 +00:00
LibJS: Use new NativeFunction::create() in most places
Resolves one FIXME where we can now pass a realm, and sets the length correctly in a bunch of places that previously didn't. Also reduces the number of "format function name string from arbitrary PropertyKey" implementations, although two more remain present in the AST (used with ECMAScriptFunctionObjects, which is a different beast).
This commit is contained in:
parent
e4f165d460
commit
47cdd90836
9 changed files with 98 additions and 105 deletions
|
@ -228,44 +228,39 @@ ThrowCompletionOr<Value> shadow_realm_import_value(GlobalObject& global_object,
|
|||
// NOTE: We don't support this concept yet.
|
||||
|
||||
// 9. Let steps be the steps of an ExportGetter function as described below.
|
||||
auto steps = [string = move(export_name_string)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
||||
// 1. Assert: exports is a module namespace exotic object.
|
||||
VERIFY(vm.argument(0).is_object());
|
||||
auto& exports = vm.argument(0).as_object();
|
||||
VERIFY(is<ModuleNamespaceObject>(exports));
|
||||
|
||||
// 2. Let f be the active function object.
|
||||
auto* function = vm.running_execution_context().function;
|
||||
|
||||
// 3. Let string be f.[[ExportNameString]].
|
||||
// 4. Assert: Type(string) is String.
|
||||
|
||||
// 5. Let hasOwn be ? HasOwnProperty(exports, string).
|
||||
auto has_own = TRY(exports.has_own_property(string));
|
||||
|
||||
// 6. If hasOwn is false, throw a TypeError exception.
|
||||
if (!has_own)
|
||||
return vm.template throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, string);
|
||||
|
||||
// 7. Let value be ? Get(exports, string).
|
||||
auto value = TRY(exports.get(string));
|
||||
|
||||
// 8. Let realm be f.[[Realm]].
|
||||
auto* realm = function->realm();
|
||||
VERIFY(realm);
|
||||
|
||||
// 9. Return ? GetWrappedValue(realm, value).
|
||||
return get_wrapped_value(global_object, *realm, value);
|
||||
};
|
||||
|
||||
// 10. Let onFulfilled be ! CreateBuiltinFunction(steps, 1, "", « [[ExportNameString]] », callerRealm).
|
||||
// 11. Set onFulfilled.[[ExportNameString]] to exportNameString.
|
||||
// FIXME: Support passing a realm to NativeFunction::create()
|
||||
(void)caller_realm;
|
||||
auto* on_fulfilled = NativeFunction::create(
|
||||
global_object,
|
||||
"",
|
||||
[string = move(export_name_string)](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
||||
// 1. Assert: exports is a module namespace exotic object.
|
||||
VERIFY(vm.argument(0).is_object());
|
||||
auto& exports = vm.argument(0).as_object();
|
||||
VERIFY(is<ModuleNamespaceObject>(exports));
|
||||
|
||||
// 2. Let f be the active function object.
|
||||
auto* function = vm.running_execution_context().function;
|
||||
|
||||
// 3. Let string be f.[[ExportNameString]].
|
||||
// 4. Assert: Type(string) is String.
|
||||
|
||||
// 5. Let hasOwn be ? HasOwnProperty(exports, string).
|
||||
auto has_own = TRY(exports.has_own_property(string));
|
||||
|
||||
// 6. If hasOwn is false, throw a TypeError exception.
|
||||
if (!has_own)
|
||||
return vm.template throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, string);
|
||||
|
||||
// 7. Let value be ? Get(exports, string).
|
||||
auto value = TRY(exports.get(string));
|
||||
|
||||
// 8. Let realm be f.[[Realm]].
|
||||
auto* realm = function->realm();
|
||||
VERIFY(realm);
|
||||
|
||||
// 9. Return ? GetWrappedValue(realm, value).
|
||||
return get_wrapped_value(global_object, *realm, value);
|
||||
});
|
||||
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);
|
||||
auto* on_fulfilled = NativeFunction::create(global_object, move(steps), 1, "", &caller_realm);
|
||||
|
||||
// 12. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||
auto promise_capability = MUST(new_promise_capability(global_object, global_object.promise_constructor()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue