Create internal fields on global proxy objects
BUG=v8:5588 R=verwaest@chromium.org Review-Url: https://codereview.chromium.org/2467463002 Cr-Commit-Position: refs/heads/master@{#40670}
This commit is contained in:
parent
70dfb5a0d6
commit
26547761ef
@ -7870,6 +7870,11 @@ class V8_EXPORT ExtensionConfiguration {
|
||||
const char** names_;
|
||||
};
|
||||
|
||||
#ifndef V8_CONTEXT_PROXY_INTERNAL_FIELD_COUNT
|
||||
// The number of required internal fields for global proxy objects can be
|
||||
// defined by embedder.
|
||||
#define V8_CONTEXT_PROXY_INTERNAL_FIELD_COUNT 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A sandboxed execution context with its own set of built-in objects
|
||||
@ -8068,6 +8073,9 @@ class V8_EXPORT Context {
|
||||
Local<Context> context_;
|
||||
};
|
||||
|
||||
static const int kProxyInternalFieldCount =
|
||||
V8_CONTEXT_PROXY_INTERNAL_FIELD_COUNT;
|
||||
|
||||
private:
|
||||
friend class Value;
|
||||
friend class Script;
|
||||
|
@ -643,6 +643,7 @@ Handle<JSFunction> ApiNatives::CreateApiFunction(
|
||||
case GlobalProxyType:
|
||||
type = JS_GLOBAL_PROXY_TYPE;
|
||||
instance_size += JSGlobalProxy::kSize;
|
||||
DCHECK_EQ(instance_size, JSGlobalProxy::kSizeWithInternalFields);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
|
@ -6075,6 +6075,9 @@ static i::Handle<ObjectType> CreateEnvironment(
|
||||
proxy_constructor->set_prototype_template(
|
||||
*Utils::OpenHandle(*global_template));
|
||||
|
||||
proxy_template->SetInternalFieldCount(
|
||||
v8::Context::kProxyInternalFieldCount);
|
||||
|
||||
// Migrate security handlers from global_template to
|
||||
// proxy_template. Temporarily removing access check
|
||||
// information from the global template.
|
||||
|
@ -960,8 +960,9 @@ Handle<JSGlobalObject> Genesis::CreateNewGlobals(
|
||||
if (global_proxy_template.IsEmpty()) {
|
||||
Handle<String> name = Handle<String>(heap()->empty_string());
|
||||
Handle<Code> code = isolate()->builtins()->Illegal();
|
||||
global_proxy_function = factory()->NewFunction(
|
||||
name, code, JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
|
||||
global_proxy_function =
|
||||
factory()->NewFunction(name, code, JS_GLOBAL_PROXY_TYPE,
|
||||
JSGlobalProxy::kSizeWithInternalFields);
|
||||
} else {
|
||||
Handle<ObjectTemplateInfo> data =
|
||||
v8::Utils::OpenHandle(*global_proxy_template);
|
||||
@ -4519,9 +4520,11 @@ Genesis::Genesis(Isolate* isolate,
|
||||
Handle<JSFunction> global_proxy_function =
|
||||
isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
||||
initial_map, shared, factory()->undefined_value());
|
||||
DCHECK_EQ(global_proxy_data->internal_field_count(), 0);
|
||||
DCHECK_EQ(global_proxy_data->internal_field_count(),
|
||||
v8::Context::kProxyInternalFieldCount);
|
||||
Handle<Map> global_proxy_map = isolate->factory()->NewMap(
|
||||
JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize, FAST_HOLEY_SMI_ELEMENTS);
|
||||
JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSizeWithInternalFields,
|
||||
FAST_HOLEY_SMI_ELEMENTS);
|
||||
JSFunction::SetInitialMap(global_proxy_function, global_proxy_map,
|
||||
factory()->null_value());
|
||||
global_proxy_map->set_is_access_check_needed(true);
|
||||
|
@ -2182,7 +2182,8 @@ Handle<JSProxy> Factory::NewJSProxy(Handle<JSReceiver> target,
|
||||
Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() {
|
||||
// Create an empty shell of a JSGlobalProxy that needs to be reinitialized
|
||||
// via ReinitializeJSGlobalProxy later.
|
||||
Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
|
||||
Handle<Map> map =
|
||||
NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSizeWithInternalFields);
|
||||
// Maintain invariant expected from any JSGlobalProxy.
|
||||
map->set_is_access_check_needed(true);
|
||||
CALL_HEAP_FUNCTION(
|
||||
|
@ -8509,6 +8509,8 @@ class JSGlobalProxy : public JSObject {
|
||||
static const int kNativeContextOffset = JSObject::kHeaderSize;
|
||||
static const int kHashOffset = kNativeContextOffset + kPointerSize;
|
||||
static const int kSize = kHashOffset + kPointerSize;
|
||||
static const int kSizeWithInternalFields =
|
||||
kSize + v8::Context::kProxyInternalFieldCount * kPointerSize;
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
|
||||
|
@ -25939,3 +25939,14 @@ TEST(EvalInAccessCheckedContext) {
|
||||
CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
|
||||
context1->Exit();
|
||||
}
|
||||
|
||||
TEST(InternalFieldsOnGlobalProxy) {
|
||||
v8::Isolate* isolate = CcTest::isolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = Context::New(isolate, nullptr, obj_template);
|
||||
v8::Local<v8::Object> global = context->Global();
|
||||
CHECK_EQ(v8::Context::kProxyInternalFieldCount, global->InternalFieldCount());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user