Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/api.cc

Issue 2741683004: [rename] Rename internal field to embedder field. (Closed)
Patch Set: Remove API changes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/api-natives.cc » ('j') | src/objects.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 i::ExternalReferenceTable::instance(isolate)->ResetCount(); 629 i::ExternalReferenceTable::instance(isolate)->ResetCount();
630 #endif // DEBUG 630 #endif // DEBUG
631 631
632 i::StartupSerializer startup_serializer(isolate, function_code_handling); 632 i::StartupSerializer startup_serializer(isolate, function_code_handling);
633 startup_serializer.SerializeStrongReferences(); 633 startup_serializer.SerializeStrongReferences();
634 634
635 // Serialize each context with a new partial serializer. 635 // Serialize each context with a new partial serializer.
636 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1); 636 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1);
637 637
638 { 638 {
639 // The default snapshot does not support internal fields. 639 // The default snapshot does not support embedder fields.
640 i::PartialSerializer partial_serializer( 640 i::PartialSerializer partial_serializer(
641 isolate, &startup_serializer, v8::SerializeInternalFieldsCallback()); 641 isolate, &startup_serializer, v8::SerializeInternalFieldsCallback());
642 partial_serializer.Serialize(&default_context, false); 642 partial_serializer.Serialize(&default_context, false);
643 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); 643 context_snapshots.Add(new i::SnapshotData(&partial_serializer));
644 } 644 }
645 645
646 for (int i = 0; i < num_additional_contexts; i++) { 646 for (int i = 0; i < num_additional_contexts; i++) {
647 i::PartialSerializer partial_serializer( 647 i::PartialSerializer partial_serializer(
648 isolate, &startup_serializer, data->internal_fields_serializers_[i]); 648 isolate, &startup_serializer, data->embedder_fields_serializers_[i]);
649 partial_serializer.Serialize(&contexts[i], true); 649 partial_serializer.Serialize(&contexts[i], true);
650 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); 650 context_snapshots.Add(new i::SnapshotData(&partial_serializer));
651 } 651 }
652 652
653 startup_serializer.SerializeWeakReferencesAndDeferred(); 653 startup_serializer.SerializeWeakReferencesAndDeferred();
654 654
655 #ifdef DEBUG 655 #ifdef DEBUG
656 if (i::FLAG_external_reference_stats) { 656 if (i::FLAG_external_reference_stats) {
657 i::ExternalReferenceTable::instance(isolate)->PrintCount(); 657 i::ExternalReferenceTable::instance(isolate)->PrintCount();
658 } 658 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 #endif // VERIFY_HEAP 898 #endif // VERIFY_HEAP
899 return result.location(); 899 return result.location();
900 } 900 }
901 901
902 void V8::RegisterExternallyReferencedObject(i::Object** object, 902 void V8::RegisterExternallyReferencedObject(i::Object** object,
903 i::Isolate* isolate) { 903 i::Isolate* isolate) {
904 isolate->heap()->RegisterExternallyReferencedObject(object); 904 isolate->heap()->RegisterExternallyReferencedObject(object);
905 } 905 }
906 906
907 void V8::MakeWeak(i::Object** location, void* parameter, 907 void V8::MakeWeak(i::Object** location, void* parameter,
908 int internal_field_index1, int internal_field_index2, 908 int embedder_field_index1, int embedder_field_index2,
909 WeakCallbackInfo<void>::Callback weak_callback) { 909 WeakCallbackInfo<void>::Callback weak_callback) {
910 WeakCallbackType type = WeakCallbackType::kParameter; 910 WeakCallbackType type = WeakCallbackType::kParameter;
911 if (internal_field_index1 == 0) { 911 if (embedder_field_index1 == 0) {
912 if (internal_field_index2 == 1) { 912 if (embedder_field_index2 == 1) {
913 type = WeakCallbackType::kInternalFields; 913 type = WeakCallbackType::kInternalFields;
914 } else { 914 } else {
915 DCHECK_EQ(internal_field_index2, -1); 915 DCHECK_EQ(embedder_field_index2, -1);
916 type = WeakCallbackType::kInternalFields; 916 type = WeakCallbackType::kInternalFields;
917 } 917 }
918 } else { 918 } else {
919 DCHECK_EQ(internal_field_index1, -1); 919 DCHECK_EQ(embedder_field_index1, -1);
920 DCHECK_EQ(internal_field_index2, -1); 920 DCHECK_EQ(embedder_field_index2, -1);
921 } 921 }
922 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); 922 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
923 } 923 }
924 924
925 void V8::MakeWeak(i::Object** location, void* parameter, 925 void V8::MakeWeak(i::Object** location, void* parameter,
926 WeakCallbackInfo<void>::Callback weak_callback, 926 WeakCallbackInfo<void>::Callback weak_callback,
927 WeakCallbackType type) { 927 WeakCallbackType type) {
928 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); 928 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
929 } 929 }
930 930
(...skipping 25 matching lines...) Expand all
956 956
957 void V8::FromJustIsNothing() { 957 void V8::FromJustIsNothing() {
958 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing."); 958 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing.");
959 } 959 }
960 960
961 961
962 void V8::ToLocalEmpty() { 962 void V8::ToLocalEmpty() {
963 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal."); 963 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal.");
964 } 964 }
965 965
966
967 void V8::InternalFieldOutOfBounds(int index) { 966 void V8::InternalFieldOutOfBounds(int index) {
968 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback, 967 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback,
969 "WeakCallbackInfo::GetInternalField", 968 "WeakCallbackInfo::GetInternalField",
970 "Internal field out of bounds."); 969 "Internal field out of bounds.");
971 } 970 }
972 971
973 972
974 // --- H a n d l e s --- 973 // --- H a n d l e s ---
975 974
976 975
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 i::Handle<i::CallHandlerInfo> obj = 1845 i::Handle<i::CallHandlerInfo> obj =
1847 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 1846 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
1848 SET_FIELD_WRAPPED(obj, set_callback, callback); 1847 SET_FIELD_WRAPPED(obj, set_callback, callback);
1849 if (data.IsEmpty()) { 1848 if (data.IsEmpty()) {
1850 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1849 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1851 } 1850 }
1852 obj->set_data(*Utils::OpenHandle(*data)); 1851 obj->set_data(*Utils::OpenHandle(*data));
1853 cons->set_instance_call_handler(*obj); 1852 cons->set_instance_call_handler(*obj);
1854 } 1853 }
1855 1854
1856
1857 int ObjectTemplate::InternalFieldCount() { 1855 int ObjectTemplate::InternalFieldCount() {
1858 return Utils::OpenHandle(this)->internal_field_count(); 1856 return Utils::OpenHandle(this)->embedder_field_count();
1859 } 1857 }
1860 1858
1861
1862 void ObjectTemplate::SetInternalFieldCount(int value) { 1859 void ObjectTemplate::SetInternalFieldCount(int value) {
1863 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 1860 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1864 if (!Utils::ApiCheck(i::Smi::IsValid(value), 1861 if (!Utils::ApiCheck(i::Smi::IsValid(value),
1865 "v8::ObjectTemplate::SetInternalFieldCount()", 1862 "v8::ObjectTemplate::SetInternalFieldCount()",
1866 "Invalid internal field count")) { 1863 "Invalid embedder field count")) {
1867 return; 1864 return;
1868 } 1865 }
1869 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); 1866 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1870 if (value > 0) { 1867 if (value > 0) {
1871 // The internal field count is set by the constructor function's 1868 // The embedder field count is set by the constructor function's
1872 // construct code, so we ensure that there is a constructor 1869 // construct code, so we ensure that there is a constructor
1873 // function to do the setting. 1870 // function to do the setting.
1874 EnsureConstructor(isolate, this); 1871 EnsureConstructor(isolate, this);
1875 } 1872 }
1876 Utils::OpenHandle(this)->set_internal_field_count(value); 1873 Utils::OpenHandle(this)->set_embedder_field_count(value);
1877 } 1874 }
1878 1875
1879 bool ObjectTemplate::IsImmutableProto() { 1876 bool ObjectTemplate::IsImmutableProto() {
1880 return Utils::OpenHandle(this)->immutable_proto(); 1877 return Utils::OpenHandle(this)->immutable_proto();
1881 } 1878 }
1882 1879
1883 void ObjectTemplate::SetImmutableProto() { 1880 void ObjectTemplate::SetImmutableProto() {
1884 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 1881 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1885 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); 1882 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1886 Utils::OpenHandle(this)->set_immutable_proto(true); 1883 Utils::OpenHandle(this)->set_immutable_proto(true);
(...skipping 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after
6022 6019
6023 uint32_t Uint32::Value() const { 6020 uint32_t Uint32::Value() const {
6024 i::Handle<i::Object> obj = Utils::OpenHandle(this); 6021 i::Handle<i::Object> obj = Utils::OpenHandle(this);
6025 if (obj->IsSmi()) { 6022 if (obj->IsSmi()) {
6026 return i::Smi::cast(*obj)->value(); 6023 return i::Smi::cast(*obj)->value();
6027 } else { 6024 } else {
6028 return static_cast<uint32_t>(obj->Number()); 6025 return static_cast<uint32_t>(obj->Number());
6029 } 6026 }
6030 } 6027 }
6031 6028
6032
6033 int v8::Object::InternalFieldCount() { 6029 int v8::Object::InternalFieldCount() {
6034 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); 6030 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
6035 if (!self->IsJSObject()) return 0; 6031 if (!self->IsJSObject()) return 0;
6036 return i::Handle<i::JSObject>::cast(self)->GetInternalFieldCount(); 6032 return i::Handle<i::JSObject>::cast(self)->GetEmbedderFieldCount();
6037 } 6033 }
6038 6034
6039
6040 static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index, 6035 static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index,
6041 const char* location) { 6036 const char* location) {
6042 return Utils::ApiCheck( 6037 return Utils::ApiCheck(
6043 obj->IsJSObject() && 6038 obj->IsJSObject() &&
6044 (index < i::Handle<i::JSObject>::cast(obj)->GetInternalFieldCount()), 6039 (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()),
6045 location, "Internal field out of bounds"); 6040 location, "Internal field out of bounds");
6046 } 6041 }
6047 6042
6048
6049 Local<Value> v8::Object::SlowGetInternalField(int index) { 6043 Local<Value> v8::Object::SlowGetInternalField(int index) {
6050 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6044 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6051 const char* location = "v8::Object::GetInternalField()"; 6045 const char* location = "v8::Object::GetInternalField()";
6052 if (!InternalFieldOK(obj, index, location)) return Local<Value>(); 6046 if (!InternalFieldOK(obj, index, location)) return Local<Value>();
6053 i::Handle<i::Object> value( 6047 i::Handle<i::Object> value(
6054 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), 6048 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index),
6055 obj->GetIsolate()); 6049 obj->GetIsolate());
6056 return Utils::ToLocal(value); 6050 return Utils::ToLocal(value);
6057 } 6051 }
6058 6052
6059
6060 void v8::Object::SetInternalField(int index, v8::Local<Value> value) { 6053 void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
6061 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6054 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6062 const char* location = "v8::Object::SetInternalField()"; 6055 const char* location = "v8::Object::SetInternalField()";
6063 if (!InternalFieldOK(obj, index, location)) return; 6056 if (!InternalFieldOK(obj, index, location)) return;
6064 i::Handle<i::Object> val = Utils::OpenHandle(*value); 6057 i::Handle<i::Object> val = Utils::OpenHandle(*value);
6065 i::Handle<i::JSObject>::cast(obj)->SetInternalField(index, *val); 6058 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
6066 } 6059 }
6067 6060
6068
6069 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) { 6061 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
6070 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6062 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6071 const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; 6063 const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
6072 if (!InternalFieldOK(obj, index, location)) return NULL; 6064 if (!InternalFieldOK(obj, index, location)) return NULL;
6073 return DecodeSmiToAligned( 6065 return DecodeSmiToAligned(
6074 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), location); 6066 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index), location);
6075 } 6067 }
6076 6068
6077 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { 6069 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
6078 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6070 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6079 const char* location = "v8::Object::SetAlignedPointerInInternalField()"; 6071 const char* location = "v8::Object::SetAlignedPointerInInternalField()";
6080 if (!InternalFieldOK(obj, index, location)) return; 6072 if (!InternalFieldOK(obj, index, location)) return;
6081 i::Handle<i::JSObject>::cast(obj) 6073 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(
6082 ->SetInternalField(index, EncodeAlignedAsSmi(value, location)); 6074 index, EncodeAlignedAsSmi(value, location));
6083 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); 6075 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
6084 } 6076 }
6085 6077
6086 void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[], 6078 void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[],
6087 void* values[]) { 6079 void* values[]) {
6088 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6080 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6089 const char* location = "v8::Object::SetAlignedPointerInInternalFields()"; 6081 const char* location = "v8::Object::SetAlignedPointerInInternalFields()";
6090 i::DisallowHeapAllocation no_gc; 6082 i::DisallowHeapAllocation no_gc;
6091 i::JSObject* object = i::JSObject::cast(*obj); 6083 i::JSObject* object = i::JSObject::cast(*obj);
6092 int nof_internal_fields = object->GetInternalFieldCount(); 6084 int nof_embedder_fields = object->GetEmbedderFieldCount();
6093 for (int i = 0; i < argc; i++) { 6085 for (int i = 0; i < argc; i++) {
6094 int index = indices[i]; 6086 int index = indices[i];
6095 if (!Utils::ApiCheck(index < nof_internal_fields, location, 6087 if (!Utils::ApiCheck(index < nof_embedder_fields, location,
6096 "Internal field out of bounds")) { 6088 "Internal field out of bounds")) {
6097 return; 6089 return;
6098 } 6090 }
6099 void* value = values[i]; 6091 void* value = values[i];
6100 object->SetInternalField(index, EncodeAlignedAsSmi(value, location)); 6092 object->SetEmbedderField(index, EncodeAlignedAsSmi(value, location));
6101 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); 6093 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
6102 } 6094 }
6103 } 6095 }
6104 6096
6105 static void* ExternalValue(i::Object* obj) { 6097 static void* ExternalValue(i::Object* obj) {
6106 // Obscure semantics for undefined, but somehow checked in our unit tests... 6098 // Obscure semantics for undefined, but somehow checked in our unit tests...
6107 if (!obj->IsSmi() && 6099 if (!obj->IsSmi() &&
6108 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) { 6100 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) {
6109 return NULL; 6101 return NULL;
6110 } 6102 }
6111 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); 6103 i::Object* foreign = i::JSObject::cast(obj)->GetEmbedderField(0);
6112 return i::Foreign::cast(foreign)->foreign_address(); 6104 return i::Foreign::cast(foreign)->foreign_address();
6113 } 6105 }
6114 6106
6115 6107
6116 // --- E n v i r o n m e n t --- 6108 // --- E n v i r o n m e n t ---
6117 6109
6118 6110
6119 void v8::V8::InitializePlatform(Platform* platform) { 6111 void v8::V8::InitializePlatform(Platform* platform) {
6120 i::V8::InitializePlatform(platform); 6112 i::V8::InitializePlatform(platform);
6121 } 6113 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
6217 6209
6218 template <typename ObjectType> 6210 template <typename ObjectType>
6219 struct InvokeBootstrapper; 6211 struct InvokeBootstrapper;
6220 6212
6221 template <> 6213 template <>
6222 struct InvokeBootstrapper<i::Context> { 6214 struct InvokeBootstrapper<i::Context> {
6223 i::Handle<i::Context> Invoke( 6215 i::Handle<i::Context> Invoke(
6224 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, 6216 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
6225 v8::Local<v8::ObjectTemplate> global_object_template, 6217 v8::Local<v8::ObjectTemplate> global_object_template,
6226 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, 6218 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
6227 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6219 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6228 return isolate->bootstrapper()->CreateEnvironment( 6220 return isolate->bootstrapper()->CreateEnvironment(
6229 maybe_global_proxy, global_object_template, extensions, 6221 maybe_global_proxy, global_object_template, extensions,
6230 context_snapshot_index, internal_fields_deserializer); 6222 context_snapshot_index, embedder_fields_deserializer);
6231 } 6223 }
6232 }; 6224 };
6233 6225
6234 template <> 6226 template <>
6235 struct InvokeBootstrapper<i::JSGlobalProxy> { 6227 struct InvokeBootstrapper<i::JSGlobalProxy> {
6236 i::Handle<i::JSGlobalProxy> Invoke( 6228 i::Handle<i::JSGlobalProxy> Invoke(
6237 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, 6229 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
6238 v8::Local<v8::ObjectTemplate> global_object_template, 6230 v8::Local<v8::ObjectTemplate> global_object_template,
6239 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, 6231 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
6240 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6232 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6241 USE(extensions); 6233 USE(extensions);
6242 USE(context_snapshot_index); 6234 USE(context_snapshot_index);
6243 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy, 6235 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
6244 global_object_template); 6236 global_object_template);
6245 } 6237 }
6246 }; 6238 };
6247 6239
6248 template <typename ObjectType> 6240 template <typename ObjectType>
6249 static i::Handle<ObjectType> CreateEnvironment( 6241 static i::Handle<ObjectType> CreateEnvironment(
6250 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, 6242 i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
6251 v8::MaybeLocal<ObjectTemplate> maybe_global_template, 6243 v8::MaybeLocal<ObjectTemplate> maybe_global_template,
6252 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, 6244 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index,
6253 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6245 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6254 i::Handle<ObjectType> result; 6246 i::Handle<ObjectType> result;
6255 6247
6256 { 6248 {
6257 ENTER_V8_FOR_NEW_CONTEXT(isolate); 6249 ENTER_V8_FOR_NEW_CONTEXT(isolate);
6258 v8::Local<ObjectTemplate> proxy_template; 6250 v8::Local<ObjectTemplate> proxy_template;
6259 i::Handle<i::FunctionTemplateInfo> proxy_constructor; 6251 i::Handle<i::FunctionTemplateInfo> proxy_constructor;
6260 i::Handle<i::FunctionTemplateInfo> global_constructor; 6252 i::Handle<i::FunctionTemplateInfo> global_constructor;
6261 i::Handle<i::Object> named_interceptor( 6253 i::Handle<i::Object> named_interceptor(
6262 isolate->factory()->undefined_value()); 6254 isolate->factory()->undefined_value());
6263 i::Handle<i::Object> indexed_interceptor( 6255 i::Handle<i::Object> indexed_interceptor(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
6316 6308
6317 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; 6309 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
6318 if (!maybe_global_proxy.IsEmpty()) { 6310 if (!maybe_global_proxy.IsEmpty()) {
6319 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( 6311 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(
6320 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); 6312 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked()));
6321 } 6313 }
6322 // Create the environment. 6314 // Create the environment.
6323 InvokeBootstrapper<ObjectType> invoke; 6315 InvokeBootstrapper<ObjectType> invoke;
6324 result = 6316 result =
6325 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, 6317 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
6326 context_snapshot_index, internal_fields_deserializer); 6318 context_snapshot_index, embedder_fields_deserializer);
6327 6319
6328 // Restore the access check info and interceptors on the global template. 6320 // Restore the access check info and interceptors on the global template.
6329 if (!maybe_global_template.IsEmpty()) { 6321 if (!maybe_global_template.IsEmpty()) {
6330 DCHECK(!global_constructor.is_null()); 6322 DCHECK(!global_constructor.is_null());
6331 DCHECK(!proxy_constructor.is_null()); 6323 DCHECK(!proxy_constructor.is_null());
6332 global_constructor->set_access_check_info( 6324 global_constructor->set_access_check_info(
6333 proxy_constructor->access_check_info()); 6325 proxy_constructor->access_check_info());
6334 global_constructor->set_needs_access_check( 6326 global_constructor->set_needs_access_check(
6335 proxy_constructor->needs_access_check()); 6327 proxy_constructor->needs_access_check());
6336 global_constructor->set_named_property_handler(*named_interceptor); 6328 global_constructor->set_named_property_handler(*named_interceptor);
6337 global_constructor->set_indexed_property_handler(*indexed_interceptor); 6329 global_constructor->set_indexed_property_handler(*indexed_interceptor);
6338 } 6330 }
6339 } 6331 }
6340 // Leave V8. 6332 // Leave V8.
6341 6333
6342 return result; 6334 return result;
6343 } 6335 }
6344 6336
6345 Local<Context> NewContext( 6337 Local<Context> NewContext(
6346 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, 6338 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
6347 v8::MaybeLocal<ObjectTemplate> global_template, 6339 v8::MaybeLocal<ObjectTemplate> global_template,
6348 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index, 6340 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index,
6349 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6341 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6350 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 6342 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
6351 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext"); 6343 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
6352 LOG_API(isolate, Context, New); 6344 LOG_API(isolate, Context, New);
6353 i::HandleScope scope(isolate); 6345 i::HandleScope scope(isolate);
6354 ExtensionConfiguration no_extensions; 6346 ExtensionConfiguration no_extensions;
6355 if (extensions == NULL) extensions = &no_extensions; 6347 if (extensions == NULL) extensions = &no_extensions;
6356 i::Handle<i::Context> env = CreateEnvironment<i::Context>( 6348 i::Handle<i::Context> env = CreateEnvironment<i::Context>(
6357 isolate, extensions, global_template, global_object, 6349 isolate, extensions, global_template, global_object,
6358 context_snapshot_index, internal_fields_deserializer); 6350 context_snapshot_index, embedder_fields_deserializer);
6359 if (env.is_null()) { 6351 if (env.is_null()) {
6360 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); 6352 if (isolate->has_pending_exception()) isolate->clear_pending_exception();
6361 return Local<Context>(); 6353 return Local<Context>();
6362 } 6354 }
6363 return Utils::ToLocal(scope.CloseAndEscape(env)); 6355 return Utils::ToLocal(scope.CloseAndEscape(env));
6364 } 6356 }
6365 6357
6366 Local<Context> v8::Context::New(v8::Isolate* external_isolate, 6358 Local<Context> v8::Context::New(v8::Isolate* external_isolate,
6367 v8::ExtensionConfiguration* extensions, 6359 v8::ExtensionConfiguration* extensions,
6368 v8::MaybeLocal<ObjectTemplate> global_template, 6360 v8::MaybeLocal<ObjectTemplate> global_template,
6369 v8::MaybeLocal<Value> global_object) { 6361 v8::MaybeLocal<Value> global_object) {
6370 return NewContext(external_isolate, extensions, global_template, 6362 return NewContext(external_isolate, extensions, global_template,
6371 global_object, 0, DeserializeInternalFieldsCallback()); 6363 global_object, 0, DeserializeInternalFieldsCallback());
6372 } 6364 }
6373 6365
6374 MaybeLocal<Context> v8::Context::FromSnapshot( 6366 MaybeLocal<Context> v8::Context::FromSnapshot(
6375 v8::Isolate* external_isolate, size_t context_snapshot_index, 6367 v8::Isolate* external_isolate, size_t context_snapshot_index,
6376 v8::DeserializeInternalFieldsCallback internal_fields_deserializer, 6368 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
6377 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) { 6369 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) {
6378 size_t index_including_default_context = context_snapshot_index + 1; 6370 size_t index_including_default_context = context_snapshot_index + 1;
6379 if (!i::Snapshot::HasContextSnapshot( 6371 if (!i::Snapshot::HasContextSnapshot(
6380 reinterpret_cast<i::Isolate*>(external_isolate), 6372 reinterpret_cast<i::Isolate*>(external_isolate),
6381 index_including_default_context)) { 6373 index_including_default_context)) {
6382 return MaybeLocal<Context>(); 6374 return MaybeLocal<Context>();
6383 } 6375 }
6384 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(), 6376 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
6385 global_object, index_including_default_context, 6377 global_object, index_including_default_context,
6386 internal_fields_deserializer); 6378 embedder_fields_deserializer);
6387 } 6379 }
6388 6380
6389 MaybeLocal<Object> v8::Context::NewRemoteContext( 6381 MaybeLocal<Object> v8::Context::NewRemoteContext(
6390 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template, 6382 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template,
6391 v8::MaybeLocal<v8::Value> global_object) { 6383 v8::MaybeLocal<v8::Value> global_object) {
6392 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 6384 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
6393 LOG_API(isolate, Context, NewRemoteContext); 6385 LOG_API(isolate, Context, NewRemoteContext);
6394 i::HandleScope scope(isolate); 6386 i::HandleScope scope(isolate);
6395 i::Handle<i::FunctionTemplateInfo> global_constructor = 6387 i::Handle<i::FunctionTemplateInfo> global_constructor =
6396 EnsureConstructor(isolate, *global_template); 6388 EnsureConstructor(isolate, *global_template);
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
7497 has_pending_exception = 7489 has_pending_exception =
7498 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); 7490 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
7499 RETURN_ON_FAILED_EXECUTION(Proxy); 7491 RETURN_ON_FAILED_EXECUTION(Proxy);
7500 RETURN_ESCAPED(result); 7492 RETURN_ESCAPED(result);
7501 } 7493 }
7502 7494
7503 Local<String> WasmCompiledModule::GetWasmWireBytes() { 7495 Local<String> WasmCompiledModule::GetWasmWireBytes() {
7504 i::Handle<i::JSObject> obj = 7496 i::Handle<i::JSObject> obj =
7505 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7497 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7506 i::Handle<i::WasmCompiledModule> compiled_part = 7498 i::Handle<i::WasmCompiledModule> compiled_part =
7507 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7499 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7508 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); 7500 i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
7509 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); 7501 return Local<String>::Cast(Utils::ToLocal(wire_bytes));
7510 } 7502 }
7511 7503
7512 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7504 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7513 i::Handle<i::JSObject> obj = 7505 i::Handle<i::JSObject> obj =
7514 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7506 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7515 i::Handle<i::WasmCompiledModule> compiled_part = 7507 i::Handle<i::WasmCompiledModule> compiled_part =
7516 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7508 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7517 7509
7518 std::unique_ptr<i::ScriptData> script_data = 7510 std::unique_ptr<i::ScriptData> script_data =
7519 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7511 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7520 compiled_part); 7512 compiled_part);
7521 script_data->ReleaseDataOwnership(); 7513 script_data->ReleaseDataOwnership();
7522 7514
7523 size_t size = static_cast<size_t>(script_data->length()); 7515 size_t size = static_cast<size_t>(script_data->length());
7524 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; 7516 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
7525 } 7517 }
7526 7518
(...skipping 2718 matching lines...) Expand 10 before | Expand all | Expand 10 after
10245 Address callback_address = 10237 Address callback_address =
10246 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10238 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10247 VMState<EXTERNAL> state(isolate); 10239 VMState<EXTERNAL> state(isolate);
10248 ExternalCallbackScope call_scope(isolate, callback_address); 10240 ExternalCallbackScope call_scope(isolate, callback_address);
10249 callback(info); 10241 callback(info);
10250 } 10242 }
10251 10243
10252 10244
10253 } // namespace internal 10245 } // namespace internal
10254 } // namespace v8 10246 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/api-natives.cc » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698