mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-28 12:18:56 +00:00
LibJS: Update HostEnsureCanCompileStrings arguments to latest spec
This commit is contained in:
parent
6da0ac3aa7
commit
c1998f96c2
Notes:
github-actions[bot]
2024-11-05 00:16:51 +00:00
Author: https://github.com/shannonbooth
Commit: c1998f96c2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2134
Reviewed-by: https://github.com/ADKaster ✅
6 changed files with 21 additions and 18 deletions
|
@ -511,13 +511,14 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
|
||||||
// 2. If Type(x) is not String, return x.
|
// 2. If Type(x) is not String, return x.
|
||||||
if (!x.is_string())
|
if (!x.is_string())
|
||||||
return x;
|
return x;
|
||||||
|
auto& code_string = x.as_string();
|
||||||
|
|
||||||
// 3. Let evalRealm be the current Realm Record.
|
// 3. Let evalRealm be the current Realm Record.
|
||||||
auto& eval_realm = *vm.running_execution_context().realm;
|
auto& eval_realm = *vm.running_execution_context().realm;
|
||||||
|
|
||||||
// 4. NOTE: In the case of a direct eval, evalRealm is the realm of both the caller of eval and of the eval function itself.
|
// 4. NOTE: In the case of a direct eval, evalRealm is the realm of both the caller of eval and of the eval function itself.
|
||||||
// 5. Perform ? HostEnsureCanCompileStrings(evalRealm).
|
// 5. Perform ? HostEnsureCanCompileStrings(evalRealm, « », x, direct).
|
||||||
TRY(vm.host_ensure_can_compile_strings(eval_realm));
|
TRY(vm.host_ensure_can_compile_strings(eval_realm, {}, code_string.utf8_string_view(), direct));
|
||||||
|
|
||||||
// 6. Let inFunction be false.
|
// 6. Let inFunction be false.
|
||||||
bool in_function = false;
|
bool in_function = false;
|
||||||
|
@ -571,8 +572,6 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
|
||||||
// f. If inMethod is false, and body Contains SuperProperty, throw a SyntaxError exception.
|
// f. If inMethod is false, and body Contains SuperProperty, throw a SyntaxError exception.
|
||||||
// g. If inDerivedConstructor is false, and body Contains SuperCall, throw a SyntaxError exception.
|
// g. If inDerivedConstructor is false, and body Contains SuperCall, throw a SyntaxError exception.
|
||||||
// h. If inClassFieldInitializer is true, and ContainsArguments of body is true, throw a SyntaxError exception.
|
// h. If inClassFieldInitializer is true, and ContainsArguments of body is true, throw a SyntaxError exception.
|
||||||
auto& code_string = x.as_string();
|
|
||||||
|
|
||||||
Parser::EvalInitialState initial_state {
|
Parser::EvalInitialState initial_state {
|
||||||
.in_eval_function_context = in_function,
|
.in_eval_function_context = in_function,
|
||||||
.allow_super_property_lookup = in_method,
|
.allow_super_property_lookup = in_method,
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <LibJS/Runtime/Iterator.h>
|
#include <LibJS/Runtime/Iterator.h>
|
||||||
#include <LibJS/Runtime/KeyedCollections.h>
|
#include <LibJS/Runtime/KeyedCollections.h>
|
||||||
#include <LibJS/Runtime/PrivateEnvironment.h>
|
#include <LibJS/Runtime/PrivateEnvironment.h>
|
||||||
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
@ -67,10 +68,7 @@ enum class CallerMode {
|
||||||
Strict,
|
Strict,
|
||||||
NonStrict
|
NonStrict
|
||||||
};
|
};
|
||||||
enum class EvalMode {
|
|
||||||
Direct,
|
|
||||||
Indirect
|
|
||||||
};
|
|
||||||
ThrowCompletionOr<Value> perform_eval(VM&, Value, CallerMode, EvalMode);
|
ThrowCompletionOr<Value> perform_eval(VM&, Value, CallerMode, EvalMode);
|
||||||
|
|
||||||
ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& program, Environment* variable_environment, Environment* lexical_environment, PrivateEnvironment* private_environment, bool strict);
|
ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& program, Environment* variable_environment, Environment* lexical_environment, PrivateEnvironment* private_environment, bool strict);
|
||||||
|
|
|
@ -142,8 +142,8 @@ ThrowCompletionOr<NonnullGCPtr<ECMAScriptFunctionObject>> FunctionConstructor::c
|
||||||
// 10. Let currentRealm be the current Realm Record.
|
// 10. Let currentRealm be the current Realm Record.
|
||||||
auto& realm = *vm.current_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// FIXME: 11. Perform ? HostEnsureCanCompileStrings(currentRealm, parameterStrings, bodyString, false).
|
// 11. Perform ? HostEnsureCanCompileStrings(currentRealm, parameterStrings, bodyString, false).
|
||||||
TRY(vm.host_ensure_can_compile_strings(current_realm));
|
TRY(vm.host_ensure_can_compile_strings(realm, parameter_strings, body_string, EvalMode::Indirect));
|
||||||
|
|
||||||
// 12. Let P be the empty String.
|
// 12. Let P be the empty String.
|
||||||
String parameters_string;
|
String parameters_string;
|
||||||
|
|
|
@ -95,9 +95,8 @@ ThrowCompletionOr<void> copy_name_and_length(VM& vm, FunctionObject& function, F
|
||||||
// 3.1.3 PerformShadowRealmEval ( sourceText: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, ), 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(VM& vm, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_text, Realm& caller_realm, Realm& eval_realm)
|
||||||
{
|
{
|
||||||
// FIXME: Needs to be updated to latest ECMA-262. See: https://github.com/tc39/proposal-shadowrealm/issues/367
|
// 1. Perform ? HostEnsureCanCompileStrings(evalRealm, « », sourceText, false).
|
||||||
// 1. Perform ? HostEnsureCanCompileStrings(callerRealm, evalRealm).
|
TRY(vm.host_ensure_can_compile_strings(eval_realm, {}, source_text, EvalMode::Indirect));
|
||||||
TRY(vm.host_ensure_can_compile_strings(eval_realm));
|
|
||||||
|
|
||||||
// 2. 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:
|
||||||
|
|
||||||
|
|
|
@ -120,10 +120,12 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
||||||
return Vector<ByteString> { "type" };
|
return Vector<ByteString> { "type" };
|
||||||
};
|
};
|
||||||
|
|
||||||
// 19.2.1.2 HostEnsureCanCompileStrings ( callerRealm, calleeRealm ), https://tc39.es/ecma262/#sec-hostensurecancompilestrings
|
// 19.2.1.2 HostEnsureCanCompileStrings ( calleeRealm, parameterStrings, bodyString, direct ), https://tc39.es/ecma262/#sec-hostensurecancompilestrings
|
||||||
host_ensure_can_compile_strings = [](Realm&) -> ThrowCompletionOr<void> {
|
host_ensure_can_compile_strings = [](Realm&, ReadonlySpan<String>, StringView, EvalMode) -> ThrowCompletionOr<void> {
|
||||||
// The host-defined abstract operation HostEnsureCanCompileStrings takes argument calleeRealm (a Realm Record)
|
// The host-defined abstract operation HostEnsureCanCompileStrings takes arguments calleeRealm (a Realm Record),
|
||||||
// and returns either a normal completion containing unused or a throw completion.
|
// parameterStrings (a List of Strings), bodyString (a String), and direct (a Boolean) and returns either a normal
|
||||||
|
// completion containing unused or a throw completion.
|
||||||
|
//
|
||||||
// It allows host environments to block certain ECMAScript functions which allow developers to compile strings into ECMAScript code.
|
// It allows host environments to block certain ECMAScript functions which allow developers to compile strings into ECMAScript code.
|
||||||
// An implementation of HostEnsureCanCompileStrings must conform to the following requirements:
|
// An implementation of HostEnsureCanCompileStrings must conform to the following requirements:
|
||||||
// - If the returned Completion Record is a normal completion, it must be a normal completion containing unused.
|
// - If the returned Completion Record is a normal completion, it must be a normal completion containing unused.
|
||||||
|
|
|
@ -37,6 +37,11 @@ enum class HandledByHost {
|
||||||
Unhandled,
|
Unhandled,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class EvalMode {
|
||||||
|
Direct,
|
||||||
|
Indirect
|
||||||
|
};
|
||||||
|
|
||||||
class VM : public RefCounted<VM> {
|
class VM : public RefCounted<VM> {
|
||||||
public:
|
public:
|
||||||
struct CustomData {
|
struct CustomData {
|
||||||
|
@ -276,7 +281,7 @@ public:
|
||||||
Function<void(FinalizationRegistry&)> host_enqueue_finalization_registry_cleanup_job;
|
Function<void(FinalizationRegistry&)> host_enqueue_finalization_registry_cleanup_job;
|
||||||
Function<void(NonnullGCPtr<HeapFunction<ThrowCompletionOr<Value>()>>, Realm*)> host_enqueue_promise_job;
|
Function<void(NonnullGCPtr<HeapFunction<ThrowCompletionOr<Value>()>>, Realm*)> host_enqueue_promise_job;
|
||||||
Function<JS::NonnullGCPtr<JobCallback>(FunctionObject&)> host_make_job_callback;
|
Function<JS::NonnullGCPtr<JobCallback>(FunctionObject&)> host_make_job_callback;
|
||||||
Function<ThrowCompletionOr<void>(Realm&)> host_ensure_can_compile_strings;
|
Function<ThrowCompletionOr<void>(Realm&, ReadonlySpan<String>, StringView, EvalMode)> host_ensure_can_compile_strings;
|
||||||
Function<ThrowCompletionOr<void>(Object&)> host_ensure_can_add_private_element;
|
Function<ThrowCompletionOr<void>(Object&)> host_ensure_can_add_private_element;
|
||||||
Function<ThrowCompletionOr<HandledByHost>(ArrayBuffer&, size_t)> host_resize_array_buffer;
|
Function<ThrowCompletionOr<HandledByHost>(ArrayBuffer&, size_t)> host_resize_array_buffer;
|
||||||
Function<void(StringView)> host_unrecognized_date_string;
|
Function<void(StringView)> host_unrecognized_date_string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue