mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Remove ShadowRealm HTML integration
This commit is contained in:
committed by
Shannon Booth
parent
f27bc38aa7
commit
bb0f244667
Notes:
github-actions[bot]
2026-04-05 11:58:52 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/bb0f244667d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8753
@@ -114,16 +114,15 @@ ErrorOr<ByteBuffer> get_buffer_source_copy(JS::Object const& buffer_source)
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#call-user-object-operation-return
|
||||
// https://whatpr.org/webidl/1437.html#call-user-object-operation-return
|
||||
inline JS::Completion clean_up_on_return(JS::Realm& stored_realm, JS::Realm& relevant_realm, JS::Completion& completion, OperationReturnsPromise operation_returns_promise)
|
||||
inline JS::Completion clean_up_on_return(HTML::EnvironmentSettingsObject& stored_settings, HTML::EnvironmentSettingsObject& relevant_settings, JS::Completion& completion, OperationReturnsPromise operation_returns_promise)
|
||||
{
|
||||
// Return: at this point completion will be set to an ECMAScript completion value.
|
||||
|
||||
// 1. Clean up after running a callback with stored realm.
|
||||
HTML::clean_up_after_running_callback(stored_realm);
|
||||
// 1. Clean up after running a callback with stored settings.
|
||||
HTML::clean_up_after_running_callback(stored_settings);
|
||||
|
||||
// 2. Clean up after running script with relevant realm.
|
||||
HTML::clean_up_after_running_script(relevant_realm);
|
||||
// 2. Clean up after running script with relevant settings.
|
||||
HTML::clean_up_after_running_script(relevant_settings);
|
||||
|
||||
// 3. If completion is a normal completion, return completion.
|
||||
if (completion.type() == JS::Completion::Type::Normal)
|
||||
@@ -134,7 +133,7 @@ inline JS::Completion clean_up_on_return(JS::Realm& stored_realm, JS::Realm& rel
|
||||
return completion;
|
||||
|
||||
// 5. Let rejectedPromise be ! Call(%Promise.reject%, %Promise%, «completion.[[Value]]»).
|
||||
auto rejected_promise = create_rejected_promise(relevant_realm, completion.release_value());
|
||||
auto rejected_promise = create_rejected_promise(relevant_settings.realm(), completion.release_value());
|
||||
|
||||
// 6. Return the result of converting rejectedPromise to the operation’s return type.
|
||||
// Note: The operation must return a promise, so no conversion is necessary
|
||||
@@ -142,7 +141,6 @@ inline JS::Completion clean_up_on_return(JS::Realm& stored_realm, JS::Realm& rel
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#call-a-user-objects-operation
|
||||
// https://whatpr.org/webidl/1437.html#call-a-user-objects-operation
|
||||
JS::Completion call_user_object_operation(CallbackType& callback, Utf16FlyString const& operation_name, Optional<JS::Value> this_argument, ReadonlySpan<JS::Value> args)
|
||||
{
|
||||
// 1. Let completion be an uninitialized variable.
|
||||
@@ -155,22 +153,25 @@ JS::Completion call_user_object_operation(CallbackType& callback, Utf16FlyString
|
||||
// 3. Let O be the ECMAScript object corresponding to value.
|
||||
auto& object = callback.callback;
|
||||
|
||||
// 4. Let relevant realm be O’s associated Realm.
|
||||
auto& relevant_realm = object->shape().realm();
|
||||
// 4. Let realm be O’s associated realm.
|
||||
auto& realm = object->shape().realm();
|
||||
|
||||
// 5. Let stored realm be value’s callback context.
|
||||
auto& stored_realm = callback.callback_context;
|
||||
// 5. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = HTML::principal_realm_settings_object(realm);
|
||||
|
||||
// 6. Prepare to run script with relevant realm.
|
||||
HTML::prepare_to_run_script(relevant_realm);
|
||||
// 6. Let stored settings be value’s callback context.
|
||||
auto& stored_settings = callback.callback_context;
|
||||
|
||||
// 7. Prepare to run a callback with stored realm.
|
||||
HTML::prepare_to_run_callback(stored_realm);
|
||||
// 7. Prepare to run script with relevant settings.
|
||||
HTML::prepare_to_run_script(relevant_settings);
|
||||
|
||||
// 8. Let X be O.
|
||||
// 8. Prepare to run a callback with stored settings.
|
||||
HTML::prepare_to_run_callback(stored_settings);
|
||||
|
||||
// 9. Let X be O.
|
||||
auto actual_function_object = object;
|
||||
|
||||
// 9. If ! IsCallable(O) is false, then:
|
||||
// 10. If ! IsCallable(O) is false, then:
|
||||
if (!object->is_function()) {
|
||||
// 1. Let getResult be Get(O, opName).
|
||||
auto get_result = object->get(operation_name);
|
||||
@@ -178,13 +179,13 @@ JS::Completion call_user_object_operation(CallbackType& callback, Utf16FlyString
|
||||
// 2. If getResult is an abrupt completion, set completion to getResult and jump to the step labeled return.
|
||||
if (get_result.is_throw_completion()) {
|
||||
completion = get_result.throw_completion();
|
||||
return clean_up_on_return(stored_realm, relevant_realm, completion, callback.operation_returns_promise);
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
// 4. If ! IsCallable(X) is false, then set completion to a new Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}, and jump to the step labeled return.
|
||||
if (!get_result.value().is_function()) {
|
||||
completion = relevant_realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, get_result.value());
|
||||
return clean_up_on_return(stored_realm, relevant_realm, completion, callback.operation_returns_promise);
|
||||
completion = realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, get_result.value());
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
// 3. Set X to getResult.[[Value]].
|
||||
@@ -195,23 +196,23 @@ JS::Completion call_user_object_operation(CallbackType& callback, Utf16FlyString
|
||||
this_argument = object;
|
||||
}
|
||||
|
||||
// FIXME: 10. Let esArgs be the result of converting args to an ECMAScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
// FIXME: 11. Let esArgs be the result of converting args to an ECMAScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
// For simplicity, we currently make the caller do this. However, this means we can't throw exceptions at this point like the spec wants us to.
|
||||
|
||||
// 11. Let callResult be Call(X, thisArg, esArgs).
|
||||
// 12. Let callResult be Call(X, thisArg, esArgs).
|
||||
auto call_result = JS::call(object->vm(), as<JS::FunctionObject>(*actual_function_object), this_argument.value(), args);
|
||||
|
||||
// 12. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
// 13. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
if (call_result.is_throw_completion()) {
|
||||
completion = call_result.throw_completion();
|
||||
return clean_up_on_return(stored_realm, relevant_realm, completion, callback.operation_returns_promise);
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
// 13. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as the operation’s return type.
|
||||
// 14. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as the operation’s return type.
|
||||
// FIXME: This does no conversion.
|
||||
completion = call_result.value();
|
||||
|
||||
return clean_up_on_return(stored_realm, relevant_realm, completion, callback.operation_returns_promise);
|
||||
return clean_up_on_return(stored_settings, relevant_settings, completion, callback.operation_returns_promise);
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#ref-for-idl-ByteString%E2%91%A7
|
||||
@@ -265,45 +266,48 @@ static auto invoke_callback_impl(CallbackType& callback, Optional<JS::Value> thi
|
||||
// 3. Let F be the ECMAScript object corresponding to callable.
|
||||
auto& function_object = callback.callback;
|
||||
|
||||
// 5. Let relevant realm be F’s associated realm.
|
||||
auto& relevant_realm = function_object->shape().realm();
|
||||
// 5. Let realm be F’s associated realm.
|
||||
auto& realm = function_object->shape().realm();
|
||||
|
||||
// 6. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = HTML::principal_realm_settings_object(realm);
|
||||
|
||||
// 4. If ! IsCallable(F) is false:
|
||||
if (!function_object->is_function()) {
|
||||
// 1. Note: This is only possible when the callback function came from an attribute marked with [LegacyTreatNonObjectAsNull].
|
||||
|
||||
// 2. Return the result of converting undefined to the callback function’s return type.
|
||||
return return_steps(relevant_realm, JS::js_undefined());
|
||||
return return_steps(realm, JS::js_undefined());
|
||||
}
|
||||
|
||||
// 6. Let stored realm be callable’s callback context.
|
||||
auto& stored_realm = callback.callback_context;
|
||||
// 7. Let stored settings be callable’s callback context.
|
||||
auto& stored_settings = callback.callback_context;
|
||||
|
||||
// 7. Prepare to run script with relevant realm.
|
||||
HTML::prepare_to_run_script(relevant_realm);
|
||||
// 8. Prepare to run script with relevant realm.
|
||||
HTML::prepare_to_run_script(relevant_settings);
|
||||
|
||||
// 8. Prepare to run a callback with stored realm.
|
||||
HTML::prepare_to_run_callback(stored_realm);
|
||||
// 9. Prepare to run a callback with stored realm.
|
||||
HTML::prepare_to_run_callback(stored_settings);
|
||||
|
||||
// FIXME: 9. Let jsArgs be the result of converting args to a JavaScript arguments list.
|
||||
// If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
// FIXME: 10. Let jsArgs be the result of converting args to a JavaScript arguments list.
|
||||
// If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
|
||||
// 10. Let callResult be Call(F, thisArg, jsArgs).
|
||||
// 11. Let callResult be Call(F, thisArg, jsArgs).
|
||||
auto call_result = JS::call(function_object->vm(), as<JS::FunctionObject>(*function_object), this_argument.value(), args);
|
||||
|
||||
// 11. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
// 12. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as callable’s
|
||||
// 12. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
// 13. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as callable’s
|
||||
// return type. If this throws an exception, set completion to the completion value representing the thrown exception.
|
||||
// 13. Return: at this point completion will be set to an IDL value or an abrupt completion.
|
||||
// 14. Return: at this point completion will be set to an IDL value or an abrupt completion.
|
||||
{
|
||||
// 1. Clean up after running a callback with stored realm.
|
||||
HTML::clean_up_after_running_callback(stored_realm);
|
||||
// 1. Clean up after running a callback with stored settings.
|
||||
HTML::clean_up_after_running_callback(stored_settings);
|
||||
|
||||
// 2. Clean up after running script with relevant realm.
|
||||
// 2. Clean up after running script with relevant settings.
|
||||
// FIXME: This method follows an older version of the spec, which takes a realm, so we use F's associated realm instead.
|
||||
HTML::clean_up_after_running_script(relevant_realm);
|
||||
HTML::clean_up_after_running_script(relevant_settings);
|
||||
|
||||
return return_steps(relevant_realm, move(call_result));
|
||||
return return_steps(realm, move(call_result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,31 +395,34 @@ JS::Completion construct(CallbackType& callable, ReadonlySpan<JS::Value> args)
|
||||
auto& function_object = callable.callback;
|
||||
|
||||
// 3. If IsConstructor(F) is false, throw a TypeError exception.
|
||||
// 4. Let relevant realm be F’s associated realm.
|
||||
auto& relevant_realm = function_object->shape().realm();
|
||||
// 4. Let realm be F’s associated realm.
|
||||
auto& realm = function_object->shape().realm();
|
||||
if (!JS::Value(function_object).is_constructor())
|
||||
return relevant_realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, JS::Value(function_object));
|
||||
return realm.vm().template throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, JS::Value(function_object));
|
||||
|
||||
// 5. Let stored realm be callable’s callback context.
|
||||
auto& stored_realm = callable.callback_context;
|
||||
// 5. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = HTML::principal_realm_settings_object(realm);
|
||||
|
||||
// 6. Prepare to run script with relevant realm.
|
||||
HTML::prepare_to_run_script(relevant_realm);
|
||||
// 6. Let stored settings be callable’s callback context.
|
||||
auto& stored_settings = callable.callback_context;
|
||||
|
||||
// 7. Prepare to run a callback with stored realm.
|
||||
HTML::prepare_to_run_callback(stored_realm);
|
||||
// 7. Prepare to run script with relevant settings.
|
||||
HTML::prepare_to_run_script(relevant_settings);
|
||||
|
||||
// FIXME: 8. Let jsArgs be the result of converting args to a JavaScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
// 8. Prepare to run a callback with stored settings.
|
||||
HTML::prepare_to_run_callback(stored_settings);
|
||||
|
||||
// FIXME: 9. Let jsArgs be the result of converting args to a JavaScript arguments list. If this throws an exception, set completion to the completion value representing the thrown exception and jump to the step labeled return.
|
||||
// For simplicity, we currently make the caller do this. However, this means we can't throw exceptions at this point like the spec wants us to.
|
||||
|
||||
// 9. Let callResult be Completion(Construct(F, jsArgs)).
|
||||
// 10. Let callResult be Completion(Construct(F, jsArgs)).
|
||||
auto call_result = JS::construct(function_object->vm(), as<JS::FunctionObject>(*function_object), args);
|
||||
|
||||
// 10. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
// 11. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
if (call_result.is_throw_completion()) {
|
||||
completion = call_result.throw_completion();
|
||||
}
|
||||
// 11. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as
|
||||
// 12. Set completion to the result of converting callResult.[[Value]] to an IDL value of the same type as
|
||||
// callable’s return type.
|
||||
// If this throws an exception, set completion to the completion value representing the thrown exception.
|
||||
else {
|
||||
@@ -423,13 +430,13 @@ JS::Completion construct(CallbackType& callable, ReadonlySpan<JS::Value> args)
|
||||
completion = JS::Value(call_result.value());
|
||||
}
|
||||
|
||||
// 12. Return: at this point completion will be set to an IDL value or an abrupt completion.
|
||||
// 13. Return: at this point completion will be set to an IDL value or an abrupt completion.
|
||||
{
|
||||
// 1. Clean up after running a callback with stored realm.
|
||||
HTML::clean_up_after_running_callback(stored_realm);
|
||||
// 1. Clean up after running a callback with stored settings.
|
||||
HTML::clean_up_after_running_callback(stored_settings);
|
||||
|
||||
// 2. Clean up after running script with relevant realm.
|
||||
HTML::clean_up_after_running_script(relevant_realm);
|
||||
// 2. Clean up after running script with relevant settings.
|
||||
HTML::clean_up_after_running_script(relevant_settings);
|
||||
|
||||
// 3. If completion is an abrupt completion, throw completion.[[Value]].
|
||||
if (completion.is_abrupt())
|
||||
|
||||
Reference in New Issue
Block a user