📄 api.cc.svn-base
字号:
}void Context::Enter() { if (IsDeadCheck("v8::Context::Enter()")) return; i::Handle<i::Context> env = Utils::OpenHandle(this); thread_local.EnterContext(env); thread_local.SaveContext(i::GlobalHandles::Create(i::Top::context())); i::Top::set_context(*env); thread_local.SaveSecurityContext( i::GlobalHandles::Create(i::Top::security_context())); i::Top::set_security_context(*env);}void Context::Exit() { if (has_shut_down) return; if (!ApiCheck(thread_local.LeaveLastContext(), "v8::Context::Exit()", "Cannot exit non-entered context")) { return; } // Content of 'last_context' and 'last_security_context' could be NULL. i::Handle<i::Object> last_context = thread_local.RestoreContext(); i::Top::set_context(static_cast<i::Context*>(*last_context)); i::GlobalHandles::Destroy(last_context.location()); i::Handle<i::Object> last_security_context = thread_local.RestoreSecurityContext(); i::Top::set_security_context( static_cast<i::Context*>(*last_security_context)); i::GlobalHandles::Destroy(last_security_context.location());}void v8::HandleScope::DeleteExtensions() { ASSERT(current_.extensions != 0); thread_local.DeleteExtensions(current_.extensions);}void HandleScope::ZapRange(void** start, void** end) { if (start == NULL) return; for (void** p = start; p < end; p++) { *p = reinterpret_cast<void*>(v8::internal::kHandleZapValue); }}void** v8::HandleScope::RawClose(void** value) { if (!ApiCheck(!is_closed_, "v8::HandleScope::Close()", "Local scope has already been closed")) { return 0; } LOG_API("CloseHandleScope"); // Read the result before popping the handle block. i::Object* result = reinterpret_cast<i::Object*>(*value); is_closed_ = true; RestorePreviousState(); // Allocate a new handle on the previous handle block. i::Handle<i::Object> handle(result); return reinterpret_cast<void**>(handle.location());}// --- N e a n d e r ---// A constructor cannot easily return an error value, therefore it is necessary// to check for a dead VM with ON_BAILOUT before constructing any Neander// objects. To remind you about this there is no HandleScope in the// NeanderObject constructor. When you add one to the site calling the// constructor you should check that you ensured the VM was not dead first.NeanderObject::NeanderObject(int size) { EnsureInitialized("v8::Nowhere"); value_ = i::Factory::NewNeanderObject(); i::Handle<i::FixedArray> elements = i::Factory::NewFixedArray(size); value_->set_elements(*elements);}int NeanderObject::size() { return i::FixedArray::cast(value_->elements())->length();}NeanderArray::NeanderArray() : obj_(2) { obj_.set(0, i::Smi::FromInt(0));}int NeanderArray::length() { return i::Smi::cast(obj_.get(0))->value();}i::Object* NeanderArray::get(int offset) { ASSERT(0 <= offset); ASSERT(offset < length()); return obj_.get(offset + 1);}// This method cannot easily return an error value, therefore it is necessary// to check for a dead VM with ON_BAILOUT before calling it. To remind you// about this there is no HandleScope in this method. When you add one to the// site calling this method you should check that you ensured the VM was not// dead first.void NeanderArray::add(i::Handle<i::Object> value) { int length = this->length(); int size = obj_.size(); if (length == size - 1) { i::Handle<i::FixedArray> new_elms = i::Factory::NewFixedArray(2 * size); for (int i = 0; i < length; i++) new_elms->set(i + 1, get(i)); obj_.value()->set_elements(*new_elms); } obj_.set(length + 1, *value); obj_.set(0, i::Smi::FromInt(length + 1));}void NeanderArray::set(int index, i::Object* value) { if (index < 0 || index >= this->length()) return; obj_.set(index + 1, value);}// --- T e m p l a t e ---static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { that->set_tag(i::Smi::FromInt(type));}void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, v8::PropertyAttribute attribute) { if (IsDeadCheck("v8::Template::SetProperty()")) return; HandleScope scope; i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); 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)));}// --- F u n c t i o n T e m p l a t e ---static void InitializeFunctionTemplate( i::Handle<i::FunctionTemplateInfo> info) { info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); info->set_flag(0);}Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { if (IsDeadCheck("v8::FunctionTemplate::PrototypeTemplate()")) { return Local<ObjectTemplate>(); } i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template()); if (result->IsUndefined()) { result = Utils::OpenHandle(*ObjectTemplate::New()); Utils::OpenHandle(this)->set_prototype_template(*result); } return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result));}void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { if (IsDeadCheck("v8::FunctionTemplate::Inherit()")) return; Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));}// To distinguish the function templates, so that we can find them in the// function cache of the global context.static int next_serial_number = 0;Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, v8::Handle<Value> data, v8::Handle<Signature> signature) { EnsureInitialized("v8::FunctionTemplate::New()"); LOG_API("FunctionTemplate::New"); i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); i::Handle<i::FunctionTemplateInfo> obj = i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); InitializeFunctionTemplate(obj); obj->set_serial_number(i::Smi::FromInt(next_serial_number++)); if (callback != 0) { if (data.IsEmpty()) data = v8::Undefined(); Utils::ToLocal(obj)->SetCallHandler(callback, data); } obj->set_undetectable(false); obj->set_needs_access_check(false); if (!signature.IsEmpty()) obj->set_signature(*Utils::OpenHandle(*signature)); return Utils::ToLocal(obj);}Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, int argc, Handle<FunctionTemplate> argv[]) { EnsureInitialized("v8::Signature::New()"); LOG_API("Signature::New"); i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::SIGNATURE_INFO_TYPE); i::Handle<i::SignatureInfo> obj = i::Handle<i::SignatureInfo>::cast(struct_obj); if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); if (argc > 0) { i::Handle<i::FixedArray> args = i::Factory::NewFixedArray(argc); for (int i = 0; i < argc; i++) { if (!argv[i].IsEmpty()) args->set(i, *Utils::OpenHandle(*argv[i])); } obj->set_args(*args); } return Utils::ToLocal(obj);}Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { Handle<FunctionTemplate> types[1] = { type }; return TypeSwitch::New(1, types);}Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { EnsureInitialized("v8::TypeSwitch::New()"); LOG_API("TypeSwitch::New"); i::Handle<i::FixedArray> vector = i::Factory::NewFixedArray(argc); for (int i = 0; i < argc; i++) vector->set(i, *Utils::OpenHandle(*types[i])); i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::TYPE_SWITCH_INFO_TYPE); i::Handle<i::TypeSwitchInfo> obj = i::Handle<i::TypeSwitchInfo>::cast(struct_obj); obj->set_types(*vector); return Utils::ToLocal(obj);}int TypeSwitch::match(v8::Handle<Value> value) { LOG_API("TypeSwitch::match"); i::Handle<i::Object> obj = Utils::OpenHandle(*value); i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); i::FixedArray* types = i::FixedArray::cast(info->types()); for (int i = 0; i < types->length(); i++) { if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) return i + 1; } return 0;}void FunctionTemplate::SetCallHandler(InvocationCallback callback, v8::Handle<Value> data) { if (IsDeadCheck("v8::FunctionTemplate::SetCallHandler()")) return; HandleScope scope; i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE); i::Handle<i::CallHandlerInfo> obj = i::Handle<i::CallHandlerInfo>::cast(struct_obj); obj->set_callback(*FromCData(callback)); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); Utils::OpenHandle(this)->set_call_code(*obj);}void FunctionTemplate::AddInstancePropertyAccessor( v8::Handle<String> name, AccessorGetter getter, AccessorSetter setter, v8::Handle<Value> data, v8::AccessControl settings, v8::PropertyAttribute attributes) { if (IsDeadCheck("v8::FunctionTemplate::AddInstancePropertyAccessor()")) { return; } HandleScope scope; i::Handle<i::AccessorInfo> obj = i::Factory::NewAccessorInfo(); ASSERT(getter != NULL); obj->set_getter(*FromCData(getter)); obj->set_setter(*FromCData(setter)); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); obj->set_name(*Utils::OpenHandle(*name)); if (settings & ALL_CAN_READ) obj->set_all_can_read(true); if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); if (list->IsUndefined()) { list = NeanderArray().value(); Utils::OpenHandle(this)->set_property_accessors(*list); } NeanderArray array(list); array.add(obj);}Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { if (IsDeadCheck("v8::FunctionTemplate::InstanceTemplate()") || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) return Local<ObjectTemplate>(); if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { Local<ObjectTemplate> templ = ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); } i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( Utils::OpenHandle(this)->instance_template())); return Utils::ToLocal(result);}void FunctionTemplate::SetClassName(Handle<String> name) { if (IsDeadCheck("v8::FunctionTemplate::SetClassName()")) return; Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));}void FunctionTemplate::SetHiddenPrototype(bool value) { if (IsDeadCheck("v8::FunctionTemplate::SetHiddenPrototype()")) return; Utils::OpenHandle(this)->set_hidden_prototype(value);}void FunctionTemplate::SetNamedInstancePropertyHandler( NamedPropertyGetter getter, NamedPropertySetter setter, NamedPropertyQuery query, NamedPropertyDeleter remover, NamedPropertyEnumerator enumerator, Handle<Value> data) { if (IsDeadCheck("v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { return; } HandleScope scope; i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); i::Handle<i::InterceptorInfo> obj = i::Handle<i::InterceptorInfo>::cast(struct_obj); if (getter != 0) obj->set_getter(*FromCData(getter)); if (setter != 0) obj->set_setter(*FromCData(setter)); if (query != 0) obj->set_query(*FromCData(query)); if (remover != 0) obj->set_deleter(*FromCData(remover)); if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator)); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); Utils::OpenHandle(this)->set_named_property_handler(*obj);}void FunctionTemplate::SetIndexedInstancePropertyHandler( IndexedPropertyGetter getter, IndexedPropertySetter setter, IndexedPropertyQuery query, IndexedPropertyDeleter remover, IndexedPropertyEnumerator enumerator, Handle<Value> data) { if (IsDeadCheck( "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { return; } HandleScope scope; i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); i::Handle<i::InterceptorInfo> obj = i::Handle<i::InterceptorInfo>::cast(struct_obj); if (getter != 0) obj->set_getter(*FromCData(getter)); if (setter != 0) obj->set_setter(*FromCData(setter)); if (query != 0) obj->set_query(*FromCData(query)); if (remover != 0) obj->set_deleter(*FromCData(remover)); if (enumerator != 0) obj->set_enumerator(*FromCData(enumerator)); if (data.IsEmpty()) data = v8::Undefined(); obj->set_data(*Utils::OpenHandle(*data)); Utils::OpenHandle(this)->set_indexed_property_handler(*obj);}void FunctionTemplate::SetInstanceCallAsFunctionHandler( InvocationCallback callback, Handle<Value> data) { if (IsDeadCheck("v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { return; } HandleScope scope; i::Handle<i::Struct> struct_obj = i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -