Commit 093019ee authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

Make CreateDynamicFunction switch context before throwing

In https://chromium-review.googlesource.com/c/v8/v8/+/2124837 we
changed the behavior of CreateDynamicFunction such that it throws
a TypeError if the operation is disallowed. The TypeError
constructor was taken from the target context, which didn't make
a lot of sense: the entered context doesn't have access to
the function ctor's context, so it won't have access to an
exception created in the function ctor's context either.

With this CL, the TypeError constructor is taken from the entered
context instead. Note that this is not necessarily the calling
context (we don't generally know the calling context at this point).

Bug: v8:10361, chromium:1065094
Change-Id: I09daa1f913a7e33841eb7fa0c00fca435df64b2f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2127866Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Auto-Submit: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66918}
parent e7cb911a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/api/api-inl.h"
#include "src/builtins/builtins-utils-inl.h" #include "src/builtins/builtins-utils-inl.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/codegen/code-factory.h" #include "src/codegen/code-factory.h"
...@@ -31,6 +32,11 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate, ...@@ -31,6 +32,11 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) { if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) {
isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined); isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined);
// TODO(verwaest): We would like to throw using the calling context instead
// of the entered context but we don't currently have access to that.
HandleScopeImplementer* impl = isolate->handle_scope_implementer();
SaveAndSwitchContext save(
isolate, impl->LastEnteredOrMicrotaskContext()->native_context());
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kNoAccess), Object); THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kNoAccess), Object);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment