Commit 08743307 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[ApiNatives] Eliminate old enum and TODO

- Removes ApiNativeType enum, using InstanceType instead.
- Replaces switch with JSObject::GetInstanceSize call.

Bug: v8:8015
Change-Id: I1c952792a068ec4f46a03ec47dce578d632e7cc3
Reviewed-on: https://chromium-review.googlesource.com/1199905Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55972}
parent 32aef42a
......@@ -496,8 +496,15 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
parent_prototype);
}
}
InstanceType function_type =
(!data->needs_access_check() &&
data->named_property_handler()->IsUndefined(isolate) &&
data->indexed_property_handler()->IsUndefined(isolate))
? JS_API_OBJECT_TYPE
: JS_SPECIAL_API_OBJECT_TYPE;
Handle<JSFunction> function = ApiNatives::CreateApiFunction(
isolate, data, prototype, ApiNatives::JavaScriptObjectType, maybe_name);
isolate, data, prototype, function_type, maybe_name);
if (serial_number) {
// Cache the function.
CacheTemplateInstantiation(isolate, serial_number, CachingMode::kUnlimited,
......@@ -626,8 +633,7 @@ void ApiNatives::AddNativeDataProperty(Isolate* isolate,
Handle<JSFunction> ApiNatives::CreateApiFunction(
Isolate* isolate, Handle<FunctionTemplateInfo> obj,
Handle<Object> prototype, ApiInstanceType instance_type,
MaybeHandle<Name> maybe_name) {
Handle<Object> prototype, InstanceType type, MaybeHandle<Name> maybe_name) {
Handle<SharedFunctionInfo> shared =
FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj,
maybe_name);
......@@ -671,33 +677,10 @@ Handle<JSFunction> ApiNatives::CreateApiFunction(
immutable_proto = instance_template->immutable_proto();
}
// TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
// JSObject::GetHeaderSize.
int instance_size = kPointerSize * embedder_field_count;
InstanceType type;
switch (instance_type) {
case JavaScriptObjectType:
if (!obj->needs_access_check() &&
obj->named_property_handler()->IsUndefined(isolate) &&
obj->indexed_property_handler()->IsUndefined(isolate)) {
type = JS_API_OBJECT_TYPE;
} else {
type = JS_SPECIAL_API_OBJECT_TYPE;
}
instance_size += JSObject::kHeaderSize;
break;
case GlobalObjectType:
type = JS_GLOBAL_OBJECT_TYPE;
instance_size += JSGlobalObject::kSize;
break;
case GlobalProxyType:
type = JS_GLOBAL_PROXY_TYPE;
instance_size += JSGlobalProxy::kSize;
break;
default:
UNREACHABLE();
break;
}
// JS_FUNCTION_TYPE requires information about the prototype slot.
DCHECK_NE(JS_FUNCTION_TYPE, type);
int instance_size =
JSObject::GetHeaderSize(type) + kPointerSize * embedder_field_count;
Handle<Map> map = isolate->factory()->NewMap(type, instance_size,
TERMINAL_FAST_ELEMENTS_KIND);
......
......@@ -9,6 +9,7 @@
#include "src/base/macros.h"
#include "src/handles.h"
#include "src/maybe-handles.h"
#include "src/objects.h"
#include "src/property-details.h"
namespace v8 {
......@@ -33,15 +34,9 @@ class ApiNatives {
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> InstantiateRemoteObject(
Handle<ObjectTemplateInfo> data);
enum ApiInstanceType {
JavaScriptObjectType,
GlobalObjectType,
GlobalProxyType
};
static Handle<JSFunction> CreateApiFunction(
Isolate* isolate, Handle<FunctionTemplateInfo> obj,
Handle<Object> prototype, ApiInstanceType instance_type,
Handle<Object> prototype, InstanceType type,
MaybeHandle<Name> name = MaybeHandle<Name>());
static void AddDataProperty(Isolate* isolate, Handle<TemplateInfo> info,
......
......@@ -1267,7 +1267,7 @@ Handle<JSGlobalObject> Genesis::CreateNewGlobals(
isolate());
js_global_object_function = ApiNatives::CreateApiFunction(
isolate(), js_global_object_constructor, factory()->the_hole_value(),
ApiNatives::GlobalObjectType);
JS_GLOBAL_OBJECT_TYPE);
}
js_global_object_function->initial_map()->set_is_prototype_map(true);
......@@ -1293,7 +1293,7 @@ Handle<JSGlobalObject> Genesis::CreateNewGlobals(
FunctionTemplateInfo::cast(data->constructor()), isolate());
global_proxy_function = ApiNatives::CreateApiFunction(
isolate(), global_constructor, factory()->the_hole_value(),
ApiNatives::GlobalProxyType);
JS_GLOBAL_PROXY_TYPE);
}
global_proxy_function->initial_map()->set_is_access_check_needed(true);
global_proxy_function->initial_map()->set_has_hidden_prototype(true);
......
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