Browse Source

LibJS: Make prepare_for_ordinary_call() new_target parameter an Object*

This got changed in the spec at some point, replacing the assertion in
step 1 with "... and newTarget (an Object or undefined)" in the
parameter description.
Subsequently, there's now one step less, so the numbers all change.
Linus Groh 3 years ago
parent
commit
15c33477e4
2 changed files with 17 additions and 20 deletions
  1. 16 19
      Userland/Libraries/LibJS/Runtime/VM.cpp
  2. 1 1
      Userland/Libraries/LibJS/Runtime/VM.h

+ 16 - 19
Userland/Libraries/LibJS/Runtime/VM.cpp

@@ -576,7 +576,7 @@ Value VM::get_new_target()
 }
 }
 
 
 // 10.2.1.1 PrepareForOrdinaryCall ( F, newTarget ), https://tc39.es/ecma262/#sec-prepareforordinarycall
 // 10.2.1.1 PrepareForOrdinaryCall ( F, newTarget ), https://tc39.es/ecma262/#sec-prepareforordinarycall
-void VM::prepare_for_ordinary_call(FunctionObject& function, ExecutionContext& callee_context, Value new_target)
+void VM::prepare_for_ordinary_call(FunctionObject& function, ExecutionContext& callee_context, [[maybe_unused]] Object* new_target)
 {
 {
     // NOTE: This is a LibJS specific hack for NativeFunction to inherit the strictness of its caller.
     // NOTE: This is a LibJS specific hack for NativeFunction to inherit the strictness of its caller.
     // FIXME: I feel like we should be able to get rid of this.
     // FIXME: I feel like we should be able to get rid of this.
@@ -585,46 +585,43 @@ void VM::prepare_for_ordinary_call(FunctionObject& function, ExecutionContext& c
     else
     else
         callee_context.is_strict_mode = function.is_strict_mode();
         callee_context.is_strict_mode = function.is_strict_mode();
 
 
-    // 1. Assert: Type(newTarget) is Undefined or Object.
-    VERIFY(new_target.is_undefined() || new_target.is_object());
-
-    // 2. Let callerContext be the running execution context.
-    // 3. Let calleeContext be a new ECMAScript code execution context.
+    // 1. Let callerContext be the running execution context.
+    // 2. Let calleeContext be a new ECMAScript code execution context.
 
 
     // NOTE: In the specification, PrepareForOrdinaryCall "returns" a new callee execution context.
     // NOTE: In the specification, PrepareForOrdinaryCall "returns" a new callee execution context.
     // To avoid heap allocations, we put our ExecutionContext objects on the C++ stack instead.
     // To avoid heap allocations, we put our ExecutionContext objects on the C++ stack instead.
     // Whoever calls us should put an ExecutionContext on their stack and pass that as the `callee_context`.
     // Whoever calls us should put an ExecutionContext on their stack and pass that as the `callee_context`.
 
 
-    // 4. Set the Function of calleeContext to F.
+    // 3. Set the Function of calleeContext to F.
     callee_context.function = &function;
     callee_context.function = &function;
     callee_context.function_name = function.name();
     callee_context.function_name = function.name();
 
 
-    // 5. Let calleeRealm be F.[[Realm]].
-    // 6. Set the Realm of calleeContext to calleeRealm.
-    // 7. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
+    // 4. Let calleeRealm be F.[[Realm]].
+    // 5. Set the Realm of calleeContext to calleeRealm.
+    // 6. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
     // FIXME: Our execution context struct currently does not track these items.
     // FIXME: Our execution context struct currently does not track these items.
 
 
-    // 8. Let localEnv be NewFunctionEnvironment(F, newTarget).
+    // 7. Let localEnv be NewFunctionEnvironment(F, newTarget).
     // FIXME: This should call NewFunctionEnvironment instead of the ad-hoc FunctionObject::create_environment()
     // FIXME: This should call NewFunctionEnvironment instead of the ad-hoc FunctionObject::create_environment()
     auto* local_environment = function.create_environment(function);
     auto* local_environment = function.create_environment(function);
 
 
-    // 9. Set the LexicalEnvironment of calleeContext to localEnv.
+    // 8. Set the LexicalEnvironment of calleeContext to localEnv.
     callee_context.lexical_environment = local_environment;
     callee_context.lexical_environment = local_environment;
 
 
-    // 10. Set the VariableEnvironment of calleeContext to localEnv.
+    // 9. Set the VariableEnvironment of calleeContext to localEnv.
     callee_context.variable_environment = local_environment;
     callee_context.variable_environment = local_environment;
 
 
-    // 11. Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
+    // 10. Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
     // FIXME: We currently don't support private environments.
     // FIXME: We currently don't support private environments.
 
 
-    // 12. If callerContext is not already suspended, suspend callerContext.
+    // 11. If callerContext is not already suspended, suspend callerContext.
     // FIXME: We don't have this concept yet.
     // FIXME: We don't have this concept yet.
 
 
-    // 13. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
+    // 12. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
     push_execution_context(callee_context, function.global_object());
     push_execution_context(callee_context, function.global_object());
 
 
-    // 14. NOTE: Any exception objects produced after this point are associated with calleeRealm.
-    // 15. Return calleeContext. (See NOTE above about how contexts are allocated on the C++ stack.)
+    // 13. NOTE: Any exception objects produced after this point are associated with calleeRealm.
+    // 14. Return calleeContext. (See NOTE above about how contexts are allocated on the C++ stack.)
 }
 }
 
 
 // 10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument ), https://tc39.es/ecma262/#sec-ordinarycallbindthis
 // 10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument ), https://tc39.es/ecma262/#sec-ordinarycallbindthis
@@ -672,7 +669,7 @@ Value VM::call_internal(FunctionObject& function, Value this_value, Optional<Mar
     }
     }
 
 
     ExecutionContext callee_context(heap());
     ExecutionContext callee_context(heap());
-    prepare_for_ordinary_call(function, callee_context, js_undefined());
+    prepare_for_ordinary_call(function, callee_context, nullptr);
     if (exception())
     if (exception())
         return {};
         return {};
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/VM.h

@@ -284,7 +284,7 @@ private:
     void ordinary_call_bind_this(FunctionObject&, ExecutionContext&, Value this_argument);
     void ordinary_call_bind_this(FunctionObject&, ExecutionContext&, Value this_argument);
 
 
     [[nodiscard]] Value call_internal(FunctionObject&, Value this_value, Optional<MarkedValueList> arguments);
     [[nodiscard]] Value call_internal(FunctionObject&, Value this_value, Optional<MarkedValueList> arguments);
-    void prepare_for_ordinary_call(FunctionObject&, ExecutionContext& callee_context, Value new_target);
+    void prepare_for_ordinary_call(FunctionObject&, ExecutionContext& callee_context, Object* new_target);
 
 
     Exception* m_exception { nullptr };
     Exception* m_exception { nullptr };