mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
LibJS: Implement Wrapped Function Exotic Objects
This is a new concept from the ShadowRealm API stage 3 proposal: https://tc39.es/proposal-shadowrealm/#sec-wrapped-function-exotic-objects
This commit is contained in:
parent
d92967406a
commit
50f8755792
7 changed files with 194 additions and 0 deletions
33
Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
Normal file
33
Userland/Libraries/LibJS/Runtime/ShadowRealm.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/Runtime/ShadowRealm.h>
|
||||
#include <LibJS/Runtime/WrappedFunction.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
// 3.1.3 GetWrappedValue ( callerRealm, value ), https://tc39.es/proposal-shadowrealm/#sec-getwrappedvalue
|
||||
ThrowCompletionOr<Value> get_wrapped_value(GlobalObject& global_object, Realm& caller_realm, Value value)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: callerRealm is a Realm Record.
|
||||
|
||||
// 2. If Type(value) is Object, then
|
||||
if (value.is_object()) {
|
||||
// a. If IsCallable(value) is false, throw a TypeError exception.
|
||||
if (!value.is_function())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ShadowRealmWrappedValueNonFunctionObject, value);
|
||||
|
||||
// b. Return ! WrappedFunctionCreate(callerRealm, value).
|
||||
return { WrappedFunction::create(global_object, caller_realm, value.as_function()) };
|
||||
}
|
||||
|
||||
// 3. Return value.
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue