| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 488 |
| 489 static SnapshotCreatorData* cast(void* data) { | 489 static SnapshotCreatorData* cast(void* data) { |
| 490 return reinterpret_cast<SnapshotCreatorData*>(data); | 490 return reinterpret_cast<SnapshotCreatorData*>(data); |
| 491 } | 491 } |
| 492 | 492 |
| 493 ArrayBufferAllocator allocator_; | 493 ArrayBufferAllocator allocator_; |
| 494 Isolate* isolate_; | 494 Isolate* isolate_; |
| 495 Persistent<Context> default_context_; | 495 Persistent<Context> default_context_; |
| 496 PersistentValueVector<Context> contexts_; | 496 PersistentValueVector<Context> contexts_; |
| 497 PersistentValueVector<Template> templates_; | 497 PersistentValueVector<Template> templates_; |
| 498 std::vector<SerializeInternalFieldsCallback> internal_fields_serializers_; | 498 std::vector<SerializeInternalFieldsCallback> embedder_fields_serializers_; |
| 499 bool created_; | 499 bool created_; |
| 500 }; | 500 }; |
| 501 | 501 |
| 502 } // namespace | 502 } // namespace |
| 503 | 503 |
| 504 SnapshotCreator::SnapshotCreator(intptr_t* external_references, | 504 SnapshotCreator::SnapshotCreator(intptr_t* external_references, |
| 505 StartupData* existing_snapshot) { | 505 StartupData* existing_snapshot) { |
| 506 i::Isolate* internal_isolate = new i::Isolate(true); | 506 i::Isolate* internal_isolate = new i::Isolate(true); |
| 507 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | 507 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
| 508 SnapshotCreatorData* data = new SnapshotCreatorData(isolate); | 508 SnapshotCreatorData* data = new SnapshotCreatorData(isolate); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 547 |
| 548 size_t SnapshotCreator::AddContext(Local<Context> context, | 548 size_t SnapshotCreator::AddContext(Local<Context> context, |
| 549 SerializeInternalFieldsCallback callback) { | 549 SerializeInternalFieldsCallback callback) { |
| 550 DCHECK(!context.IsEmpty()); | 550 DCHECK(!context.IsEmpty()); |
| 551 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); | 551 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); |
| 552 DCHECK(!data->created_); | 552 DCHECK(!data->created_); |
| 553 Isolate* isolate = data->isolate_; | 553 Isolate* isolate = data->isolate_; |
| 554 CHECK_EQ(isolate, context->GetIsolate()); | 554 CHECK_EQ(isolate, context->GetIsolate()); |
| 555 size_t index = static_cast<int>(data->contexts_.Size()); | 555 size_t index = static_cast<int>(data->contexts_.Size()); |
| 556 data->contexts_.Append(context); | 556 data->contexts_.Append(context); |
| 557 data->internal_fields_serializers_.push_back(callback); | 557 data->embedder_fields_serializers_.push_back(callback); |
| 558 return index; | 558 return index; |
| 559 } | 559 } |
| 560 | 560 |
| 561 size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) { | 561 size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) { |
| 562 DCHECK(!template_obj.IsEmpty()); | 562 DCHECK(!template_obj.IsEmpty()); |
| 563 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); | 563 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); |
| 564 DCHECK(!data->created_); | 564 DCHECK(!data->created_); |
| 565 DCHECK_EQ(reinterpret_cast<i::Isolate*>(data->isolate_), | 565 DCHECK_EQ(reinterpret_cast<i::Isolate*>(data->isolate_), |
| 566 Utils::OpenHandle(*template_obj)->GetIsolate()); | 566 Utils::OpenHandle(*template_obj)->GetIsolate()); |
| 567 size_t index = static_cast<int>(data->templates_.Size()); | 567 size_t index = static_cast<int>(data->templates_.Size()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 i::ExternalReferenceTable::instance(isolate)->ResetCount(); | 637 i::ExternalReferenceTable::instance(isolate)->ResetCount(); |
| 638 #endif // DEBUG | 638 #endif // DEBUG |
| 639 | 639 |
| 640 i::StartupSerializer startup_serializer(isolate, function_code_handling); | 640 i::StartupSerializer startup_serializer(isolate, function_code_handling); |
| 641 startup_serializer.SerializeStrongReferences(); | 641 startup_serializer.SerializeStrongReferences(); |
| 642 | 642 |
| 643 // Serialize each context with a new partial serializer. | 643 // Serialize each context with a new partial serializer. |
| 644 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1); | 644 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1); |
| 645 | 645 |
| 646 { | 646 { |
| 647 // The default snapshot does not support internal fields. | 647 // The default snapshot does not support embedder fields. |
| 648 i::PartialSerializer partial_serializer( | 648 i::PartialSerializer partial_serializer( |
| 649 isolate, &startup_serializer, v8::SerializeInternalFieldsCallback()); | 649 isolate, &startup_serializer, v8::SerializeInternalFieldsCallback()); |
| 650 partial_serializer.Serialize(&default_context, false); | 650 partial_serializer.Serialize(&default_context, false); |
| 651 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); | 651 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); |
| 652 } | 652 } |
| 653 | 653 |
| 654 for (int i = 0; i < num_additional_contexts; i++) { | 654 for (int i = 0; i < num_additional_contexts; i++) { |
| 655 i::PartialSerializer partial_serializer( | 655 i::PartialSerializer partial_serializer( |
| 656 isolate, &startup_serializer, data->internal_fields_serializers_[i]); | 656 isolate, &startup_serializer, data->embedder_fields_serializers_[i]); |
| 657 partial_serializer.Serialize(&contexts[i], true); | 657 partial_serializer.Serialize(&contexts[i], true); |
| 658 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); | 658 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); |
| 659 } | 659 } |
| 660 | 660 |
| 661 startup_serializer.SerializeWeakReferencesAndDeferred(); | 661 startup_serializer.SerializeWeakReferencesAndDeferred(); |
| 662 | 662 |
| 663 #ifdef DEBUG | 663 #ifdef DEBUG |
| 664 if (i::FLAG_external_reference_stats) { | 664 if (i::FLAG_external_reference_stats) { |
| 665 i::ExternalReferenceTable::instance(isolate)->PrintCount(); | 665 i::ExternalReferenceTable::instance(isolate)->PrintCount(); |
| 666 } | 666 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 #endif // VERIFY_HEAP | 906 #endif // VERIFY_HEAP |
| 907 return result.location(); | 907 return result.location(); |
| 908 } | 908 } |
| 909 | 909 |
| 910 void V8::RegisterExternallyReferencedObject(i::Object** object, | 910 void V8::RegisterExternallyReferencedObject(i::Object** object, |
| 911 i::Isolate* isolate) { | 911 i::Isolate* isolate) { |
| 912 isolate->heap()->RegisterExternallyReferencedObject(object); | 912 isolate->heap()->RegisterExternallyReferencedObject(object); |
| 913 } | 913 } |
| 914 | 914 |
| 915 void V8::MakeWeak(i::Object** location, void* parameter, | 915 void V8::MakeWeak(i::Object** location, void* parameter, |
| 916 int internal_field_index1, int internal_field_index2, | 916 int embedder_field_index1, int embedder_field_index2, |
| 917 WeakCallbackInfo<void>::Callback weak_callback) { | 917 WeakCallbackInfo<void>::Callback weak_callback) { |
| 918 WeakCallbackType type = WeakCallbackType::kParameter; | 918 WeakCallbackType type = WeakCallbackType::kParameter; |
| 919 if (internal_field_index1 == 0) { | 919 if (embedder_field_index1 == 0) { |
| 920 if (internal_field_index2 == 1) { | 920 if (embedder_field_index2 == 1) { |
| 921 type = WeakCallbackType::kInternalFields; | 921 type = WeakCallbackType::kInternalFields; |
| 922 } else { | 922 } else { |
| 923 DCHECK_EQ(internal_field_index2, -1); | 923 DCHECK_EQ(embedder_field_index2, -1); |
| 924 type = WeakCallbackType::kInternalFields; | 924 type = WeakCallbackType::kInternalFields; |
| 925 } | 925 } |
| 926 } else { | 926 } else { |
| 927 DCHECK_EQ(internal_field_index1, -1); | 927 DCHECK_EQ(embedder_field_index1, -1); |
| 928 DCHECK_EQ(internal_field_index2, -1); | 928 DCHECK_EQ(embedder_field_index2, -1); |
| 929 } | 929 } |
| 930 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); | 930 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); |
| 931 } | 931 } |
| 932 | 932 |
| 933 void V8::MakeWeak(i::Object** location, void* parameter, | 933 void V8::MakeWeak(i::Object** location, void* parameter, |
| 934 WeakCallbackInfo<void>::Callback weak_callback, | 934 WeakCallbackInfo<void>::Callback weak_callback, |
| 935 WeakCallbackType type) { | 935 WeakCallbackType type) { |
| 936 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); | 936 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); |
| 937 } | 937 } |
| 938 | 938 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 964 | 964 |
| 965 void V8::FromJustIsNothing() { | 965 void V8::FromJustIsNothing() { |
| 966 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing."); | 966 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing."); |
| 967 } | 967 } |
| 968 | 968 |
| 969 | 969 |
| 970 void V8::ToLocalEmpty() { | 970 void V8::ToLocalEmpty() { |
| 971 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal."); | 971 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal."); |
| 972 } | 972 } |
| 973 | 973 |
| 974 | |
| 975 void V8::InternalFieldOutOfBounds(int index) { | 974 void V8::InternalFieldOutOfBounds(int index) { |
| 976 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback, | 975 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback, |
| 977 "WeakCallbackInfo::GetInternalField", | 976 "WeakCallbackInfo::GetInternalField", |
| 978 "Internal field out of bounds."); | 977 "Internal field out of bounds."); |
| 979 } | 978 } |
| 980 | 979 |
| 981 | 980 |
| 982 // --- H a n d l e s --- | 981 // --- H a n d l e s --- |
| 983 | 982 |
| 984 | 983 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 i::Handle<i::CallHandlerInfo> obj = | 1853 i::Handle<i::CallHandlerInfo> obj = |
| 1855 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1854 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
| 1856 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1855 SET_FIELD_WRAPPED(obj, set_callback, callback); |
| 1857 if (data.IsEmpty()) { | 1856 if (data.IsEmpty()) { |
| 1858 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1857 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1859 } | 1858 } |
| 1860 obj->set_data(*Utils::OpenHandle(*data)); | 1859 obj->set_data(*Utils::OpenHandle(*data)); |
| 1861 cons->set_instance_call_handler(*obj); | 1860 cons->set_instance_call_handler(*obj); |
| 1862 } | 1861 } |
| 1863 | 1862 |
| 1864 | |
| 1865 int ObjectTemplate::InternalFieldCount() { | 1863 int ObjectTemplate::InternalFieldCount() { |
| 1866 return Utils::OpenHandle(this)->internal_field_count(); | 1864 return Utils::OpenHandle(this)->embedder_field_count(); |
| 1867 } | 1865 } |
| 1868 | 1866 |
| 1869 | |
| 1870 void ObjectTemplate::SetInternalFieldCount(int value) { | 1867 void ObjectTemplate::SetInternalFieldCount(int value) { |
| 1871 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1868 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1872 if (!Utils::ApiCheck(i::Smi::IsValid(value), | 1869 if (!Utils::ApiCheck(i::Smi::IsValid(value), |
| 1873 "v8::ObjectTemplate::SetInternalFieldCount()", | 1870 "v8::ObjectTemplate::SetInternalFieldCount()", |
| 1874 "Invalid internal field count")) { | 1871 "Invalid embedder field count")) { |
| 1875 return; | 1872 return; |
| 1876 } | 1873 } |
| 1877 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 1874 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 1878 if (value > 0) { | 1875 if (value > 0) { |
| 1879 // The internal field count is set by the constructor function's | 1876 // The embedder field count is set by the constructor function's |
| 1880 // construct code, so we ensure that there is a constructor | 1877 // construct code, so we ensure that there is a constructor |
| 1881 // function to do the setting. | 1878 // function to do the setting. |
| 1882 EnsureConstructor(isolate, this); | 1879 EnsureConstructor(isolate, this); |
| 1883 } | 1880 } |
| 1884 Utils::OpenHandle(this)->set_internal_field_count(value); | 1881 Utils::OpenHandle(this)->set_embedder_field_count(value); |
| 1885 } | 1882 } |
| 1886 | 1883 |
| 1887 bool ObjectTemplate::IsImmutableProto() { | 1884 bool ObjectTemplate::IsImmutableProto() { |
| 1888 return Utils::OpenHandle(this)->immutable_proto(); | 1885 return Utils::OpenHandle(this)->immutable_proto(); |
| 1889 } | 1886 } |
| 1890 | 1887 |
| 1891 void ObjectTemplate::SetImmutableProto() { | 1888 void ObjectTemplate::SetImmutableProto() { |
| 1892 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1889 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1893 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 1890 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 1894 Utils::OpenHandle(this)->set_immutable_proto(true); | 1891 Utils::OpenHandle(this)->set_immutable_proto(true); |
| (...skipping 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6030 | 6027 |
| 6031 uint32_t Uint32::Value() const { | 6028 uint32_t Uint32::Value() const { |
| 6032 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6029 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6033 if (obj->IsSmi()) { | 6030 if (obj->IsSmi()) { |
| 6034 return i::Smi::cast(*obj)->value(); | 6031 return i::Smi::cast(*obj)->value(); |
| 6035 } else { | 6032 } else { |
| 6036 return static_cast<uint32_t>(obj->Number()); | 6033 return static_cast<uint32_t>(obj->Number()); |
| 6037 } | 6034 } |
| 6038 } | 6035 } |
| 6039 | 6036 |
| 6040 | |
| 6041 int v8::Object::InternalFieldCount() { | 6037 int v8::Object::InternalFieldCount() { |
| 6042 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); | 6038 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); |
| 6043 if (!self->IsJSObject()) return 0; | 6039 if (!self->IsJSObject()) return 0; |
| 6044 return i::Handle<i::JSObject>::cast(self)->GetInternalFieldCount(); | 6040 return i::Handle<i::JSObject>::cast(self)->GetEmbedderFieldCount(); |
| 6045 } | 6041 } |
| 6046 | 6042 |
| 6047 | |
| 6048 static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index, | 6043 static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index, |
| 6049 const char* location) { | 6044 const char* location) { |
| 6050 return Utils::ApiCheck( | 6045 return Utils::ApiCheck( |
| 6051 obj->IsJSObject() && | 6046 obj->IsJSObject() && |
| 6052 (index < i::Handle<i::JSObject>::cast(obj)->GetInternalFieldCount()), | 6047 (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()), |
| 6053 location, "Internal field out of bounds"); | 6048 location, "Internal field out of bounds"); |
| 6054 } | 6049 } |
| 6055 | 6050 |
| 6056 | |
| 6057 Local<Value> v8::Object::SlowGetInternalField(int index) { | 6051 Local<Value> v8::Object::SlowGetInternalField(int index) { |
| 6058 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); | 6052 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); |
| 6059 const char* location = "v8::Object::GetInternalField()"; | 6053 const char* location = "v8::Object::GetInternalField()"; |
| 6060 if (!InternalFieldOK(obj, index, location)) return Local<Value>(); | 6054 if (!InternalFieldOK(obj, index, location)) return Local<Value>(); |
| 6061 i::Handle<i::Object> value( | 6055 i::Handle<i::Object> value( |
| 6062 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), | 6056 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index), |
| 6063 obj->GetIsolate()); | 6057 obj->GetIsolate()); |
| 6064 return Utils::ToLocal(value); | 6058 return Utils::ToLocal(value); |
| 6065 } | 6059 } |
| 6066 | 6060 |
| 6067 | |
| 6068 void v8::Object::SetInternalField(int index, v8::Local<Value> value) { | 6061 void v8::Object::SetInternalField(int index, v8::Local<Value> value) { |
| 6069 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); | 6062 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); |
| 6070 const char* location = "v8::Object::SetInternalField()"; | 6063 const char* location = "v8::Object::SetInternalField()"; |
| 6071 if (!InternalFieldOK(obj, index, location)) return; | 6064 if (!InternalFieldOK(obj, index, location)) return; |
| 6072 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 6065 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 6073 i::Handle<i::JSObject>::cast(obj)->SetInternalField(index, *val); | 6066 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val); |
| 6074 } | 6067 } |
| 6075 | 6068 |
| 6076 | |
| 6077 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { | 6069 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { |
| 6078 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); | 6070 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); |
| 6079 const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; | 6071 const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; |
| 6080 if (!InternalFieldOK(obj, index, location)) return NULL; | 6072 if (!InternalFieldOK(obj, index, location)) return NULL; |
| 6081 return DecodeSmiToAligned( | 6073 return DecodeSmiToAligned( |
| 6082 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), location); | 6074 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index), location); |
| 6083 } | 6075 } |
| 6084 | 6076 |
| 6085 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { | 6077 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { |
| 6086 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); | 6078 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); |
| 6087 const char* location = "v8::Object::SetAlignedPointerInInternalField()"; | 6079 const char* location = "v8::Object::SetAlignedPointerInInternalField()"; |
| 6088 if (!InternalFieldOK(obj, index, location)) return; | 6080 if (!InternalFieldOK(obj, index, location)) return; |
| 6089 i::Handle<i::JSObject>::cast(obj) | 6081 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField( |
| 6090 ->SetInternalField(index, EncodeAlignedAsSmi(value, location)); | 6082 index, EncodeAlignedAsSmi(value, location)); |
| 6091 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); | 6083 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); |
| 6092 } | 6084 } |
| 6093 | 6085 |
| 6094 void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[], | 6086 void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[], |
| 6095 void* values[]) { | 6087 void* values[]) { |
| 6096 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); | 6088 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); |
| 6097 const char* location = "v8::Object::SetAlignedPointerInInternalFields()"; | 6089 const char* location = "v8::Object::SetAlignedPointerInInternalFields()"; |
| 6098 i::DisallowHeapAllocation no_gc; | 6090 i::DisallowHeapAllocation no_gc; |
| 6099 i::JSObject* object = i::JSObject::cast(*obj); | 6091 i::JSObject* object = i::JSObject::cast(*obj); |
| 6100 int nof_internal_fields = object->GetInternalFieldCount(); | 6092 int nof_embedder_fields = object->GetEmbedderFieldCount(); |
| 6101 for (int i = 0; i < argc; i++) { | 6093 for (int i = 0; i < argc; i++) { |
| 6102 int index = indices[i]; | 6094 int index = indices[i]; |
| 6103 if (!Utils::ApiCheck(index < nof_internal_fields, location, | 6095 if (!Utils::ApiCheck(index < nof_embedder_fields, location, |
| 6104 "Internal field out of bounds")) { | 6096 "Internal field out of bounds")) { |
| 6105 return; | 6097 return; |
| 6106 } | 6098 } |
| 6107 void* value = values[i]; | 6099 void* value = values[i]; |
| 6108 object->SetInternalField(index, EncodeAlignedAsSmi(value, location)); | 6100 object->SetEmbedderField(index, EncodeAlignedAsSmi(value, location)); |
| 6109 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); | 6101 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); |
| 6110 } | 6102 } |
| 6111 } | 6103 } |
| 6112 | 6104 |
| 6113 static void* ExternalValue(i::Object* obj) { | 6105 static void* ExternalValue(i::Object* obj) { |
| 6114 // Obscure semantics for undefined, but somehow checked in our unit tests... | 6106 // Obscure semantics for undefined, but somehow checked in our unit tests... |
| 6115 if (!obj->IsSmi() && | 6107 if (!obj->IsSmi() && |
| 6116 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) { | 6108 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) { |
| 6117 return NULL; | 6109 return NULL; |
| 6118 } | 6110 } |
| 6119 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); | 6111 i::Object* foreign = i::JSObject::cast(obj)->GetEmbedderField(0); |
| 6120 return i::Foreign::cast(foreign)->foreign_address(); | 6112 return i::Foreign::cast(foreign)->foreign_address(); |
| 6121 } | 6113 } |
| 6122 | 6114 |
| 6123 | 6115 |
| 6124 // --- E n v i r o n m e n t --- | 6116 // --- E n v i r o n m e n t --- |
| 6125 | 6117 |
| 6126 | 6118 |
| 6127 void v8::V8::InitializePlatform(Platform* platform) { | 6119 void v8::V8::InitializePlatform(Platform* platform) { |
| 6128 i::V8::InitializePlatform(platform); | 6120 i::V8::InitializePlatform(platform); |
| 6129 } | 6121 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6225 | 6217 |
| 6226 template <typename ObjectType> | 6218 template <typename ObjectType> |
| 6227 struct InvokeBootstrapper; | 6219 struct InvokeBootstrapper; |
| 6228 | 6220 |
| 6229 template <> | 6221 template <> |
| 6230 struct InvokeBootstrapper<i::Context> { | 6222 struct InvokeBootstrapper<i::Context> { |
| 6231 i::Handle<i::Context> Invoke( | 6223 i::Handle<i::Context> Invoke( |
| 6232 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, | 6224 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, |
| 6233 v8::Local<v8::ObjectTemplate> global_object_template, | 6225 v8::Local<v8::ObjectTemplate> global_object_template, |
| 6234 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, | 6226 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
| 6235 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { | 6227 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) { |
| 6236 return isolate->bootstrapper()->CreateEnvironment( | 6228 return isolate->bootstrapper()->CreateEnvironment( |
| 6237 maybe_global_proxy, global_object_template, extensions, | 6229 maybe_global_proxy, global_object_template, extensions, |
| 6238 context_snapshot_index, internal_fields_deserializer); | 6230 context_snapshot_index, embedder_fields_deserializer); |
| 6239 } | 6231 } |
| 6240 }; | 6232 }; |
| 6241 | 6233 |
| 6242 template <> | 6234 template <> |
| 6243 struct InvokeBootstrapper<i::JSGlobalProxy> { | 6235 struct InvokeBootstrapper<i::JSGlobalProxy> { |
| 6244 i::Handle<i::JSGlobalProxy> Invoke( | 6236 i::Handle<i::JSGlobalProxy> Invoke( |
| 6245 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, | 6237 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, |
| 6246 v8::Local<v8::ObjectTemplate> global_object_template, | 6238 v8::Local<v8::ObjectTemplate> global_object_template, |
| 6247 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, | 6239 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, |
| 6248 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { | 6240 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) { |
| 6249 USE(extensions); | 6241 USE(extensions); |
| 6250 USE(context_snapshot_index); | 6242 USE(context_snapshot_index); |
| 6251 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy, | 6243 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy, |
| 6252 global_object_template); | 6244 global_object_template); |
| 6253 } | 6245 } |
| 6254 }; | 6246 }; |
| 6255 | 6247 |
| 6256 template <typename ObjectType> | 6248 template <typename ObjectType> |
| 6257 static i::Handle<ObjectType> CreateEnvironment( | 6249 static i::Handle<ObjectType> CreateEnvironment( |
| 6258 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, | 6250 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, |
| 6259 v8::MaybeLocal<ObjectTemplate> maybe_global_template, | 6251 v8::MaybeLocal<ObjectTemplate> maybe_global_template, |
| 6260 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, | 6252 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, |
| 6261 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { | 6253 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) { |
| 6262 i::Handle<ObjectType> result; | 6254 i::Handle<ObjectType> result; |
| 6263 | 6255 |
| 6264 { | 6256 { |
| 6265 ENTER_V8_FOR_NEW_CONTEXT(isolate); | 6257 ENTER_V8_FOR_NEW_CONTEXT(isolate); |
| 6266 v8::Local<ObjectTemplate> proxy_template; | 6258 v8::Local<ObjectTemplate> proxy_template; |
| 6267 i::Handle<i::FunctionTemplateInfo> proxy_constructor; | 6259 i::Handle<i::FunctionTemplateInfo> proxy_constructor; |
| 6268 i::Handle<i::FunctionTemplateInfo> global_constructor; | 6260 i::Handle<i::FunctionTemplateInfo> global_constructor; |
| 6269 i::Handle<i::Object> named_interceptor( | 6261 i::Handle<i::Object> named_interceptor( |
| 6270 isolate->factory()->undefined_value()); | 6262 isolate->factory()->undefined_value()); |
| 6271 i::Handle<i::Object> indexed_interceptor( | 6263 i::Handle<i::Object> indexed_interceptor( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6324 | 6316 |
| 6325 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; | 6317 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; |
| 6326 if (!maybe_global_proxy.IsEmpty()) { | 6318 if (!maybe_global_proxy.IsEmpty()) { |
| 6327 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( | 6319 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( |
| 6328 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); | 6320 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); |
| 6329 } | 6321 } |
| 6330 // Create the environment. | 6322 // Create the environment. |
| 6331 InvokeBootstrapper<ObjectType> invoke; | 6323 InvokeBootstrapper<ObjectType> invoke; |
| 6332 result = | 6324 result = |
| 6333 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, | 6325 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, |
| 6334 context_snapshot_index, internal_fields_deserializer); | 6326 context_snapshot_index, embedder_fields_deserializer); |
| 6335 | 6327 |
| 6336 // Restore the access check info and interceptors on the global template. | 6328 // Restore the access check info and interceptors on the global template. |
| 6337 if (!maybe_global_template.IsEmpty()) { | 6329 if (!maybe_global_template.IsEmpty()) { |
| 6338 DCHECK(!global_constructor.is_null()); | 6330 DCHECK(!global_constructor.is_null()); |
| 6339 DCHECK(!proxy_constructor.is_null()); | 6331 DCHECK(!proxy_constructor.is_null()); |
| 6340 global_constructor->set_access_check_info( | 6332 global_constructor->set_access_check_info( |
| 6341 proxy_constructor->access_check_info()); | 6333 proxy_constructor->access_check_info()); |
| 6342 global_constructor->set_needs_access_check( | 6334 global_constructor->set_needs_access_check( |
| 6343 proxy_constructor->needs_access_check()); | 6335 proxy_constructor->needs_access_check()); |
| 6344 global_constructor->set_named_property_handler(*named_interceptor); | 6336 global_constructor->set_named_property_handler(*named_interceptor); |
| 6345 global_constructor->set_indexed_property_handler(*indexed_interceptor); | 6337 global_constructor->set_indexed_property_handler(*indexed_interceptor); |
| 6346 } | 6338 } |
| 6347 } | 6339 } |
| 6348 // Leave V8. | 6340 // Leave V8. |
| 6349 | 6341 |
| 6350 return result; | 6342 return result; |
| 6351 } | 6343 } |
| 6352 | 6344 |
| 6353 Local<Context> NewContext( | 6345 Local<Context> NewContext( |
| 6354 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, | 6346 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, |
| 6355 v8::MaybeLocal<ObjectTemplate> global_template, | 6347 v8::MaybeLocal<ObjectTemplate> global_template, |
| 6356 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index, | 6348 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index, |
| 6357 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { | 6349 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) { |
| 6358 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 6350 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 6359 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext"); | 6351 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext"); |
| 6360 LOG_API(isolate, Context, New); | 6352 LOG_API(isolate, Context, New); |
| 6361 i::HandleScope scope(isolate); | 6353 i::HandleScope scope(isolate); |
| 6362 ExtensionConfiguration no_extensions; | 6354 ExtensionConfiguration no_extensions; |
| 6363 if (extensions == NULL) extensions = &no_extensions; | 6355 if (extensions == NULL) extensions = &no_extensions; |
| 6364 i::Handle<i::Context> env = CreateEnvironment<i::Context>( | 6356 i::Handle<i::Context> env = CreateEnvironment<i::Context>( |
| 6365 isolate, extensions, global_template, global_object, | 6357 isolate, extensions, global_template, global_object, |
| 6366 context_snapshot_index, internal_fields_deserializer); | 6358 context_snapshot_index, embedder_fields_deserializer); |
| 6367 if (env.is_null()) { | 6359 if (env.is_null()) { |
| 6368 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); | 6360 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
| 6369 return Local<Context>(); | 6361 return Local<Context>(); |
| 6370 } | 6362 } |
| 6371 return Utils::ToLocal(scope.CloseAndEscape(env)); | 6363 return Utils::ToLocal(scope.CloseAndEscape(env)); |
| 6372 } | 6364 } |
| 6373 | 6365 |
| 6374 Local<Context> v8::Context::New(v8::Isolate* external_isolate, | 6366 Local<Context> v8::Context::New(v8::Isolate* external_isolate, |
| 6375 v8::ExtensionConfiguration* extensions, | 6367 v8::ExtensionConfiguration* extensions, |
| 6376 v8::MaybeLocal<ObjectTemplate> global_template, | 6368 v8::MaybeLocal<ObjectTemplate> global_template, |
| 6377 v8::MaybeLocal<Value> global_object) { | 6369 v8::MaybeLocal<Value> global_object) { |
| 6378 return NewContext(external_isolate, extensions, global_template, | 6370 return NewContext(external_isolate, extensions, global_template, |
| 6379 global_object, 0, DeserializeInternalFieldsCallback()); | 6371 global_object, 0, DeserializeInternalFieldsCallback()); |
| 6380 } | 6372 } |
| 6381 | 6373 |
| 6382 MaybeLocal<Context> v8::Context::FromSnapshot( | 6374 MaybeLocal<Context> v8::Context::FromSnapshot( |
| 6383 v8::Isolate* external_isolate, size_t context_snapshot_index, | 6375 v8::Isolate* external_isolate, size_t context_snapshot_index, |
| 6384 v8::DeserializeInternalFieldsCallback internal_fields_deserializer, | 6376 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer, |
| 6385 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) { | 6377 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) { |
| 6386 size_t index_including_default_context = context_snapshot_index + 1; | 6378 size_t index_including_default_context = context_snapshot_index + 1; |
| 6387 if (!i::Snapshot::HasContextSnapshot( | 6379 if (!i::Snapshot::HasContextSnapshot( |
| 6388 reinterpret_cast<i::Isolate*>(external_isolate), | 6380 reinterpret_cast<i::Isolate*>(external_isolate), |
| 6389 index_including_default_context)) { | 6381 index_including_default_context)) { |
| 6390 return MaybeLocal<Context>(); | 6382 return MaybeLocal<Context>(); |
| 6391 } | 6383 } |
| 6392 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(), | 6384 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(), |
| 6393 global_object, index_including_default_context, | 6385 global_object, index_including_default_context, |
| 6394 internal_fields_deserializer); | 6386 embedder_fields_deserializer); |
| 6395 } | 6387 } |
| 6396 | 6388 |
| 6397 MaybeLocal<Object> v8::Context::NewRemoteContext( | 6389 MaybeLocal<Object> v8::Context::NewRemoteContext( |
| 6398 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template, | 6390 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template, |
| 6399 v8::MaybeLocal<v8::Value> global_object) { | 6391 v8::MaybeLocal<v8::Value> global_object) { |
| 6400 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 6392 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
| 6401 LOG_API(isolate, Context, NewRemoteContext); | 6393 LOG_API(isolate, Context, NewRemoteContext); |
| 6402 i::HandleScope scope(isolate); | 6394 i::HandleScope scope(isolate); |
| 6403 i::Handle<i::FunctionTemplateInfo> global_constructor = | 6395 i::Handle<i::FunctionTemplateInfo> global_constructor = |
| 6404 EnsureConstructor(isolate, *global_template); | 6396 EnsureConstructor(isolate, *global_template); |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7505 has_pending_exception = | 7497 has_pending_exception = |
| 7506 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); | 7498 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); |
| 7507 RETURN_ON_FAILED_EXECUTION(Proxy); | 7499 RETURN_ON_FAILED_EXECUTION(Proxy); |
| 7508 RETURN_ESCAPED(result); | 7500 RETURN_ESCAPED(result); |
| 7509 } | 7501 } |
| 7510 | 7502 |
| 7511 Local<String> WasmCompiledModule::GetWasmWireBytes() { | 7503 Local<String> WasmCompiledModule::GetWasmWireBytes() { |
| 7512 i::Handle<i::JSObject> obj = | 7504 i::Handle<i::JSObject> obj = |
| 7513 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7505 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7514 i::Handle<i::WasmCompiledModule> compiled_part = | 7506 i::Handle<i::WasmCompiledModule> compiled_part = |
| 7515 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7507 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); |
| 7516 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); | 7508 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); |
| 7517 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); | 7509 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
| 7518 } | 7510 } |
| 7519 | 7511 |
| 7520 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7512 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
| 7521 i::Handle<i::JSObject> obj = | 7513 i::Handle<i::JSObject> obj = |
| 7522 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7514 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7523 i::Handle<i::WasmCompiledModule> compiled_part = | 7515 i::Handle<i::WasmCompiledModule> compiled_part = |
| 7524 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7516 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0))); |
| 7525 | 7517 |
| 7526 std::unique_ptr<i::ScriptData> script_data = | 7518 std::unique_ptr<i::ScriptData> script_data = |
| 7527 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7519 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
| 7528 compiled_part); | 7520 compiled_part); |
| 7529 script_data->ReleaseDataOwnership(); | 7521 script_data->ReleaseDataOwnership(); |
| 7530 | 7522 |
| 7531 size_t size = static_cast<size_t>(script_data->length()); | 7523 size_t size = static_cast<size_t>(script_data->length()); |
| 7532 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7524 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
| 7533 } | 7525 } |
| 7534 | 7526 |
| (...skipping 2718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10253 Address callback_address = | 10245 Address callback_address = |
| 10254 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10246 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10255 VMState<EXTERNAL> state(isolate); | 10247 VMState<EXTERNAL> state(isolate); |
| 10256 ExternalCallbackScope call_scope(isolate, callback_address); | 10248 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10257 callback(info); | 10249 callback(info); |
| 10258 } | 10250 } |
| 10259 | 10251 |
| 10260 | 10252 |
| 10261 } // namespace internal | 10253 } // namespace internal |
| 10262 } // namespace v8 | 10254 } // namespace v8 |
| OLD | NEW |