mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibJS: Add the HostEnsureCanAddPrivateElement hook
This hook allows us to reject private elements on certain exotic objects like the window object in browser. Note that per the spec we should only call this hook if the host is a web browser, however because LibJS has no way of knowing whether it is in a web browser environment we just always call the host hook.
This commit is contained in:
parent
b5a2f59320
commit
c4f3d44be1
3 changed files with 42 additions and 0 deletions
|
@ -124,6 +124,21 @@ VM::VM(OwnPtr<CustomData> custom_data)
|
|||
return {};
|
||||
};
|
||||
|
||||
host_ensure_can_add_private_element = [](Object&) -> ThrowCompletionOr<void> {
|
||||
// The host-defined abstract operation HostEnsureCanAddPrivateElement takes argument O (an Object)
|
||||
// and returns either a normal completion containing unused or a throw completion.
|
||||
// It allows host environments to prevent the addition of private elements to particular host-defined exotic objects.
|
||||
// An implementation of HostEnsureCanAddPrivateElement must conform to the following requirements:
|
||||
// - If O is not a host-defined exotic object, this abstract operation must return NormalCompletion(unused) and perform no other steps.
|
||||
// - Any two calls of this abstract operation with the same argument must return the same kind of Completion Record.
|
||||
// The default implementation of HostEnsureCanAddPrivateElement is to return NormalCompletion(unused).
|
||||
return {};
|
||||
|
||||
// This abstract operation is only invoked by ECMAScript hosts that are web browsers.
|
||||
// NOTE: Since LibJS has no way of knowing whether the current environment is a browser we always
|
||||
// call HostEnsureCanAddPrivateElement when needed.
|
||||
};
|
||||
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue