From 8064582626f4f2e012352750fda839ae3f975127 Mon Sep 17 00:00:00 2001 From: dcarney Date: Wed, 4 Feb 2015 05:01:34 -0800 Subject: [PATCH] Move the contents of api-natives.js to c++ R=verwaest@chromium.org BUG= Review URL: https://codereview.chromium.org/895053002 Cr-Commit-Position: refs/heads/master@{#26426} --- BUILD.gn | 4 +- include/v8.h | 2 +- src/api-natives.cc | 529 ++++++++++++++++++++++++++++++++++++++++++++ src/api-natives.h | 38 ++++ src/api.cc | 6 +- src/apinatives.js | 119 ---------- src/bootstrapper.cc | 23 +- src/builtins.cc | 5 +- src/contexts.h | 6 +- src/date.js | 6 + src/execution.cc | 67 ------ src/execution.h | 6 - src/factory.cc | 195 ---------------- src/factory.h | 17 -- src/macros.py | 18 -- src/runtime/runtime-api.cc | 127 ----------- src/runtime/runtime-i18n.cc | 9 +- src/runtime/runtime.h | 5 - test/cctest/test-api.cc | 8 +- tools/gyp/v8.gyp | 4 +- 20 files changed, 605 insertions(+), 589 deletions(-) create mode 100644 src/api-natives.cc create mode 100644 src/api-natives.h delete mode 100644 src/apinatives.js delete mode 100644 src/runtime/runtime-api.cc diff --git a/BUILD.gn b/BUILD.gn index bd5a2552..14b5613 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -175,7 +175,6 @@ action("js2c") { "src/uri.js", "src/third_party/fdlibm/fdlibm.js", "src/math.js", - "src/apinatives.js", "src/date.js", "src/regexp.js", "src/arraybuffer.js", @@ -453,6 +452,8 @@ source_set("v8_base") { "src/allocation-tracker.h", "src/api.cc", "src/api.h", + "src/api-natives.cc", + "src/api-natives.h", "src/arguments.cc", "src/arguments.h", "src/assembler.cc", @@ -890,7 +891,6 @@ source_set("v8_base") { "src/rewriter.h", "src/runtime-profiler.cc", "src/runtime-profiler.h", - "src/runtime/runtime-api.cc", "src/runtime/runtime-array.cc", "src/runtime/runtime-classes.cc", "src/runtime/runtime-collections.cc", diff --git a/include/v8.h b/include/v8.h index a799fce..8e62c93 100644 --- a/include/v8.h +++ b/include/v8.h @@ -6208,7 +6208,7 @@ class Internals { static const int kJSObjectHeaderSize = 3 * kApiPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; static const int kContextHeaderSize = 2 * kApiPointerSize; - static const int kContextEmbedderDataIndex = 76; + static const int kContextEmbedderDataIndex = 74; static const int kFullStringRepresentationMask = 0x07; static const int kStringEncodingMask = 0x4; static const int kExternalTwoByteRepresentationTag = 0x02; diff --git a/src/api-natives.cc b/src/api-natives.cc new file mode 100644 index 0000000..8233b8a --- /dev/null +++ b/src/api-natives.cc @@ -0,0 +1,529 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/api-natives.h" +#include "src/isolate-inl.h" + +namespace v8 { +namespace internal { + +namespace { + +// Transform getter or setter into something DefineAccessor can handle. +Handle InstantiateAccessorComponent(Isolate* isolate, + Handle component) { + if (component->IsUndefined()) return isolate->factory()->undefined_value(); + Handle info = + Handle::cast(component); + // TODO(dcarney): instantiate directly. + return Utils::OpenHandle(*Utils::ToLocal(info)->GetFunction()); +} + + +MaybeHandle DefineApiAccessorProperty( + Isolate* isolate, Handle object, Handle name, + Handle getter, Handle setter, Smi* attribute) { + DCHECK(PropertyDetails::AttributesField::is_valid( + static_cast(attribute->value()))); + RETURN_ON_EXCEPTION( + isolate, JSObject::DefineAccessor( + object, name, InstantiateAccessorComponent(isolate, getter), + InstantiateAccessorComponent(isolate, setter), + static_cast(attribute->value())), + Object); + return object; +} + + +MaybeHandle AddPropertyForTemplate(Isolate* isolate, + Handle object, + Handle key, + Handle value, + Smi* unchecked_attributes) { + DCHECK((unchecked_attributes->value() & + ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); + // Compute attributes. + PropertyAttributes attributes = + static_cast(unchecked_attributes->value()); + +#ifdef DEBUG + bool duplicate; + if (key->IsName()) { + LookupIterator it(object, Handle::cast(key), + LookupIterator::OWN_SKIP_INTERCEPTOR); + Maybe maybe = JSReceiver::GetPropertyAttributes(&it); + DCHECK(maybe.has_value); + duplicate = it.IsFound(); + } else { + uint32_t index = 0; + key->ToArrayIndex(&index); + Maybe maybe = JSReceiver::HasOwnElement(object, index); + if (!maybe.has_value) return MaybeHandle(); + duplicate = maybe.value; + } + if (duplicate) { + Handle args[1] = {key}; + THROW_NEW_ERROR(isolate, NewTypeError("duplicate_template_property", + HandleVector(args, 1)), + Object); + } +#endif + + RETURN_ON_EXCEPTION( + isolate, Runtime::DefineObjectProperty(object, key, value, attributes), + Object); + return object; +} + + +void DisableAccessChecks(Isolate* isolate, Handle object) { + Handle old_map(object->map()); + // Copy map so it won't interfere constructor's initial map. + Handle new_map = Map::Copy(old_map, "DisableAccessChecks"); + new_map->set_is_access_check_needed(false); + JSObject::MigrateToMap(Handle::cast(object), new_map); +} + + +void EnableAccessChecks(Isolate* isolate, Handle object) { + Handle old_map(object->map()); + // Copy map so it won't interfere constructor's initial map. + Handle new_map = Map::Copy(old_map, "EnableAccessChecks"); + new_map->set_is_access_check_needed(true); + JSObject::MigrateToMap(object, new_map); +} + + +MaybeHandle InstantiateObject(Isolate* isolate, + Handle data); + + +MaybeHandle InstantiateFunction(Isolate* isolate, + Handle data, + Handle name = Handle()); + + +MaybeHandle Instantiate(Isolate* isolate, Handle data, + Handle name = Handle()) { + if (data->IsFunctionTemplateInfo()) { + return InstantiateFunction(isolate, + Handle::cast(data), name); + } else if (data->IsObjectTemplateInfo()) { + return InstantiateObject(isolate, Handle::cast(data)); + } else { + // TODO(dcarney): CHECK data is JSObject or Primitive. + return data; + } +} + + +class AccessCheckDisableScope { + public: + AccessCheckDisableScope(Isolate* isolate, Handle obj) + : isolate_(isolate), + disabled_(obj->map()->is_access_check_needed()), + obj_(obj) { + if (disabled_) { + DisableAccessChecks(isolate_, obj_); + } + } + ~AccessCheckDisableScope() { + if (disabled_) { + EnableAccessChecks(isolate_, obj_); + } + } + + private: + Isolate* isolate_; + const bool disabled_; + Handle obj_; +}; + + +MaybeHandle ConfigureInstance(Isolate* isolate, Handle obj, + Handle data) { + auto property_list = handle(data->property_list(), isolate); + if (property_list->IsUndefined()) return obj; + // TODO(dcarney): just use a FixedArray here. + NeanderArray properties(property_list); + if (properties.length() == 0) return obj; + HandleScope scope(isolate); + // Disable access checks while instantiating the object. + AccessCheckDisableScope access_check_scope(isolate, obj); + for (int i = 0; i < properties.length();) { + int length = Smi::cast(properties.get(i))->value(); + if (length == 3) { + auto name = handle(Name::cast(properties.get(i + 1)), isolate); + auto prop_data = handle(properties.get(i + 2), isolate); + auto attributes = Smi::cast(properties.get(i + 3)); + Handle value; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, value, Instantiate(isolate, prop_data, name), JSObject); + RETURN_ON_EXCEPTION(isolate, AddPropertyForTemplate(isolate, obj, name, + value, attributes), + JSObject); + } else { + DCHECK(length == 4 || length == 5); + // TODO(verwaest): The 5th value used to be access_control. Remove once + // the bindings are updated. + auto name = handle(Name::cast(properties.get(i + 1)), isolate); + auto getter = handle(properties.get(i + 2), isolate); + auto setter = handle(properties.get(i + 3), isolate); + auto attributes = Smi::cast(properties.get(i + 4)); + RETURN_ON_EXCEPTION(isolate, + DefineApiAccessorProperty(isolate, obj, name, getter, + setter, attributes), + JSObject); + } + i += length + 1; + } + return obj; +} + + +MaybeHandle InstantiateObject(Isolate* isolate, + Handle data) { + // Enter a new scope. Recursion could otherwise create a lot of handles. + HandleScope scope(isolate); + // Fast path. + Handle result; + auto info = Handle::cast(data); + auto constructor = handle(info->constructor(), isolate); + Handle cons; + if (constructor->IsUndefined()) { + cons = isolate->object_function(); + } else { + auto cons_templ = Handle::cast(constructor); + ASSIGN_RETURN_ON_EXCEPTION( + isolate, cons, InstantiateFunction(isolate, cons_templ), JSFunction); + } + auto object = isolate->factory()->NewJSObject(cons); + ASSIGN_RETURN_ON_EXCEPTION( + isolate, result, ConfigureInstance(isolate, object, info), JSFunction); + // TODO(dcarney): is this necessary? + JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); + return scope.CloseAndEscape(result); +} + + +void InstallInCache(Isolate* isolate, int serial_number, + Handle function) { + auto cache = isolate->function_cache(); + if (cache->length() <= serial_number) { + int new_size; + if (isolate->next_serial_number() < 50) { + new_size = 100; + } else { + new_size = 3 * isolate->next_serial_number() / 2; + } + cache = FixedArray::CopySize(cache, new_size); + isolate->native_context()->set_function_cache(*cache); + } + cache->set(serial_number, *function); +} + + +MaybeHandle InstantiateFunction(Isolate* isolate, + Handle data, + Handle name) { + int serial_number = Smi::cast(data->serial_number())->value(); + // Probe cache. + if (!data->do_not_cache()) { + auto cache = isolate->function_cache(); + // Fast case: see if the function has already been instantiated + if (serial_number < cache->length()) { + Handle element = FixedArray::get(cache, serial_number); + if (element->IsJSFunction()) { + return Handle::cast(element); + } + } + } + // Enter a new scope. Recursion could otherwise create a lot of handles. + HandleScope scope(isolate); + Handle prototype; + if (!data->remove_prototype()) { + auto prototype_templ = handle(data->prototype_template(), isolate); + if (prototype_templ->IsUndefined()) { + prototype = isolate->factory()->NewJSObject(isolate->object_function()); + } else { + ASSIGN_RETURN_ON_EXCEPTION( + isolate, prototype, + InstantiateObject(isolate, + Handle::cast(prototype_templ)), + JSFunction); + } + auto parent = handle(data->parent_template(), isolate); + if (!parent->IsUndefined()) { + Handle parent_instance; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, parent_instance, + InstantiateFunction(isolate, + Handle::cast(parent)), + JSFunction); + // TODO(dcarney): decide what to do here. + Handle parent_prototype; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, parent_prototype, + JSObject::GetProperty(parent_instance, + isolate->factory()->prototype_string()), + JSFunction); + RETURN_ON_EXCEPTION( + isolate, JSObject::SetPrototype(prototype, parent_prototype, false), + JSFunction); + } + } + auto function = ApiNatives::CreateApiFunction( + isolate, data, prototype, ApiNatives::JavaScriptObjectType); + if (!name.is_null() && name->IsString()) { + function->shared()->set_name(*name); + } + if (!data->do_not_cache()) { + // Cache the function to limit recursion. + InstallInCache(isolate, serial_number, function); + } + auto result = ConfigureInstance(isolate, function, data); + if (result.is_null()) { + // uncache on error. + if (!data->do_not_cache()) { + auto cache = isolate->function_cache(); + cache->set(serial_number, isolate->heap()->undefined_value()); + } + return MaybeHandle(); + } + return scope.CloseAndEscape(function); +} + + +class InvokeScope { + public: + explicit InvokeScope(Isolate* isolate) + : isolate_(isolate), save_context_(isolate) {} + ~InvokeScope() { + bool has_exception = isolate_->has_pending_exception(); + if (has_exception) { + isolate_->ReportPendingMessages(); + } else { + isolate_->clear_pending_message(); + } + } + + private: + Isolate* isolate_; + SaveContext save_context_; +}; + +} // namespace + + +MaybeHandle ApiNatives::InstantiateFunction( + Handle data) { + Isolate* isolate = data->GetIsolate(); + InvokeScope invoke_scope(isolate); + return ::v8::internal::InstantiateFunction(isolate, data); +} + + +MaybeHandle ApiNatives::InstantiateObject( + Handle data) { + Isolate* isolate = data->GetIsolate(); + InvokeScope invoke_scope(isolate); + return ::v8::internal::InstantiateObject(isolate, data); +} + + +MaybeHandle ApiNatives::ConfigureInstance( + Isolate* isolate, Handle desc, + Handle instance) { + // Configure the instance by adding the properties specified by the + // instance template. + if (desc->instance_template()->IsUndefined()) return desc; + InvokeScope invoke_scope(isolate); + Handle instance_template( + ObjectTemplateInfo::cast(desc->instance_template()), isolate); + RETURN_ON_EXCEPTION(isolate, ::v8::internal::ConfigureInstance( + isolate, instance, instance_template), + FunctionTemplateInfo); + return desc; +} + + +Handle ApiNatives::CreateApiFunction( + Isolate* isolate, Handle obj, + Handle prototype, ApiInstanceType instance_type) { + Handle code = isolate->builtins()->HandleApiCall(); + Handle construct_stub = isolate->builtins()->JSConstructStubApi(); + + obj->set_instantiated(true); + Handle result; + if (obj->remove_prototype()) { + result = isolate->factory()->NewFunctionWithoutPrototype( + isolate->factory()->empty_string(), code); + } else { + int internal_field_count = 0; + if (!obj->instance_template()->IsUndefined()) { + Handle instance_template = Handle( + ObjectTemplateInfo::cast(obj->instance_template())); + internal_field_count = + Smi::cast(instance_template->internal_field_count())->value(); + } + + // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing + // JSObject::GetHeaderSize. + int instance_size = kPointerSize * internal_field_count; + InstanceType type; + switch (instance_type) { + case JavaScriptObjectType: + type = JS_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(); + type = JS_OBJECT_TYPE; // Keep the compiler happy. + break; + } + + result = isolate->factory()->NewFunction( + isolate->factory()->empty_string(), code, prototype, type, + instance_size, obj->read_only_prototype(), true); + } + + result->shared()->set_length(obj->length()); + Handle class_name(obj->class_name(), isolate); + if (class_name->IsString()) { + result->shared()->set_instance_class_name(*class_name); + result->shared()->set_name(*class_name); + } + result->shared()->set_function_data(*obj); + result->shared()->set_construct_stub(*construct_stub); + result->shared()->DontAdaptArguments(); + + if (obj->remove_prototype()) { + DCHECK(result->shared()->IsApiFunction()); + DCHECK(!result->has_initial_map()); + DCHECK(!result->has_prototype()); + return result; + } + +#ifdef DEBUG + LookupIterator it(handle(JSObject::cast(result->prototype())), + isolate->factory()->constructor_string(), + LookupIterator::OWN_SKIP_INTERCEPTOR); + MaybeHandle maybe_prop = Object::GetProperty(&it); + DCHECK(it.IsFound()); + DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result)); +#endif + + // Down from here is only valid for API functions that can be used as a + // constructor (don't set the "remove prototype" flag). + + Handle map(result->initial_map()); + + // Mark as undetectable if needed. + if (obj->undetectable()) { + map->set_is_undetectable(); + } + + // Mark as hidden for the __proto__ accessor if needed. + if (obj->hidden_prototype()) { + map->set_is_hidden_prototype(); + } + + // Mark as needs_access_check if needed. + if (obj->needs_access_check()) { + map->set_is_access_check_needed(true); + } + + // Set interceptor information in the map. + if (!obj->named_property_handler()->IsUndefined()) { + map->set_has_named_interceptor(); + } + if (!obj->indexed_property_handler()->IsUndefined()) { + map->set_has_indexed_interceptor(); + } + + // Set instance call-as-function information in the map. + if (!obj->instance_call_handler()->IsUndefined()) { + map->set_has_instance_call_handler(); + } + + // Recursively copy parent instance templates' accessors, + // 'data' may be modified. + int max_number_of_additional_properties = 0; + int max_number_of_static_properties = 0; + FunctionTemplateInfo* info = *obj; + while (true) { + if (!info->instance_template()->IsUndefined()) { + Object* props = ObjectTemplateInfo::cast(info->instance_template()) + ->property_accessors(); + if (!props->IsUndefined()) { + Handle props_handle(props, isolate); + NeanderArray props_array(props_handle); + max_number_of_additional_properties += props_array.length(); + } + } + if (!info->property_accessors()->IsUndefined()) { + Object* props = info->property_accessors(); + if (!props->IsUndefined()) { + Handle props_handle(props, isolate); + NeanderArray props_array(props_handle); + max_number_of_static_properties += props_array.length(); + } + } + Object* parent = info->parent_template(); + if (parent->IsUndefined()) break; + info = FunctionTemplateInfo::cast(parent); + } + + Map::EnsureDescriptorSlack(map, max_number_of_additional_properties); + + // Use a temporary FixedArray to acculumate static accessors + int valid_descriptors = 0; + Handle array; + if (max_number_of_static_properties > 0) { + array = isolate->factory()->NewFixedArray(max_number_of_static_properties); + } + + while (true) { + // Install instance descriptors + if (!obj->instance_template()->IsUndefined()) { + Handle instance = Handle( + ObjectTemplateInfo::cast(obj->instance_template()), isolate); + Handle props = + Handle(instance->property_accessors(), isolate); + if (!props->IsUndefined()) { + Map::AppendCallbackDescriptors(map, props); + } + } + // Accumulate static accessors + if (!obj->property_accessors()->IsUndefined()) { + Handle props = Handle(obj->property_accessors(), isolate); + valid_descriptors = + AccessorInfo::AppendUnique(props, array, valid_descriptors); + } + // Climb parent chain + Handle parent = Handle(obj->parent_template(), isolate); + if (parent->IsUndefined()) break; + obj = Handle::cast(parent); + } + + // Install accumulated static accessors + for (int i = 0; i < valid_descriptors; i++) { + Handle accessor(AccessorInfo::cast(array->get(i))); + JSObject::SetAccessor(result, accessor).Assert(); + } + + DCHECK(result->shared()->IsApiFunction()); + return result; +} + +} // namespace internal +} // namespace v8 diff --git a/src/api-natives.h b/src/api-natives.h new file mode 100644 index 0000000..8f93d64 --- /dev/null +++ b/src/api-natives.h @@ -0,0 +1,38 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_API_NATIVES_H_ +#define V8_API_NATIVES_H_ + +#include "src/handles.h" + +namespace v8 { +namespace internal { + +class ApiNatives { + public: + MUST_USE_RESULT static MaybeHandle InstantiateFunction( + Handle data); + MUST_USE_RESULT static MaybeHandle InstantiateObject( + Handle data); + MUST_USE_RESULT static MaybeHandle ConfigureInstance( + Isolate* isolate, Handle instance, + Handle data); + + enum ApiInstanceType { + JavaScriptObjectType, + GlobalObjectType, + GlobalProxyType + }; + + static Handle CreateApiFunction(Isolate* isolate, + Handle obj, + Handle prototype, + ApiInstanceType instance_type); +}; + +} // namespace internal +} // namespace v8 + +#endif diff --git a/src/api.cc b/src/api.cc index a6d950e..d6c0475 100644 --- a/src/api.cc +++ b/src/api.cc @@ -12,6 +12,7 @@ #include "include/v8-debug.h" #include "include/v8-profiler.h" #include "include/v8-testing.h" +#include "src/api-natives.h" #include "src/assert-scope.h" #include "src/background-parsing-task.h" #include "src/base/functional.h" @@ -5331,7 +5332,8 @@ Local ObjectTemplate::NewInstance() { ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); i::Handle obj; - has_pending_exception = !i::Execution::InstantiateObject(info).ToHandle(&obj); + has_pending_exception = + !i::ApiNatives::InstantiateObject(info).ToHandle(&obj); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Utils::ToLocal(i::Handle::cast(obj)); } @@ -5347,7 +5349,7 @@ Local FunctionTemplate::GetFunction() { EXCEPTION_PREAMBLE(isolate); i::Handle obj; has_pending_exception = - !i::Execution::InstantiateFunction(info).ToHandle(&obj); + !i::ApiNatives::InstantiateFunction(info).ToHandle(&obj); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Utils::ToLocal(i::Handle::cast(obj)); } diff --git a/src/apinatives.js b/src/apinatives.js deleted file mode 100644 index 3e38d10..0000000 --- a/src/apinatives.js +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -"use strict"; - -// This file contains infrastructure used by the API. See -// v8natives.js for an explanation of these files are processed and -// loaded. - - -function CreateDate(time) { - var date = new $Date(); - date.setTime(time); - return date; -} - - -var kApiFunctionCache = new InternalArray(); -var functionCache = kApiFunctionCache; - - -function Instantiate(data, name) { - if (!%IsTemplate(data)) return data; - var tag = %GetTemplateField(data, kApiTagOffset); - switch (tag) { - case kFunctionTag: - return InstantiateFunction(data, name); - case kNewObjectTag: - var Constructor = %GetTemplateField(data, kApiConstructorOffset); - // Note: Do not directly use a function template as a condition, our - // internal ToBoolean doesn't handle that! - var result; - if (typeof Constructor === 'undefined') { - result = {}; - ConfigureTemplateInstance(result, data); - } else { - // ConfigureTemplateInstance is implicitly called before calling the API - // constructor in HandleApiCall. - result = new (Instantiate(Constructor))(); - result = %ToFastProperties(result); - } - return result; - default: - throw 'Unknown API tag <' + tag + '>'; - } -} - - -function InstantiateFunction(data, name) { - // We need a reference to kApiFunctionCache in the stack frame - // if we need to bail out from a stack overflow. - var cache = kApiFunctionCache; - var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); - var isFunctionCached = - (serialNumber in cache) && (cache[serialNumber] != kUninitialized); - if (!isFunctionCached) { - try { - var flags = %GetTemplateField(data, kApiFlagOffset); - var prototype; - if (!(flags & (1 << kRemovePrototypeBit))) { - var template = %GetTemplateField(data, kApiPrototypeTemplateOffset); - prototype = typeof template === 'undefined' - ? {} : Instantiate(template); - - var parent = %GetTemplateField(data, kApiParentTemplateOffset); - // Note: Do not directly use a function template as a condition, our - // internal ToBoolean doesn't handle that! - if (typeof parent !== 'undefined') { - var parent_fun = Instantiate(parent); - %InternalSetPrototype(prototype, parent_fun.prototype); - } - } - var fun = %CreateApiFunction(data, prototype); - if (IS_STRING(name)) %FunctionSetName(fun, name); - var doNotCache = flags & (1 << kDoNotCacheBit); - if (!doNotCache) cache[serialNumber] = fun; - ConfigureTemplateInstance(fun, data); - if (doNotCache) return fun; - } catch (e) { - cache[serialNumber] = kUninitialized; - throw e; - } - } - return cache[serialNumber]; -} - - -function ConfigureTemplateInstance(obj, data) { - var properties = %GetTemplateField(data, kApiPropertyListOffset); - if (!properties) return; - // Disable access checks while instantiating the object. - var requires_access_checks = %DisableAccessChecks(obj); - try { - for (var i = 1; i < properties[0];) { - var length = properties[i]; - if (length == 3) { - var name = properties[i + 1]; - var prop_data = properties[i + 2]; - var attributes = properties[i + 3]; - var value = Instantiate(prop_data, name); - %AddPropertyForTemplate(obj, name, value, attributes); - } else if (length == 4 || length == 5) { - // TODO(verwaest): The 5th value used to be access_control. Remove once - // the bindings are updated. - var name = properties[i + 1]; - var getter = properties[i + 2]; - var setter = properties[i + 3]; - var attribute = properties[i + 4]; - %DefineApiAccessorProperty(obj, name, getter, setter, attribute); - } else { - throw "Bad properties array"; - } - i += length + 1; - } - } finally { - if (requires_access_checks) %EnableAccessChecks(obj); - } -} diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 6939fc3..22e5953 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -5,6 +5,7 @@ #include "src/bootstrapper.h" #include "src/accessors.h" +#include "src/api-natives.h" #include "src/code-stubs.h" #include "src/extensions/externalize-string-extension.h" #include "src/extensions/free-buffer-extension.h" @@ -809,10 +810,9 @@ Handle Genesis::CreateNewGlobals( } else { Handle js_global_object_constructor( FunctionTemplateInfo::cast(js_global_object_template->constructor())); - js_global_object_function = - factory()->CreateApiFunction(js_global_object_constructor, - factory()->the_hole_value(), - factory()->GlobalObjectType); + js_global_object_function = ApiNatives::CreateApiFunction( + isolate(), js_global_object_constructor, factory()->the_hole_value(), + ApiNatives::GlobalObjectType); } js_global_object_function->initial_map()->set_is_hidden_prototype(); @@ -833,10 +833,9 @@ Handle Genesis::CreateNewGlobals( v8::Utils::OpenHandle(*global_proxy_template); Handle global_constructor( FunctionTemplateInfo::cast(data->constructor())); - global_proxy_function = - factory()->CreateApiFunction(global_constructor, - factory()->the_hole_value(), - factory()->GlobalProxyType); + global_proxy_function = ApiNatives::CreateApiFunction( + isolate(), global_constructor, factory()->the_hole_value(), + ApiNatives::GlobalProxyType); } Handle global_name = factory()->global_string(); @@ -1533,11 +1532,7 @@ void Genesis::InstallNativeFunctions() { INSTALL_NATIVE(JSFunction, "ToLength", to_length_fun); INSTALL_NATIVE(JSFunction, "GlobalEval", global_eval_fun); - INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun); - INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance", - configure_instance_fun); INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun); - INSTALL_NATIVE(JSObject, "functionCache", function_cache); INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor", to_complete_property_descriptor); @@ -2042,6 +2037,8 @@ bool Genesis::InstallNatives() { InstallNativeFunctions(); + native_context()->set_function_cache(heap()->empty_fixed_array()); + // Store the map for the string prototype after the natives has been compiled // and the String function has been set up. Handle string_function(native_context()->string_function()); @@ -2575,7 +2572,7 @@ bool Genesis::ConfigureApiObject(Handle object, ->IsTemplateFor(object->map()));; MaybeHandle maybe_obj = - Execution::InstantiateObject(object_template); + ApiNatives::InstantiateObject(object_template); Handle obj; if (!maybe_obj.ToHandle(&obj)) { DCHECK(isolate()->has_pending_exception()); diff --git a/src/builtins.cc b/src/builtins.cc index 3e0e1ba..f35c6e3 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -5,6 +5,7 @@ #include "src/v8.h" #include "src/api.h" +#include "src/api-natives.h" #include "src/arguments.h" #include "src/base/once.h" #include "src/bootstrapper.h" @@ -1035,8 +1036,8 @@ MUST_USE_RESULT static MaybeHandle HandleApiCallHelper( if (is_construct) { ASSIGN_RETURN_ON_EXCEPTION( isolate, fun_data, - isolate->factory()->ConfigureInstance( - fun_data, Handle::cast(args.receiver())), + ApiNatives::ConfigureInstance(isolate, fun_data, + Handle::cast(args.receiver())), Object); } diff --git a/src/contexts.h b/src/contexts.h index 6510925..83510e9 100644 --- a/src/contexts.h +++ b/src/contexts.h @@ -100,8 +100,6 @@ enum BindingFlags { V(TO_INT32_FUN_INDEX, JSFunction, to_int32_fun) \ V(TO_LENGTH_FUN_INDEX, JSFunction, to_length_fun) \ V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ - V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_fun) \ - V(CONFIGURE_INSTANCE_FUN_INDEX, JSFunction, configure_instance_fun) \ V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \ V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \ V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \ @@ -140,7 +138,7 @@ enum BindingFlags { V(MAKE_MESSAGE_FUN_INDEX, JSFunction, make_message_fun) \ V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ V(CONFIGURE_GLOBAL_INDEX, JSFunction, configure_global_fun) \ - V(FUNCTION_CACHE_INDEX, JSObject, function_cache) \ + V(FUNCTION_CACHE_INDEX, FixedArray, function_cache) \ V(JSFUNCTION_RESULT_CACHES_INDEX, FixedArray, jsfunction_result_caches) \ V(NORMALIZED_MAP_CACHE_INDEX, Object, normalized_map_cache) \ V(RUNTIME_CONTEXT_INDEX, Context, runtime_context) \ @@ -348,8 +346,6 @@ class Context: public FixedArray { TO_INT32_FUN_INDEX, TO_BOOLEAN_FUN_INDEX, GLOBAL_EVAL_FUN_INDEX, - INSTANTIATE_FUN_INDEX, - CONFIGURE_INSTANCE_FUN_INDEX, ARRAY_BUFFER_FUN_INDEX, UINT8_ARRAY_FUN_INDEX, INT8_ARRAY_FUN_INDEX, diff --git a/src/date.js b/src/date.js index 87c87bf..40ab1d2 100644 --- a/src/date.js +++ b/src/date.js @@ -747,6 +747,12 @@ function CheckDateCacheCurrent() { } +function CreateDate(time) { + var date = new $Date(); + date.setTime(time); + return date; +} + // ------------------------------------------------------------------- function SetUpDate() { diff --git a/src/execution.cc b/src/execution.cc index ecc0b5e..7e8b791 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -629,73 +629,6 @@ Handle Execution::CharAt(Handle string, uint32_t index) { } -MaybeHandle Execution::InstantiateFunction( - Handle data) { - Isolate* isolate = data->GetIsolate(); - if (!data->do_not_cache()) { - // Fast case: see if the function has already been instantiated - int serial_number = Smi::cast(data->serial_number())->value(); - Handle cache(isolate->native_context()->function_cache()); - Handle elm = - Object::GetElement(isolate, cache, serial_number).ToHandleChecked(); - if (elm->IsJSFunction()) return Handle::cast(elm); - } - // The function has not yet been instantiated in this context; do it. - Handle args[] = { data }; - Handle result; - ASSIGN_RETURN_ON_EXCEPTION( - isolate, result, - Call(isolate, - isolate->instantiate_fun(), - isolate->js_builtins_object(), - arraysize(args), - args), - JSFunction); - return Handle::cast(result); -} - - -MaybeHandle Execution::InstantiateObject( - Handle data) { - Isolate* isolate = data->GetIsolate(); - Handle result; - if (data->property_list()->IsUndefined() && - !data->constructor()->IsUndefined()) { - Handle cons_template = - Handle( - FunctionTemplateInfo::cast(data->constructor())); - Handle cons; - ASSIGN_RETURN_ON_EXCEPTION( - isolate, cons, InstantiateFunction(cons_template), JSObject); - ASSIGN_RETURN_ON_EXCEPTION(isolate, result, New(cons, 0, NULL), JSObject); - } else { - Handle args[] = { data }; - ASSIGN_RETURN_ON_EXCEPTION( - isolate, result, - Call(isolate, - isolate->instantiate_fun(), - isolate->js_builtins_object(), - arraysize(args), - args), - JSObject); - } - return Handle::cast(result); -} - - -MaybeHandle Execution::ConfigureInstance( - Isolate* isolate, - Handle instance, - Handle instance_template) { - Handle args[] = { instance, instance_template }; - return Execution::Call(isolate, - isolate->configure_instance_fun(), - isolate->js_builtins_object(), - arraysize(args), - args); -} - - Handle Execution::GetStackTraceLine(Handle recv, Handle fun, Handle pos, diff --git a/src/execution.h b/src/execution.h index ae263bd..47cbb08 100644 --- a/src/execution.h +++ b/src/execution.h @@ -98,12 +98,6 @@ class Execution FINAL : public AllStatic { static Handle CharAt(Handle str, uint32_t index); static Handle GetFunctionFor(); - MUST_USE_RESULT static MaybeHandle InstantiateFunction( - Handle data); - MUST_USE_RESULT static MaybeHandle InstantiateObject( - Handle data); - MUST_USE_RESULT static MaybeHandle ConfigureInstance( - Isolate* isolate, Handle instance, Handle data); static Handle GetStackTraceLine(Handle recv, Handle fun, Handle pos, diff --git a/src/factory.cc b/src/factory.cc index 13ef723..d29c856 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -2246,186 +2246,6 @@ Handle Factory::NewJSWeakMap() { } -Handle Factory::CreateApiFunction( - Handle obj, - Handle prototype, - ApiInstanceType instance_type) { - Handle code = isolate()->builtins()->HandleApiCall(); - Handle construct_stub = isolate()->builtins()->JSConstructStubApi(); - - obj->set_instantiated(true); - Handle result; - if (obj->remove_prototype()) { - result = NewFunctionWithoutPrototype(empty_string(), code); - } else { - int internal_field_count = 0; - if (!obj->instance_template()->IsUndefined()) { - Handle instance_template = - Handle( - ObjectTemplateInfo::cast(obj->instance_template())); - internal_field_count = - Smi::cast(instance_template->internal_field_count())->value(); - } - - // TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing - // JSObject::GetHeaderSize. - int instance_size = kPointerSize * internal_field_count; - InstanceType type; - switch (instance_type) { - case JavaScriptObjectType: - type = JS_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(); - type = JS_OBJECT_TYPE; // Keep the compiler happy. - break; - } - - result = NewFunction(empty_string(), code, prototype, type, instance_size, - obj->read_only_prototype(), true); - } - - result->shared()->set_length(obj->length()); - Handle class_name(obj->class_name(), isolate()); - if (class_name->IsString()) { - result->shared()->set_instance_class_name(*class_name); - result->shared()->set_name(*class_name); - } - result->shared()->set_function_data(*obj); - result->shared()->set_construct_stub(*construct_stub); - result->shared()->DontAdaptArguments(); - - if (obj->remove_prototype()) { - DCHECK(result->shared()->IsApiFunction()); - DCHECK(!result->has_initial_map()); - DCHECK(!result->has_prototype()); - return result; - } - -#ifdef DEBUG - LookupIterator it(handle(JSObject::cast(result->prototype())), - constructor_string(), LookupIterator::OWN_SKIP_INTERCEPTOR); - MaybeHandle maybe_prop = Object::GetProperty(&it); - DCHECK(it.IsFound()); - DCHECK(maybe_prop.ToHandleChecked().is_identical_to(result)); -#endif - - // Down from here is only valid for API functions that can be used as a - // constructor (don't set the "remove prototype" flag). - - Handle map(result->initial_map()); - - // Mark as undetectable if needed. - if (obj->undetectable()) { - map->set_is_undetectable(); - } - - // Mark as hidden for the __proto__ accessor if needed. - if (obj->hidden_prototype()) { - map->set_is_hidden_prototype(); - } - - // Mark as needs_access_check if needed. - if (obj->needs_access_check()) { - map->set_is_access_check_needed(true); - } - - // Set interceptor information in the map. - if (!obj->named_property_handler()->IsUndefined()) { - map->set_has_named_interceptor(); - } - if (!obj->indexed_property_handler()->IsUndefined()) { - map->set_has_indexed_interceptor(); - } - - // Set instance call-as-function information in the map. - if (!obj->instance_call_handler()->IsUndefined()) { - map->set_has_instance_call_handler(); - } - - // Recursively copy parent instance templates' accessors, - // 'data' may be modified. - int max_number_of_additional_properties = 0; - int max_number_of_static_properties = 0; - FunctionTemplateInfo* info = *obj; - while (true) { - if (!info->instance_template()->IsUndefined()) { - Object* props = - ObjectTemplateInfo::cast( - info->instance_template())->property_accessors(); - if (!props->IsUndefined()) { - Handle props_handle(props, isolate()); - NeanderArray props_array(props_handle); - max_number_of_additional_properties += props_array.length(); - } - } - if (!info->property_accessors()->IsUndefined()) { - Object* props = info->property_accessors(); - if (!props->IsUndefined()) { - Handle props_handle(props, isolate()); - NeanderArray props_array(props_handle); - max_number_of_static_properties += props_array.length(); - } - } - Object* parent = info->parent_template(); - if (parent->IsUndefined()) break; - info = FunctionTemplateInfo::cast(parent); - } - - Map::EnsureDescriptorSlack(map, max_number_of_additional_properties); - - // Use a temporary FixedArray to acculumate static accessors - int valid_descriptors = 0; - Handle array; - if (max_number_of_static_properties > 0) { - array = NewFixedArray(max_number_of_static_properties); - } - - while (true) { - // Install instance descriptors - if (!obj->instance_template()->IsUndefined()) { - Handle instance = - Handle( - ObjectTemplateInfo::cast(obj->instance_template()), isolate()); - Handle props = Handle(instance->property_accessors(), - isolate()); - if (!props->IsUndefined()) { - Map::AppendCallbackDescriptors(map, props); - } - } - // Accumulate static accessors - if (!obj->property_accessors()->IsUndefined()) { - Handle props = Handle(obj->property_accessors(), - isolate()); - valid_descriptors = - AccessorInfo::AppendUnique(props, array, valid_descriptors); - } - // Climb parent chain - Handle parent = Handle(obj->parent_template(), isolate()); - if (parent->IsUndefined()) break; - obj = Handle::cast(parent); - } - - // Install accumulated static accessors - for (int i = 0; i < valid_descriptors; i++) { - Handle accessor(AccessorInfo::cast(array->get(i))); - JSObject::SetAccessor(result, accessor).Assert(); - } - - DCHECK(result->shared()->IsApiFunction()); - return result; -} - - Handle Factory::ObjectLiteralMapFromCache(Handle context, int number_of_properties, bool* is_result_from_cache) { @@ -2502,21 +2322,6 @@ void Factory::SetRegExpIrregexpData(Handle regexp, } -MaybeHandle Factory::ConfigureInstance( - Handle desc, Handle instance) { - // Configure the instance by adding the properties specified by the - // instance template. - Handle instance_template(desc->instance_template(), isolate()); - if (!instance_template->IsUndefined()) { - RETURN_ON_EXCEPTION( - isolate(), - Execution::ConfigureInstance(isolate(), instance, instance_template), - FunctionTemplateInfo); - } - return desc; -} - - Handle Factory::GlobalConstantFor(Handle name) { if (String::Equals(name, undefined_string())) return undefined_value(); if (String::Equals(name, nan_string())) return nan_value(); diff --git a/src/factory.h b/src/factory.h index 5be5c12..4dfd98c 100644 --- a/src/factory.h +++ b/src/factory.h @@ -561,25 +561,8 @@ class Factory FINAL { return NumberToString(NewNumberFromUint(value)); } - enum ApiInstanceType { - JavaScriptObjectType, - GlobalObjectType, - GlobalProxyType - }; - - Handle CreateApiFunction( - Handle data, - Handle prototype, - ApiInstanceType type = JavaScriptObjectType); - Handle InstallMembers(Handle function); - // Installs interceptors on the instance. 'desc' is a function template, - // and instance is an object instance created by the function of this - // function template. - MUST_USE_RESULT MaybeHandle ConfigureInstance( - Handle desc, Handle instance); - #define ROOT_ACCESSOR(type, name, camel_name) \ inline Handle name() { \ return Handle(bit_cast( \ diff --git a/src/macros.py b/src/macros.py index 1571144..93a5563 100644 --- a/src/macros.py +++ b/src/macros.py @@ -39,22 +39,10 @@ const NEW_TWO_BYTE_STRING = false; const GETTER = 0; const SETTER = 1; -# These definitions must match the index of the properties in objects.h. -const kApiTagOffset = 0; -const kApiPropertyListOffset = 1; -const kApiSerialNumberOffset = 3; -const kApiConstructorOffset = 3; -const kApiPrototypeTemplateOffset = 5; -const kApiParentTemplateOffset = 6; -const kApiFlagOffset = 14; - const NO_HINT = 0; const NUMBER_HINT = 1; const STRING_HINT = 2; -const kFunctionTag = 0; -const kNewObjectTag = 1; - # For date.js. const HoursPerDay = 24; const MinutesPerHour = 60; @@ -65,12 +53,6 @@ const msPerHour = 3600000; const msPerDay = 86400000; const msPerMonth = 2592000000; -# For apinatives.js -const kUninitialized = -1; -const kReadOnlyPrototypeBit = 3; -const kRemovePrototypeBit = 4; # For FunctionTemplateInfo, matches objects.h -const kDoNotCacheBit = 5; # For FunctionTemplateInfo, matches objects.h - # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1). const kInvalidDate = 'Invalid Date'; const kDayZeroInJulianDay = 2440588; diff --git a/src/runtime/runtime-api.cc b/src/runtime/runtime-api.cc deleted file mode 100644 index 740832e..0000000 --- a/src/runtime/runtime-api.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2014 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "src/v8.h" - -#include "src/arguments.h" -#include "src/bootstrapper.h" -#include "src/runtime/runtime.h" -#include "src/runtime/runtime-utils.h" - -namespace v8 { -namespace internal { - -RUNTIME_FUNCTION(Runtime_CreateApiFunction) { - HandleScope scope(isolate); - DCHECK(args.length() == 2); - CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0); - CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); - return *isolate->factory()->CreateApiFunction(data, prototype); -} - - -RUNTIME_FUNCTION(Runtime_IsTemplate) { - SealHandleScope shs(isolate); - DCHECK(args.length() == 1); - CONVERT_ARG_HANDLE_CHECKED(Object, arg, 0); - bool result = arg->IsObjectTemplateInfo() || arg->IsFunctionTemplateInfo(); - return isolate->heap()->ToBoolean(result); -} - - -RUNTIME_FUNCTION(Runtime_GetTemplateField) { - SealHandleScope shs(isolate); - DCHECK(args.length() == 2); - CONVERT_ARG_CHECKED(HeapObject, templ, 0); - CONVERT_SMI_ARG_CHECKED(index, 1); - int offset = index * kPointerSize + HeapObject::kHeaderSize; - InstanceType type = templ->map()->instance_type(); - RUNTIME_ASSERT(type == FUNCTION_TEMPLATE_INFO_TYPE || - type == OBJECT_TEMPLATE_INFO_TYPE); - RUNTIME_ASSERT(offset > 0); - if (type == FUNCTION_TEMPLATE_INFO_TYPE) { - RUNTIME_ASSERT(offset < FunctionTemplateInfo::kSize); - } else { - RUNTIME_ASSERT(offset < ObjectTemplateInfo::kSize); - } - return *HeapObject::RawField(templ, offset); -} - - -// Transform getter or setter into something DefineAccessor can handle. -static Handle InstantiateAccessorComponent(Isolate* isolate, - Handle component) { - if (component->IsUndefined()) return isolate->factory()->undefined_value(); - Handle info = - Handle::cast(component); - return Utils::OpenHandle(*Utils::ToLocal(info)->GetFunction()); -} - - -RUNTIME_FUNCTION(Runtime_DefineApiAccessorProperty) { - HandleScope scope(isolate); - DCHECK(args.length() == 5); - CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); - CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); - CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2); - CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); - CONVERT_SMI_ARG_CHECKED(attribute, 4); - RUNTIME_ASSERT(getter->IsUndefined() || getter->IsFunctionTemplateInfo()); - RUNTIME_ASSERT(setter->IsUndefined() || setter->IsFunctionTemplateInfo()); - RUNTIME_ASSERT(PropertyDetails::AttributesField::is_valid( - static_cast(attribute))); - RETURN_FAILURE_ON_EXCEPTION( - isolate, JSObject::DefineAccessor( - object, name, InstantiateAccessorComponent(isolate, getter), - InstantiateAccessorComponent(isolate, setter), - static_cast(attribute))); - return isolate->heap()->undefined_value(); -} - - -RUNTIME_FUNCTION(Runtime_AddPropertyForTemplate) { - HandleScope scope(isolate); - RUNTIME_ASSERT(args.length() == 4); - - CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); - CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); - CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); - CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); - RUNTIME_ASSERT( - (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - // Compute attributes. - PropertyAttributes attributes = - static_cast(unchecked_attributes); - -#ifdef DEBUG - bool duplicate; - if (key->IsName()) { - LookupIterator it(object, Handle::cast(key), - LookupIterator::OWN_SKIP_INTERCEPTOR); - Maybe maybe = JSReceiver::GetPropertyAttributes(&it); - DCHECK(maybe.has_value); - duplicate = it.IsFound(); - } else { - uint32_t index = 0; - RUNTIME_ASSERT(key->ToArrayIndex(&index)); - Maybe maybe = JSReceiver::HasOwnElement(object, index); - if (!maybe.has_value) return isolate->heap()->exception(); - duplicate = maybe.value; - } - if (duplicate) { - Handle args[1] = {key}; - THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError("duplicate_template_property", HandleVector(args, 1))); - } -#endif - - Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, - Runtime::DefineObjectProperty(object, key, value, attributes)); - return *result; -} -} -} // namespace v8::internal diff --git a/src/runtime/runtime-i18n.cc b/src/runtime/runtime-i18n.cc index 94d9f42..5e01651 100644 --- a/src/runtime/runtime-i18n.cc +++ b/src/runtime/runtime-i18n.cc @@ -6,6 +6,7 @@ #ifdef V8_I18N_SUPPORT #include "src/v8.h" +#include "src/api-natives.h" #include "src/arguments.h" #include "src/i18n.h" #include "src/runtime/runtime-utils.h" @@ -317,7 +318,7 @@ RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) { Handle local_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, local_object, - Execution::InstantiateObject(date_format_template)); + ApiNatives::InstantiateObject(date_format_template)); // Set date time formatter as internal field of the resulting JS object. icu::SimpleDateFormat* date_format = @@ -412,7 +413,7 @@ RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { Handle local_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, local_object, - Execution::InstantiateObject(number_format_template)); + ApiNatives::InstantiateObject(number_format_template)); // Set number formatter as internal field of the resulting JS object. icu::DecimalFormat* number_format = @@ -517,7 +518,7 @@ RUNTIME_FUNCTION(Runtime_CreateCollator) { // Create an empty object wrapper. Handle local_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, local_object, Execution::InstantiateObject(collator_template)); + isolate, local_object, ApiNatives::InstantiateObject(collator_template)); // Set collator as internal field of the resulting JS object. icu::Collator* collator = @@ -616,7 +617,7 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) { Handle local_object; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, local_object, - Execution::InstantiateObject(break_iterator_template)); + ApiNatives::InstantiateObject(break_iterator_template)); // Set break iterator as internal field of the resulting JS object. icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator( diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 734f0a4..86ea420 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -232,9 +232,6 @@ namespace internal { \ F(SetCode, 2, 1) \ \ - F(CreateApiFunction, 2, 1) \ - F(IsTemplate, 1, 1) \ - F(GetTemplateField, 2, 1) \ F(DisableAccessChecks, 1, 1) \ F(EnableAccessChecks, 1, 1) \ \ @@ -254,10 +251,8 @@ namespace internal { F(GlobalProxy, 1, 1) \ \ F(AddNamedProperty, 4, 1) \ - F(AddPropertyForTemplate, 4, 1) \ F(SetProperty, 4, 1) \ F(AddElement, 4, 1) \ - F(DefineApiAccessorProperty, 5, 1) \ F(DefineDataPropertyUnchecked, 4, 1) \ F(DefineAccessorPropertyUnchecked, 5, 1) \ F(GetDataProperty, 2, 1) \ diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 5b3311a..b66d117 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -23398,10 +23398,10 @@ THREADED_TEST(FunctionNew) { i::Smi::cast(v8::Utils::OpenHandle(*func) ->shared()->get_api_func_data()->serial_number())->value(); i::Isolate* i_isolate = reinterpret_cast(isolate); - i::Handle cache(i_isolate->native_context()->function_cache()); - i::Handle elm = - i::Object::GetElement(i_isolate, cache, serial_number).ToHandleChecked(); - CHECK(elm->IsUndefined()); + i::Handle cache(i_isolate->native_context()->function_cache()); + if (serial_number < cache->length()) { + CHECK(cache->get(serial_number)->IsUndefined()); + } // Verify that each Function::New creates a new function instance Local data2 = v8::Object::New(isolate); function_new_expected_env = data2; diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index d70247f..6c08b75 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -358,6 +358,8 @@ '../../src/allocation-tracker.h', '../../src/api.cc', '../../src/api.h', + '../../src/api-natives.cc', + '../../src/api-natives.h', '../../src/arguments.cc', '../../src/arguments.h', '../../src/assembler.cc', @@ -796,7 +798,6 @@ '../../src/rewriter.h', '../../src/runtime-profiler.cc', '../../src/runtime-profiler.h', - '../../src/runtime/runtime-api.cc', '../../src/runtime/runtime-array.cc', '../../src/runtime/runtime-classes.cc', '../../src/runtime/runtime-collections.cc', @@ -1677,7 +1678,6 @@ '../../src/uri.js', '../../src/third_party/fdlibm/fdlibm.js', '../../src/math.js', - '../../src/apinatives.js', '../../src/date.js', '../../src/regexp.js', '../../src/arraybuffer.js', -- 2.7.4