diff options
author | Andras Becsi <andras.becsi@digia.com> | 2013-12-11 21:33:03 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2013-12-13 12:34:07 +0100 |
commit | f2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch) | |
tree | 0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/v8/src/api.cc | |
parent | 5362912cdb5eea702b68ebe23702468d17c3017a (diff) | |
download | qtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz |
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/v8/src/api.cc')
-rw-r--r-- | chromium/v8/src/api.cc | 1004 |
1 files changed, 366 insertions, 638 deletions
diff --git a/chromium/v8/src/api.cc b/chromium/v8/src/api.cc index 7b2524cc4d7..71a8f4a6cf7 100644 --- a/chromium/v8/src/api.cc +++ b/chromium/v8/src/api.cc @@ -46,12 +46,14 @@ #include "heap-profiler.h" #include "heap-snapshot-generator-inl.h" #include "icu_util.h" +#include "json-parser.h" #include "messages.h" #ifdef COMPRESS_STARTUP_DATA_BZ2 #include "natives.h" #endif #include "parser.h" #include "platform.h" +#include "platform/time.h" #include "profile-generator-inl.h" #include "property-details.h" #include "property.h" @@ -60,6 +62,7 @@ #include "scanner-character-streams.h" #include "snapshot.h" #include "unicode-inl.h" +#include "utils/random-number-generator.h" #include "v8threads.h" #include "version.h" #include "vm-state-inl.h" @@ -219,25 +222,27 @@ void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { // HeapIterator here without doing a special GC. isolate->heap()->RecordStats(&heap_stats, false); } - i::V8::SetFatalError(); + isolate->SignalFatalError(); FatalErrorCallback callback = GetFatalErrorHandler(); const char* message = "Allocation failed - process out of memory"; callback(location, message); // If the callback returns, we stop execution. - UNREACHABLE(); + FATAL("API fatal error handler returned after process out of memory"); } bool Utils::ReportApiFailure(const char* location, const char* message) { FatalErrorCallback callback = GetFatalErrorHandler(); callback(location, message); - i::V8::SetFatalError(); + i::Isolate* isolate = i::Isolate::Current(); + isolate->SignalFatalError(); return false; } bool V8::IsDead() { - return i::V8::IsDead(); + i::Isolate* isolate = i::Isolate::Current(); + return isolate->IsDead(); } @@ -276,7 +281,7 @@ static bool ReportEmptyHandle(const char* location) { */ static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) { return !isolate->IsInitialized() - && i::V8::IsDead() ? ReportV8Dead(location) : false; + && isolate->IsDead() ? ReportV8Dead(location) : false; } @@ -398,9 +403,6 @@ enum CompressedStartupDataItems { kSnapshotContext, kLibraries, kExperimentalLibraries, -#if defined(V8_I18N_SUPPORT) - kI18NExtension, -#endif kCompressedStartupDataCount }; @@ -441,17 +443,6 @@ void V8::GetCompressedStartupData(StartupData* compressed_data) { exp_libraries_source.length(); compressed_data[kExperimentalLibraries].raw_size = i::ExperimentalNatives::GetRawScriptsSize(); - -#if defined(V8_I18N_SUPPORT) - i::Vector<const ii:byte> i18n_extension_source = - i::I18NNatives::GetScriptsSource(); - compressed_data[kI18NExtension].data = - reinterpret_cast<const char*>(i18n_extension_source.start()); - compressed_data[kI18NExtension].compressed_size = - i18n_extension_source.length(); - compressed_data[kI18NExtension].raw_size = - i::I18NNatives::GetRawScriptsSize(); -#endif #endif } @@ -481,15 +472,6 @@ void V8::SetDecompressedStartupData(StartupData* decompressed_data) { decompressed_data[kExperimentalLibraries].data, decompressed_data[kExperimentalLibraries].raw_size); i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source); - -#if defined(V8_I18N_SUPPORT) - ASSERT_EQ(i::I18NNatives::GetRawScriptsSize(), - decompressed_data[kI18NExtension].raw_size); - i::Vector<const char> i18n_extension_source( - decompressed_data[kI18NExtension].data, - decompressed_data[kI18NExtension].raw_size); - i::I18NNatives::SetRawScriptsSource(i18n_extension_source); -#endif #endif } @@ -620,7 +602,8 @@ ResourceConstraints::ResourceConstraints() : max_young_space_size_(0), max_old_space_size_(0), max_executable_size_(0), - stack_limit_(NULL) { } + stack_limit_(NULL), + is_memory_constrained_() { } bool SetResourceConstraints(ResourceConstraints* constraints) { @@ -641,6 +624,10 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); isolate->stack_guard()->SetStackLimit(limit); } + if (constraints->is_memory_constrained().has_value) { + isolate->set_is_memory_constrained( + constraints->is_memory_constrained().value); + } return true; } @@ -656,11 +643,22 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { } +i::Object** V8::CopyPersistent(i::Object** obj) { + i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(obj); +#ifdef DEBUG + (*obj)->Verify(); +#endif // DEBUG + return result.location(); +} + + void V8::MakeWeak(i::Object** object, void* parameters, + WeakCallback weak_callback, RevivableCallback weak_reference_callback) { i::GlobalHandles::MakeWeak(object, parameters, + weak_callback, weak_reference_callback); } @@ -675,14 +673,22 @@ void V8::DisposeGlobal(i::Object** obj) { } -// --- H a n d l e s --- +void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); + i::Object* object = *Utils::OpenHandle(value); + isolate->eternal_handles()->Create(isolate, object, index); +} -HandleScope::HandleScope() { - Initialize(reinterpret_cast<Isolate*>(i::Isolate::Current())); +Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); + return Utils::ToLocal(isolate->eternal_handles()->Get(index)); } +// --- H a n d l e s --- + + HandleScope::HandleScope(Isolate* isolate) { Initialize(isolate); } @@ -770,7 +776,6 @@ void Context::Exit() { i::Context* last_context = isolate->handle_scope_implementer()->RestoreContext(); isolate->set_context(last_context); - isolate->set_context_exit_happened(true); } @@ -945,21 +950,62 @@ static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { } -void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, +static void TemplateSet(i::Isolate* isolate, + v8::Template* templ, + int length, + v8::Handle<v8::Data>* data) { + i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate); + if (list->IsUndefined()) { + list = NeanderArray().value(); + Utils::OpenHandle(templ)->set_property_list(*list); + } + NeanderArray array(list); + array.add(Utils::OpenHandle(*v8::Integer::New(length))); + for (int i = 0; i < length; i++) { + i::Handle<i::Object> value = data[i].IsEmpty() ? + i::Handle<i::Object>(isolate->factory()->undefined_value()) : + Utils::OpenHandle(*data[i]); + array.add(value); + } +} + + +void Template::Set(v8::Handle<String> name, + v8::Handle<Data> value, v8::PropertyAttribute attribute) { i::Isolate* isolate = i::Isolate::Current(); if (IsDeadCheck(isolate, "v8::Template::Set()")) return; ENTER_V8(isolate); i::HandleScope scope(isolate); - i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list(), isolate); - if (list->IsUndefined()) { - list = NeanderArray().value(); - Utils::OpenHandle(this)->set_property_list(*list); - } - NeanderArray array(list); - array.add(Utils::OpenHandle(*name)); - array.add(Utils::OpenHandle(*value)); - array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); + const int kSize = 3; + v8::Handle<v8::Data> data[kSize] = { + name, + value, + v8::Integer::New(attribute)}; + TemplateSet(isolate, this, kSize, data); +} + + +void Template::SetAccessorProperty( + v8::Local<v8::String> name, + v8::Local<FunctionTemplate> getter, + v8::Local<FunctionTemplate> setter, + v8::PropertyAttribute attribute, + v8::AccessControl access_control) { + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + if (IsDeadCheck(isolate, "v8::Template::SetAccessor()")) return; + ENTER_V8(isolate); + ASSERT(!name.IsEmpty()); + ASSERT(!getter.IsEmpty() || !setter.IsEmpty()); + i::HandleScope scope(isolate); + const int kSize = 5; + v8::Handle<v8::Data> data[kSize] = { + name, + getter, + setter, + v8::Integer::New(attribute), + v8::Integer::New(access_control)}; + TemplateSet(isolate, this, kSize, data); } @@ -995,69 +1041,48 @@ void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { } -// TODO(dcarney): Remove this abstraction when old callbacks are removed. -class CallHandlerHelper { - public: - static inline void Set(Local<FunctionTemplate> function_template, - InvocationCallback callback, - v8::Handle<Value> data) { - function_template->SetCallHandlerInternal(callback, data); - } - static inline void Set(Local<FunctionTemplate> function_template, - FunctionCallback callback, - v8::Handle<Value> data) { - function_template->SetCallHandler(callback, data); - } -}; - - -template<typename Callback> static Local<FunctionTemplate> FunctionTemplateNew( - Callback callback, + i::Isolate* isolate, + FunctionCallback callback, v8::Handle<Value> data, v8::Handle<Signature> signature, - int length) { - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); - LOG_API(isolate, "FunctionTemplate::New"); - ENTER_V8(isolate); + int length, + bool do_not_cache) { i::Handle<i::Struct> struct_obj = isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); i::Handle<i::FunctionTemplateInfo> obj = i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); InitializeFunctionTemplate(obj); - int next_serial_number = isolate->next_serial_number(); - isolate->set_next_serial_number(next_serial_number + 1); + obj->set_do_not_cache(do_not_cache); + int next_serial_number = 0; + if (!do_not_cache) { + next_serial_number = isolate->next_serial_number() + 1; + isolate->set_next_serial_number(next_serial_number); + } obj->set_serial_number(i::Smi::FromInt(next_serial_number)); if (callback != 0) { if (data.IsEmpty()) data = v8::Undefined(); - CallHandlerHelper::Set(Utils::ToLocal(obj), callback, data); + Utils::ToLocal(obj)->SetCallHandler(callback, data); } obj->set_length(length); obj->set_undetectable(false); obj->set_needs_access_check(false); - if (!signature.IsEmpty()) obj->set_signature(*Utils::OpenHandle(*signature)); return Utils::ToLocal(obj); } - -Local<FunctionTemplate> FunctionTemplate::New( - InvocationCallback callback, - v8::Handle<Value> data, - v8::Handle<Signature> signature, - int length) { - return FunctionTemplateNew(callback, data, signature, length); -} - - Local<FunctionTemplate> FunctionTemplate::New( FunctionCallback callback, v8::Handle<Value> data, v8::Handle<Signature> signature, int length) { - return FunctionTemplateNew(callback, data, signature, length); + i::Isolate* isolate = i::Isolate::Current(); + EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); + LOG_API(isolate, "FunctionTemplate::New"); + ENTER_V8(isolate); + return FunctionTemplateNew( + isolate, callback, data, signature, length, false); } @@ -1245,16 +1270,14 @@ int TypeSwitch::match(v8::Handle<Value> value) { #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ - i::Handle<i::Object> foreign = FromCData(cdata); \ + i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ (obj)->setter(*foreign); \ } while (false) -template<typename Callback> -static void FunctionTemplateSetCallHandler(FunctionTemplate* function_template, - Callback callback_in, - v8::Handle<Value> data) { - i::Isolate* isolate = Utils::OpenHandle(function_template)->GetIsolate(); +void FunctionTemplate::SetCallHandler(FunctionCallback callback, + v8::Handle<Value> data) { + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return; ENTER_V8(isolate); i::HandleScope scope(isolate); @@ -1262,28 +1285,12 @@ static void FunctionTemplateSetCallHandler(FunctionTemplate* function_template, isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); i::Handle<i::CallHandlerInfo> obj = i::Handle<i::CallHandlerInfo>::cast(struct_obj); - FunctionCallback callback = - i::CallbackTable::Register(isolate, callback_in); SET_FIELD_WRAPPED(obj, set_callback, callback); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); - Utils::OpenHandle(function_template)->set_call_code(*obj); + Utils::OpenHandle(this)->set_call_code(*obj); } -void FunctionTemplate::SetCallHandler(InvocationCallback callback, - v8::Handle<Value> data) { - FunctionTemplateSetCallHandler(this, callback, data); -} - -void FunctionTemplate::SetCallHandlerInternal(InvocationCallback callback, - v8::Handle<Value> data) { - FunctionTemplateSetCallHandler(this, callback, data); -} - -void FunctionTemplate::SetCallHandler(FunctionCallback callback, - v8::Handle<Value> data) { - FunctionTemplateSetCallHandler(this, callback, data); -} static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( i::Handle<i::AccessorInfo> obj, @@ -1306,8 +1313,8 @@ static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( template<typename Getter, typename Setter> static i::Handle<i::AccessorInfo> MakeAccessorInfo( v8::Handle<String> name, - Getter getter_in, - Setter setter_in, + Getter getter, + Setter setter, v8::Handle<Value> data, v8::AccessControl settings, v8::PropertyAttribute attributes, @@ -1315,11 +1322,7 @@ static i::Handle<i::AccessorInfo> MakeAccessorInfo( i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); i::Handle<i::ExecutableAccessorInfo> obj = isolate->factory()->NewExecutableAccessorInfo(); - AccessorGetterCallback getter = - i::CallbackTable::Register(isolate, getter_in); SET_FIELD_WRAPPED(obj, set_getter, getter); - AccessorSetterCallback setter = - i::CallbackTable::Register(isolate, setter_in); SET_FIELD_WRAPPED(obj, set_setter, setter); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); @@ -1397,124 +1400,14 @@ void FunctionTemplate::ReadOnlyPrototype() { Utils::OpenHandle(this)->set_read_only_prototype(true); } -template< - typename Getter, - typename Setter, - typename Query, - typename Deleter, - typename Enumerator> -static void SetNamedInstancePropertyHandler( - i::Handle<i::FunctionTemplateInfo> function_template, - Getter getter_in, - Setter setter_in, - Query query_in, - Deleter remover_in, - Enumerator enumerator_in, - Handle<Value> data) { - i::Isolate* isolate = function_template->GetIsolate(); - if (IsDeadCheck(isolate, - "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { - return; - } - ENTER_V8(isolate); - i::HandleScope scope(isolate); - i::Handle<i::Struct> struct_obj = - isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); - i::Handle<i::InterceptorInfo> obj = - i::Handle<i::InterceptorInfo>::cast(struct_obj); - - NamedPropertyGetterCallback getter = - i::CallbackTable::Register(isolate, getter_in); - if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); - NamedPropertySetterCallback setter = - i::CallbackTable::Register(isolate, setter_in); - if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); - NamedPropertyQueryCallback query = - i::CallbackTable::Register(isolate, query_in); - if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); - NamedPropertyDeleterCallback remover = - i::CallbackTable::Register(isolate, remover_in); - if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); - NamedPropertyEnumeratorCallback enumerator = - i::CallbackTable::Register(isolate, enumerator_in); - if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); - - if (data.IsEmpty()) data = v8::Undefined(); - obj->set_data(*Utils::OpenHandle(*data)); - function_template->set_named_property_handler(*obj); -} - - -template< - typename Getter, - typename Setter, - typename Query, - typename Deleter, - typename Enumerator> -static void SetIndexedInstancePropertyHandler( - i::Handle<i::FunctionTemplateInfo> function_template, - Getter getter_in, - Setter setter_in, - Query query_in, - Deleter remover_in, - Enumerator enumerator_in, - Handle<Value> data) { - i::Isolate* isolate = function_template->GetIsolate(); - if (IsDeadCheck(isolate, - "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { - return; - } - ENTER_V8(isolate); - i::HandleScope scope(isolate); - i::Handle<i::Struct> struct_obj = - isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); - i::Handle<i::InterceptorInfo> obj = - i::Handle<i::InterceptorInfo>::cast(struct_obj); - - IndexedPropertyGetterCallback getter = - i::CallbackTable::Register(isolate, getter_in); - if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); - IndexedPropertySetterCallback setter = - i::CallbackTable::Register(isolate, setter_in); - if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); - IndexedPropertyQueryCallback query = - i::CallbackTable::Register(isolate, query_in); - if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); - IndexedPropertyDeleterCallback remover = - i::CallbackTable::Register(isolate, remover_in); - if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); - IndexedPropertyEnumeratorCallback enumerator = - i::CallbackTable::Register(isolate, enumerator_in); - if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); - - if (data.IsEmpty()) data = v8::Undefined(); - obj->set_data(*Utils::OpenHandle(*data)); - function_template->set_indexed_property_handler(*obj); -} - -template<typename Callback> -static void SetInstanceCallAsFunctionHandler( - i::Handle<i::FunctionTemplateInfo> function_template, - Callback callback_in, - Handle<Value> data) { - i::Isolate* isolate = function_template->GetIsolate(); - if (IsDeadCheck(isolate, - "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { +void FunctionTemplate::RemovePrototype() { + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + if (IsDeadCheck(isolate, "v8::FunctionTemplate::RemovePrototype()")) { return; } ENTER_V8(isolate); - i::HandleScope scope(isolate); - i::Handle<i::Struct> struct_obj = - isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); - i::Handle<i::CallHandlerInfo> obj = - i::Handle<i::CallHandlerInfo>::cast(struct_obj); - FunctionCallback callback = - i::CallbackTable::Register(isolate, callback_in); - SET_FIELD_WRAPPED(obj, set_callback, callback); - if (data.IsEmpty()) data = v8::Undefined(); - obj->set_data(*Utils::OpenHandle(*data)); - function_template->set_instance_call_handler(*obj); + Utils::OpenHandle(this)->set_remove_prototype(true); } @@ -1549,63 +1442,91 @@ Local<ObjectTemplate> ObjectTemplate::New( // Ensure that the object template has a constructor. If no // constructor is available we create one. -static void EnsureConstructor(ObjectTemplate* object_template) { - if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { - Local<FunctionTemplate> templ = FunctionTemplate::New(); - i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); - constructor->set_instance_template(*Utils::OpenHandle(object_template)); - Utils::OpenHandle(object_template)->set_constructor(*constructor); +static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( + ObjectTemplate* object_template) { + i::Object* obj = Utils::OpenHandle(object_template)->constructor(); + if (!obj ->IsUndefined()) { + i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); + return i::Handle<i::FunctionTemplateInfo>(info, info->GetIsolate()); } + Local<FunctionTemplate> templ = FunctionTemplate::New(); + i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); + constructor->set_instance_template(*Utils::OpenHandle(object_template)); + Utils::OpenHandle(object_template)->set_constructor(*constructor); + return constructor; } -static inline void AddPropertyToFunctionTemplate( - i::Handle<i::FunctionTemplateInfo> cons, +static inline void AddPropertyToTemplate( + i::Handle<i::TemplateInfo> info, i::Handle<i::AccessorInfo> obj) { - i::Handle<i::Object> list(cons->property_accessors(), cons->GetIsolate()); + i::Handle<i::Object> list(info->property_accessors(), info->GetIsolate()); if (list->IsUndefined()) { list = NeanderArray().value(); - cons->set_property_accessors(*list); + info->set_property_accessors(*list); } NeanderArray array(list); array.add(obj); } -template<typename Setter, typename Getter, typename Data> -static bool ObjectTemplateSetAccessor( - ObjectTemplate* object_template, - v8::Handle<String> name, +static inline i::Handle<i::TemplateInfo> GetTemplateInfo( + Template* template_obj) { + return Utils::OpenHandle(template_obj); +} + + +// TODO(dcarney): remove this with ObjectTemplate::SetAccessor +static inline i::Handle<i::TemplateInfo> GetTemplateInfo( + ObjectTemplate* object_template) { + EnsureConstructor(object_template); + return Utils::OpenHandle(object_template); +} + + +template<typename Setter, typename Getter, typename Data, typename Template> +static bool TemplateSetAccessor( + Template* template_obj, + v8::Local<String> name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attribute, - v8::Handle<AccessorSignature> signature) { - i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); + v8::Local<AccessorSignature> signature) { + i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate(); if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return false; ENTER_V8(isolate); i::HandleScope scope(isolate); - EnsureConstructor(object_template); - i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( - Utils::OpenHandle(object_template)->constructor()); - i::Handle<i::FunctionTemplateInfo> cons(constructor); i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( name, getter, setter, data, settings, attribute, signature); if (obj.is_null()) return false; - AddPropertyToFunctionTemplate(cons, obj); + i::Handle<i::TemplateInfo> info = GetTemplateInfo(template_obj); + AddPropertyToTemplate(info, obj); return true; } -void ObjectTemplate::SetAccessor(v8::Handle<String> name, - AccessorGetter getter, - AccessorSetter setter, - v8::Handle<Value> data, - AccessControl settings, - PropertyAttribute attribute, - v8::Handle<AccessorSignature> signature) { - ObjectTemplateSetAccessor( +bool Template::SetDeclaredAccessor( + Local<String> name, + Local<DeclaredAccessorDescriptor> descriptor, + PropertyAttribute attribute, + Local<AccessorSignature> signature, + AccessControl settings) { + void* null = NULL; + return TemplateSetAccessor( + this, name, descriptor, null, null, settings, attribute, signature); +} + + +void Template::SetNativeDataProperty(v8::Local<String> name, + AccessorGetterCallback getter, + AccessorSetterCallback setter, + v8::Handle<Value> data, + PropertyAttribute attribute, + v8::Local<AccessorSignature> signature, + AccessControl settings) { + TemplateSetAccessor( this, name, getter, setter, data, settings, attribute, signature); } @@ -1617,77 +1538,42 @@ void ObjectTemplate::SetAccessor(v8::Handle<String> name, AccessControl settings, PropertyAttribute attribute, v8::Handle<AccessorSignature> signature) { - ObjectTemplateSetAccessor( + TemplateSetAccessor( this, name, getter, setter, data, settings, attribute, signature); } -bool ObjectTemplate::SetAccessor(Handle<String> name, - Handle<DeclaredAccessorDescriptor> descriptor, - AccessControl settings, - PropertyAttribute attribute, - Handle<AccessorSignature> signature) { - void* null = NULL; - return ObjectTemplateSetAccessor( - this, name, descriptor, null, null, settings, attribute, signature); -} - - -template< - typename Getter, - typename Setter, - typename Query, - typename Deleter, - typename Enumerator> -static void ObjectTemplateSetNamedPropertyHandler( - ObjectTemplate* object_template, - Getter getter, - Setter setter, - Query query, - Deleter remover, - Enumerator enumerator, +void ObjectTemplate::SetNamedPropertyHandler( + NamedPropertyGetterCallback getter, + NamedPropertySetterCallback setter, + NamedPropertyQueryCallback query, + NamedPropertyDeleterCallback remover, + NamedPropertyEnumeratorCallback enumerator, Handle<Value> data) { - i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) { return; } ENTER_V8(isolate); i::HandleScope scope(isolate); - EnsureConstructor(object_template); + EnsureConstructor(this); i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( - Utils::OpenHandle(object_template)->constructor()); + Utils::OpenHandle(this)->constructor()); i::Handle<i::FunctionTemplateInfo> cons(constructor); - SetNamedInstancePropertyHandler(cons, - getter, - setter, - query, - remover, - enumerator, - data); -} - - -void ObjectTemplate::SetNamedPropertyHandler( - NamedPropertyGetter getter, - NamedPropertySetter setter, - NamedPropertyQuery query, - NamedPropertyDeleter remover, - NamedPropertyEnumerator enumerator, - Handle<Value> data) { - ObjectTemplateSetNamedPropertyHandler( - this, getter, setter, query, remover, enumerator, data); -} + i::Handle<i::Struct> struct_obj = + isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); + i::Handle<i::InterceptorInfo> obj = + i::Handle<i::InterceptorInfo>::cast(struct_obj); + if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); + if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); + if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); + if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); + if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); -void ObjectTemplate::SetNamedPropertyHandler( - NamedPropertyGetterCallback getter, - NamedPropertySetterCallback setter, - NamedPropertyQueryCallback query, - NamedPropertyDeleterCallback remover, - NamedPropertyEnumeratorCallback enumerator, - Handle<Value> data) { - ObjectTemplateSetNamedPropertyHandler( - this, getter, setter, query, remover, enumerator, data); + if (data.IsEmpty()) data = v8::Undefined(); + obj->set_data(*Utils::OpenHandle(*data)); + cons->set_named_property_handler(*obj); } @@ -1736,93 +1622,61 @@ void ObjectTemplate::SetAccessCheckCallbacks( } -template< - typename Getter, - typename Setter, - typename Query, - typename Deleter, - typename Enumerator> -void ObjectTemplateSetIndexedPropertyHandler( - ObjectTemplate* object_template, - Getter getter, - Setter setter, - Query query, - Deleter remover, - Enumerator enumerator, +void ObjectTemplate::SetIndexedPropertyHandler( + IndexedPropertyGetterCallback getter, + IndexedPropertySetterCallback setter, + IndexedPropertyQueryCallback query, + IndexedPropertyDeleterCallback remover, + IndexedPropertyEnumeratorCallback enumerator, Handle<Value> data) { - i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) { return; } ENTER_V8(isolate); i::HandleScope scope(isolate); - EnsureConstructor(object_template); + EnsureConstructor(this); i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( - Utils::OpenHandle(object_template)->constructor()); + Utils::OpenHandle(this)->constructor()); i::Handle<i::FunctionTemplateInfo> cons(constructor); - SetIndexedInstancePropertyHandler(cons, - getter, - setter, - query, - remover, - enumerator, - data); -} - - -void ObjectTemplate::SetIndexedPropertyHandler( - IndexedPropertyGetter getter, - IndexedPropertySetter setter, - IndexedPropertyQuery query, - IndexedPropertyDeleter remover, - IndexedPropertyEnumerator enumerator, - Handle<Value> data) { - ObjectTemplateSetIndexedPropertyHandler( - this, getter, setter, query, remover, enumerator, data); -} + i::Handle<i::Struct> struct_obj = + isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); + i::Handle<i::InterceptorInfo> obj = + i::Handle<i::InterceptorInfo>::cast(struct_obj); + if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); + if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); + if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); + if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); + if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); -void ObjectTemplate::SetIndexedPropertyHandler( - IndexedPropertyGetterCallback getter, - IndexedPropertySetterCallback setter, - IndexedPropertyQueryCallback query, - IndexedPropertyDeleterCallback remover, - IndexedPropertyEnumeratorCallback enumerator, - Handle<Value> data) { - ObjectTemplateSetIndexedPropertyHandler( - this, getter, setter, query, remover, enumerator, data); + if (data.IsEmpty()) data = v8::Undefined(); + obj->set_data(*Utils::OpenHandle(*data)); + cons->set_indexed_property_handler(*obj); } -template<typename Callback> -static void ObjectTemplateSetCallAsFunctionHandler( - ObjectTemplate* object_template, - Callback callback, - Handle<Value> data) { - i::Isolate* isolate = Utils::OpenHandle(object_template)->GetIsolate(); +void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, + Handle<Value> data) { + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetCallAsFunctionHandler()")) { return; } ENTER_V8(isolate); i::HandleScope scope(isolate); - EnsureConstructor(object_template); + EnsureConstructor(this); i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( - Utils::OpenHandle(object_template)->constructor()); + Utils::OpenHandle(this)->constructor()); i::Handle<i::FunctionTemplateInfo> cons(constructor); - SetInstanceCallAsFunctionHandler(cons, callback, data); -} - - -void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, - Handle<Value> data) { - return ObjectTemplateSetCallAsFunctionHandler(this, callback, data); -} - - -void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, - Handle<Value> data) { - return ObjectTemplateSetCallAsFunctionHandler(this, callback, data); + i::Handle<i::Struct> struct_obj = + isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); + i::Handle<i::CallHandlerInfo> obj = + i::Handle<i::CallHandlerInfo>::cast(struct_obj); + SET_FIELD_WRAPPED(obj, set_callback, callback); + if (data.IsEmpty()) data = v8::Undefined(); + obj->set_data(*Utils::OpenHandle(*data)); + cons->set_instance_call_handler(*obj); } @@ -1862,19 +1716,20 @@ void ObjectTemplate::SetInternalFieldCount(int value) { ScriptData* ScriptData::PreCompile(const char* input, int length) { i::Utf8ToUtf16CharacterStream stream( reinterpret_cast<const unsigned char*>(input), length); - return i::PreParserApi::PreParse(&stream); + return i::PreParserApi::PreParse(i::Isolate::Current(), &stream); } ScriptData* ScriptData::PreCompile(v8::Handle<String> source) { i::Handle<i::String> str = Utils::OpenHandle(*source); + i::Isolate* isolate = str->GetIsolate(); if (str->IsExternalTwoByteString()) { i::ExternalTwoByteStringUtf16CharacterStream stream( i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length()); - return i::PreParserApi::PreParse(&stream); + return i::PreParserApi::PreParse(isolate, &stream); } else { i::GenericStringUtf16CharacterStream stream(str, 0, str->length()); - return i::PreParserApi::PreParse(&stream); + return i::PreParserApi::PreParse(isolate, &stream); } } @@ -2025,8 +1880,8 @@ Local<Value> Script::Run() { EXCEPTION_PREAMBLE(isolate); i::Handle<i::Object> receiver( isolate->context()->global_proxy(), isolate); - i::Handle<i::Object> result = - i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); + i::Handle<i::Object> result = i::Execution::Call( + isolate, fun, receiver, 0, NULL, &has_pending_exception); EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); raw_result = *result; } @@ -2325,8 +2180,8 @@ static i::Handle<i::Object> CallV8HeapFunction(const char* name, isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str); i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); - i::Handle<i::Object> value = - i::Execution::Call(fun, recv, argc, argv, has_pending_exception); + i::Handle<i::Object> value = i::Execution::Call( + isolate, fun, recv, argc, argv, has_pending_exception); return value; } @@ -2468,7 +2323,7 @@ Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { ENTER_V8(isolate); HandleScope scope(reinterpret_cast<Isolate*>(isolate)); i::Handle<i::JSArray> self = Utils::OpenHandle(this); - i::Object* raw_object = self->GetElementNoExceptionThrown(index); + i::Object* raw_object = self->GetElementNoExceptionThrown(isolate, index); i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); return scope.Close(Utils::StackFrameToLocal(obj)); } @@ -2537,6 +2392,22 @@ int StackFrame::GetColumn() const { } +int StackFrame::GetScriptId() const { + i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptId()")) { + return Message::kNoScriptIdInfo; + } + ENTER_V8(isolate); + i::HandleScope scope(isolate); + i::Handle<i::JSObject> self = Utils::OpenHandle(this); + i::Handle<i::Object> scriptId = GetProperty(self, "scriptId"); + if (!scriptId->IsSmi()) { + return Message::kNoScriptIdInfo; + } + return i::Smi::cast(*scriptId)->value(); +} + + Local<String> StackFrame::GetScriptName() const { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) { @@ -2607,6 +2478,29 @@ bool StackFrame::IsConstructor() const { } +// --- J S O N --- + +Local<Value> JSON::Parse(Local<String> json_string) { + i::Isolate* isolate = i::Isolate::Current(); + EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); + ENTER_V8(isolate); + i::HandleScope scope(isolate); + i::Handle<i::String> source = i::Handle<i::String>( + FlattenGetString(Utils::OpenHandle(*json_string))); + EXCEPTION_PREAMBLE(isolate); + i::Handle<i::Object> result; + if (source->IsSeqOneByteString()) { + result = i::JsonParser<true>::Parse(source); + } else { + result = i::JsonParser<false>::Parse(source); + } + has_pending_exception = result.is_null(); + EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>()); + return Utils::ToLocal( + i::Handle<i::Object>::cast(scope.CloseAndEscape(result))); +} + + // --- D a t a --- bool Value::FullIsUndefined() const { @@ -2880,7 +2774,7 @@ Local<String> Value::ToString() const { LOG_API(isolate, "ToString"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - str = i::Execution::ToString(obj, &has_pending_exception); + str = i::Execution::ToString(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); } return ToApiHandle<String>(str); @@ -2900,7 +2794,7 @@ Local<String> Value::ToDetailString() const { LOG_API(isolate, "ToDetailString"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - str = i::Execution::ToDetailString(obj, &has_pending_exception); + str = i::Execution::ToDetailString(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<String>()); } return ToApiHandle<String>(str); @@ -2920,7 +2814,7 @@ Local<v8::Object> Value::ToObject() const { LOG_API(isolate, "ToObject"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - val = i::Execution::ToObject(obj, &has_pending_exception); + val = i::Execution::ToObject(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); } return ToApiHandle<Object>(val); @@ -2958,7 +2852,7 @@ Local<Number> Value::ToNumber() const { LOG_API(isolate, "ToNumber"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToNumber(obj, &has_pending_exception); + num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Number>()); } return ToApiHandle<Number>(num); @@ -2976,7 +2870,7 @@ Local<Integer> Value::ToInteger() const { LOG_API(isolate, "ToInteger"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToInteger(obj, &has_pending_exception); + num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); } return ToApiHandle<Integer>(num); @@ -2985,7 +2879,7 @@ Local<Integer> Value::ToInteger() const { void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); - ApiCheck(isolate != NULL && isolate->IsInitialized() && !i::V8::IsDead(), + ApiCheck(isolate != NULL && isolate->IsInitialized() && !isolate->IsDead(), "v8::internal::Internals::CheckInitialized()", "Isolate is not initialized or V8 has died"); } @@ -3071,12 +2965,6 @@ void v8::ArrayBuffer::CheckCast(Value* that) { } -void v8::ArrayBuffer::Allocator::Free(void* data) { - API_Fatal("v8::ArrayBuffer::Allocator::Free", - "Override Allocator::Free(void*, size_t)"); -} - - void v8::ArrayBufferView::CheckCast(Value* that) { i::Handle<i::Object> obj = Utils::OpenHandle(that); ApiCheck(obj->IsJSArrayBufferView(), @@ -3196,7 +3084,7 @@ double Value::NumberValue() const { LOG_API(isolate, "NumberValue"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToNumber(obj, &has_pending_exception); + num = i::Execution::ToNumber(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); } return num->Number(); @@ -3214,7 +3102,7 @@ int64_t Value::IntegerValue() const { LOG_API(isolate, "IntegerValue"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToInteger(obj, &has_pending_exception); + num = i::Execution::ToInteger(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, 0); } if (num->IsSmi()) { @@ -3236,7 +3124,7 @@ Local<Int32> Value::ToInt32() const { LOG_API(isolate, "ToInt32"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToInt32(obj, &has_pending_exception); + num = i::Execution::ToInt32(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Int32>()); } return ToApiHandle<Int32>(num); @@ -3254,7 +3142,7 @@ Local<Uint32> Value::ToUint32() const { LOG_API(isolate, "ToUInt32"); ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); - num = i::Execution::ToUint32(obj, &has_pending_exception); + num = i::Execution::ToUint32(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); } return ToApiHandle<Uint32>(num); @@ -3273,7 +3161,7 @@ Local<Uint32> Value::ToArrayIndex() const { ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); i::Handle<i::Object> string_obj = - i::Execution::ToString(obj, &has_pending_exception); + i::Execution::ToString(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Uint32>()); i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); uint32_t index; @@ -3301,7 +3189,7 @@ int32_t Value::Int32Value() const { ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); i::Handle<i::Object> num = - i::Execution::ToInt32(obj, &has_pending_exception); + i::Execution::ToInt32(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, 0); if (num->IsSmi()) { return i::Smi::cast(*num)->value(); @@ -3382,7 +3270,7 @@ uint32_t Value::Uint32Value() const { ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); i::Handle<i::Object> num = - i::Execution::ToUint32(obj, &has_pending_exception); + i::Execution::ToUint32(isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, 0); if (num->IsSmi()) { return i::Smi::cast(*num)->value(); @@ -3502,7 +3390,7 @@ Local<Value> v8::Object::Get(uint32_t index) { ENTER_V8(isolate); i::Handle<i::JSObject> self = Utils::OpenHandle(this); EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> result = i::Object::GetElement(self, index); + i::Handle<i::Object> result = i::Object::GetElement(isolate, self, index); has_pending_exception = result.is_null(); EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); return Utils::ToLocal(result); @@ -3519,7 +3407,7 @@ PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); if (!key_obj->IsName()) { EXCEPTION_PREAMBLE(isolate); - key_obj = i::Execution::ToString(key_obj, &has_pending_exception); + key_obj = i::Execution::ToString(isolate, key_obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE)); } i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj); @@ -3729,7 +3617,7 @@ bool v8::Object::Delete(uint32_t index) { ENTER_V8(isolate); HandleScope scope(reinterpret_cast<Isolate*>(isolate)); i::Handle<i::JSObject> self = Utils::OpenHandle(this); - return i::JSObject::DeleteElement(self, index)->IsTrue(); + return i::JSReceiver::DeleteElement(self, index)->IsTrue(); } @@ -3758,7 +3646,8 @@ static inline bool ObjectSetAccessor(Object* obj, name, getter, setter, data, settings, attributes, signature); if (info.is_null()) return false; bool fast = Utils::OpenHandle(obj)->HasFastProperties(); - i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(obj), info); + i::Handle<i::Object> result = + i::JSObject::SetAccessor(Utils::OpenHandle(obj), info); if (result.is_null() || result->IsUndefined()) return false; if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(obj), 0); return true; @@ -3766,17 +3655,6 @@ static inline bool ObjectSetAccessor(Object* obj, bool Object::SetAccessor(Handle<String> name, - AccessorGetter getter, - AccessorSetter setter, - v8::Handle<Value> data, - AccessControl settings, - PropertyAttribute attributes) { - return ObjectSetAccessor( - this, name, getter, setter, data, settings, attributes); -} - - -bool Object::SetAccessor(Handle<String> name, AccessorGetterCallback getter, AccessorSetterCallback setter, v8::Handle<Value> data, @@ -3787,10 +3665,10 @@ bool Object::SetAccessor(Handle<String> name, } -bool Object::SetAccessor(Handle<String> name, - Handle<DeclaredAccessorDescriptor> descriptor, - AccessControl settings, - PropertyAttribute attributes) { +bool Object::SetDeclaredAccessor(Local<String> name, + Local<DeclaredAccessorDescriptor> descriptor, + PropertyAttribute attributes, + AccessControl settings) { void* null = NULL; return ObjectSetAccessor( this, name, descriptor, null, null, settings, attributes); @@ -4020,7 +3898,7 @@ bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { i::Handle<i::String> key_obj = Utils::OpenHandle(*key); i::Handle<i::String> key_string = isolate->factory()->InternalizeString(key_obj); - self->DeleteHiddenProperty(*key_string); + i::JSObject::DeleteHiddenProperty(self, key_string); return true; } @@ -4231,7 +4109,7 @@ bool v8::Object::IsCallable() { i::HandleScope scope(isolate); i::Handle<i::JSObject> obj = Utils::OpenHandle(this); if (obj->IsJSFunction()) return true; - return i::Execution::GetFunctionDelegate(obj)->IsJSFunction(); + return i::Execution::GetFunctionDelegate(isolate, obj)->IsJSFunction(); } @@ -4255,15 +4133,15 @@ Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, fun = i::Handle<i::JSFunction>::cast(obj); } else { EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> delegate = - i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); + i::Handle<i::Object> delegate = i::Execution::TryGetFunctionDelegate( + isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); fun = i::Handle<i::JSFunction>::cast(delegate); recv_obj = obj; } EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> returned = - i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); + i::Handle<i::Object> returned = i::Execution::Call( + isolate, fun, recv_obj, argc, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Value>()); return Utils::ToLocal(scope.CloseAndEscape(returned)); } @@ -4292,14 +4170,14 @@ Local<v8::Value> Object::CallAsConstructor(int argc, i::Handle<i::JSObject>::cast(returned))); } EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> delegate = - i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); + i::Handle<i::Object> delegate = i::Execution::TryGetConstructorDelegate( + isolate, obj, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); if (!delegate->IsUndefined()) { i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> returned = - i::Execution::Call(fun, obj, argc, args, &has_pending_exception); + i::Handle<i::Object> returned = i::Execution::Call( + isolate, fun, obj, argc, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); ASSERT(!delegate->IsUndefined()); return Utils::ToLocal(scope.CloseAndEscape(returned)); @@ -4308,6 +4186,19 @@ Local<v8::Value> Object::CallAsConstructor(int argc, } +Local<Function> Function::New(Isolate* v8_isolate, + FunctionCallback callback, + Local<Value> data, + int length) { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); + LOG_API(isolate, "Function::New"); + ENTER_V8(isolate); + return FunctionTemplateNew( + isolate, callback, data, Local<Signature>(), length, true)-> + GetFunction(); +} + + Local<v8::Object> Function::NewInstance() const { return NewInstance(0, NULL); } @@ -4350,8 +4241,8 @@ Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); EXCEPTION_PREAMBLE(isolate); - i::Handle<i::Object> returned = - i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); + i::Handle<i::Object> returned = i::Execution::Call( + isolate, fun, recv_obj, argc, args, &has_pending_exception); EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); raw_result = *returned; } @@ -5289,8 +5180,8 @@ bool v8::V8::Initialize() { } -void v8::V8::SetEntropySource(EntropySource source) { - i::V8::SetEntropySource(source); +void v8::V8::SetEntropySource(EntropySource entropy_source) { + i::RandomNumberGenerator::SetEntropySource(entropy_source); } @@ -5435,7 +5326,8 @@ bool v8::V8::IdleNotification(int hint) { // continue to call IdleNotification. i::Isolate* isolate = i::Isolate::Current(); if (isolate == NULL || !isolate->IsInitialized()) return true; - return i::V8::IdleNotification(hint); + if (!i::FLAG_use_idle_notification) return true; + return isolate->heap()->IdleNotification(hint); } @@ -5463,18 +5355,6 @@ const char* v8::V8::GetVersion() { } -static i::Handle<i::FunctionTemplateInfo> - EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { - if (templ->constructor()->IsUndefined()) { - Local<FunctionTemplate> constructor = FunctionTemplate::New(); - Utils::OpenHandle(*constructor)->set_instance_template(*templ); - templ->set_constructor(*Utils::OpenHandle(*constructor)); - } - return i::Handle<i::FunctionTemplateInfo>( - i::FunctionTemplateInfo::cast(templ->constructor())); -} - - static i::Handle<i::Context> CreateEnvironment( i::Isolate* isolate, v8::ExtensionConfiguration* extensions, @@ -5491,13 +5371,11 @@ static i::Handle<i::Context> CreateEnvironment( if (!global_template.IsEmpty()) { // Make sure that the global_template has a constructor. - global_constructor = - EnsureConstructor(Utils::OpenHandle(*global_template)); + global_constructor = EnsureConstructor(*global_template); // Create a fresh template for the global proxy object. proxy_template = ObjectTemplate::New(); - proxy_constructor = - EnsureConstructor(Utils::OpenHandle(*proxy_template)); + proxy_constructor = EnsureConstructor(*proxy_template); // Set the global template to be the prototype template of // global proxy template. @@ -5540,26 +5418,6 @@ static i::Handle<i::Context> CreateEnvironment( return env; } -#ifdef V8_USE_UNSAFE_HANDLES -Persistent<Context> v8::Context::New( - v8::ExtensionConfiguration* extensions, - v8::Handle<ObjectTemplate> global_template, - v8::Handle<Value> global_object) { - i::Isolate::EnsureDefaultIsolate(); - i::Isolate* isolate = i::Isolate::Current(); - Isolate* external_isolate = reinterpret_cast<Isolate*>(isolate); - EnsureInitializedForIsolate(isolate, "v8::Context::New()"); - LOG_API(isolate, "Context::New"); - ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>()); - i::HandleScope scope(isolate); - i::Handle<i::Context> env = - CreateEnvironment(isolate, extensions, global_template, global_object); - if (env.is_null()) return Persistent<Context>(); - return Persistent<Context>::New(external_isolate, Utils::ToLocal(env)); -} -#endif - - Local<Context> v8::Context::New( v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, @@ -6202,7 +6060,7 @@ Local<v8::Value> v8::Date::New(double time) { ENTER_V8(isolate); EXCEPTION_PREAMBLE(isolate); i::Handle<i::Object> obj = - i::Execution::NewDate(time, &has_pending_exception); + i::Execution::NewDate(isolate, time, &has_pending_exception); EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); return Utils::ToLocal(obj); } @@ -6904,47 +6762,6 @@ void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { } -void V8::PauseProfiler() { - i::Isolate* isolate = i::Isolate::Current(); - isolate->logger()->PauseProfiler(); -} - - -void V8::ResumeProfiler() { - i::Isolate* isolate = i::Isolate::Current(); - isolate->logger()->ResumeProfiler(); -} - - -bool V8::IsProfilerPaused() { - i::Isolate* isolate = i::Isolate::Current(); - return isolate->logger()->IsProfilerPaused(); -} - - -int V8::GetCurrentThreadId() { - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); - return isolate->thread_id().ToInteger(); -} - - -void V8::TerminateExecution(int thread_id) { - i::Isolate* isolate = i::Isolate::Current(); - if (!isolate->IsInitialized()) return; - API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); - // If the thread_id identifies the current thread just terminate - // execution right away. Otherwise, ask the thread manager to - // terminate the thread with the given id if any. - i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); - if (isolate->thread_id().Equals(internal_tid)) { - isolate->stack_guard()->TerminateExecution(); - } else { - isolate->thread_manager()->TerminateExecution(internal_tid); - } -} - - void V8::TerminateExecution(Isolate* isolate) { // If no isolate is supplied, use the default isolate. if (isolate != NULL) { @@ -7178,37 +6995,6 @@ Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { #ifdef ENABLE_DEBUGGER_SUPPORT -static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { - i::Isolate* isolate = i::Isolate::Current(); - if (isolate->debug_event_callback() != NULL) { - isolate->debug_event_callback()(event_details.GetEvent(), - event_details.GetExecutionState(), - event_details.GetEventData(), - event_details.GetCallbackData()); - } -} - - -bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()"); - ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false); - ENTER_V8(isolate); - - isolate->set_debug_event_callback(that); - - i::HandleScope scope(isolate); - i::Handle<i::Object> foreign = isolate->factory()->undefined_value(); - if (that != NULL) { - foreign = - isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper)); - } - isolate->debugger()->SetEventListener(foreign, - Utils::OpenHandle(*data, true)); - return true; -} - - bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { i::Isolate* isolate = i::Isolate::Current(); EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()"); @@ -7268,35 +7054,6 @@ void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) { } -static void MessageHandlerWrapper(const v8::Debug::Message& message) { - i::Isolate* isolate = i::Isolate::Current(); - if (isolate->message_handler()) { - v8::String::Value json(message.GetJSON()); - (isolate->message_handler())(*json, json.length(), message.GetClientData()); - } -} - - -void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, - bool message_handler_thread) { - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); - ENTER_V8(isolate); - - // Message handler thread not supported any more. Parameter temporally left in - // the API for client compatibility reasons. - CHECK(!message_handler_thread); - - // TODO(sgjesse) support the old message handler API through a simple wrapper. - isolate->set_message_handler(handler); - if (handler != NULL) { - isolate->debugger()->SetMessageHandler(MessageHandlerWrapper); - } else { - isolate->debugger()->SetMessageHandler(NULL); - } -} - - void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { i::Isolate* isolate = i::Isolate::Current(); EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler"); @@ -7325,7 +7082,8 @@ void Debug::SetHostDispatchHandler(HostDispatchHandler handler, i::Isolate* isolate = i::Isolate::Current(); EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler"); ENTER_V8(isolate); - isolate->debugger()->SetHostDispatchHandler(handler, period); + isolate->debugger()->SetHostDispatchHandler( + handler, i::TimeDelta::FromMilliseconds(period)); } @@ -7399,7 +7157,7 @@ void Debug::DisableAgent() { void Debug::ProcessDebugMessages() { - i::Execution::ProcessDebugMessages(true); + i::Execution::ProcessDebugMessages(i::Isolate::Current(), true); } @@ -7444,8 +7202,6 @@ Handle<String> CpuProfileNode::GetFunctionName() const { int CpuProfileNode::GetScriptId() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptId"); const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); const i::CodeEntry* entry = node->entry(); return entry->script_id(); @@ -7462,43 +7218,29 @@ Handle<String> CpuProfileNode::GetScriptResourceName() const { int CpuProfileNode::GetLineNumber() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber"); return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); } -double CpuProfileNode::GetTotalTime() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime"); - return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); -} - - -double CpuProfileNode::GetSelfTime() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime"); - return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); +const char* CpuProfileNode::GetBailoutReason() const { + const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); + return node->entry()->bailout_reason(); } -double CpuProfileNode::GetTotalSamplesCount() const { +double CpuProfileNode::GetSelfSamplesCount() const { i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount"); - return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); + IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); + return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); } -double CpuProfileNode::GetSelfSamplesCount() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount"); +unsigned CpuProfileNode::GetHitCount() const { return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); } unsigned CpuProfileNode::GetCallUid() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid"); return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); } @@ -7509,15 +7251,11 @@ unsigned CpuProfileNode::GetNodeId() const { int CpuProfileNode::GetChildrenCount() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount"); return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); } const CpuProfileNode* CpuProfileNode::GetChild(int index) const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild"); const i::ProfileNode* child = reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); return reinterpret_cast<const CpuProfileNode*>(child); @@ -7538,8 +7276,6 @@ void CpuProfile::Delete() { unsigned CpuProfile::GetUid() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfile::GetUid"); return reinterpret_cast<const i::CpuProfile*>(this)->uid(); } @@ -7554,8 +7290,6 @@ Handle<String> CpuProfile::GetTitle() const { const CpuProfileNode* CpuProfile::GetTopDownRoot() const { - i::Isolate* isolate = i::Isolate::Current(); - IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot"); const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); } @@ -7569,13 +7303,13 @@ const CpuProfileNode* CpuProfile::GetSample(int index) const { int64_t CpuProfile::GetStartTime() const { const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); - return profile->start_time_us(); + return (profile->start_time() - i::Time::UnixEpoch()).InMicroseconds(); } int64_t CpuProfile::GetEndTime() const { const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); - return profile->end_time_us(); + return (profile->end_time() - i::Time::UnixEpoch()).InMicroseconds(); } @@ -7589,6 +7323,13 @@ int CpuProfiler::GetProfileCount() { } +void CpuProfiler::SetSamplingInterval(int us) { + ASSERT(us >= 0); + return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( + i::TimeDelta::FromMicroseconds(us)); +} + + const CpuProfile* CpuProfiler::GetCpuProfile(int index) { return reinterpret_cast<const CpuProfile*>( reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index)); @@ -7613,6 +7354,19 @@ void CpuProfiler::DeleteAllCpuProfiles() { } +void CpuProfiler::SetIdle(bool is_idle) { + i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate(); + i::StateTag state = isolate->current_vm_state(); + ASSERT(state == i::EXTERNAL || state == i::IDLE); + if (isolate->js_entry_sp() != NULL) return; + if (is_idle) { + isolate->set_current_vm_state(i::IDLE); + } else if (state == i::IDLE) { + isolate->set_current_vm_state(i::EXTERNAL); + } +} + + static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { return const_cast<i::HeapGraphEdge*>( reinterpret_cast<const i::HeapGraphEdge*>(edge)); @@ -8091,20 +7845,6 @@ void DeferredHandles::Iterate(ObjectVisitor* v) { } -v8::Handle<v8::Value> InvokeAccessorGetter( - v8::Local<v8::String> property, - const v8::AccessorInfo& info, - v8::AccessorGetter getter) { - Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); - Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( - getter)); - // Leaving JavaScript. - VMState<EXTERNAL> state(isolate); - ExternalCallbackScope call_scope(isolate, getter_address); - return getter(property, info); -} - - void InvokeAccessorGetterCallback( v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info, @@ -8115,19 +7855,7 @@ void InvokeAccessorGetterCallback( getter)); VMState<EXTERNAL> state(isolate); ExternalCallbackScope call_scope(isolate, getter_address); - return getter(property, info); -} - - -v8::Handle<v8::Value> InvokeInvocationCallback( - const v8::Arguments& args, - v8::InvocationCallback callback) { - Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate()); - Address callback_address = - reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); - VMState<EXTERNAL> state(isolate); - ExternalCallbackScope call_scope(isolate, callback_address); - return callback(args); + getter(property, info); } @@ -8138,7 +7866,7 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); VMState<EXTERNAL> state(isolate); ExternalCallbackScope call_scope(isolate, callback_address); - return callback(info); + callback(info); } |