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

Side by Side Diff: src/api.cc

Issue 2741683004: [rename] Rename internal field to embedder field. (Closed)
Patch Set: DEPRECATE_SOON(GetInternalField) 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
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 489
490 static SnapshotCreatorData* cast(void* data) { 490 static SnapshotCreatorData* cast(void* data) {
491 return reinterpret_cast<SnapshotCreatorData*>(data); 491 return reinterpret_cast<SnapshotCreatorData*>(data);
492 } 492 }
493 493
494 ArrayBufferAllocator allocator_; 494 ArrayBufferAllocator allocator_;
495 Isolate* isolate_; 495 Isolate* isolate_;
496 Persistent<Context> default_context_; 496 Persistent<Context> default_context_;
497 PersistentValueVector<Context> contexts_; 497 PersistentValueVector<Context> contexts_;
498 PersistentValueVector<Template> templates_; 498 PersistentValueVector<Template> templates_;
499 std::vector<SerializeInternalFieldsCallback> internal_fields_serializers_; 499 std::vector<SerializeEmbedderFieldsCallback> embedder_fields_serializers_;
500 bool created_; 500 bool created_;
501 }; 501 };
502 502
503 } // namespace 503 } // namespace
504 504
505 SnapshotCreator::SnapshotCreator(intptr_t* external_references, 505 SnapshotCreator::SnapshotCreator(intptr_t* external_references,
506 StartupData* existing_snapshot) { 506 StartupData* existing_snapshot) {
507 i::Isolate* internal_isolate = new i::Isolate(true); 507 i::Isolate* internal_isolate = new i::Isolate(true);
508 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); 508 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
509 SnapshotCreatorData* data = new SnapshotCreatorData(isolate); 509 SnapshotCreatorData* data = new SnapshotCreatorData(isolate);
(...skipping 30 matching lines...) Expand all
540 DCHECK(!context.IsEmpty()); 540 DCHECK(!context.IsEmpty());
541 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); 541 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
542 DCHECK(!data->created_); 542 DCHECK(!data->created_);
543 DCHECK(data->default_context_.IsEmpty()); 543 DCHECK(data->default_context_.IsEmpty());
544 Isolate* isolate = data->isolate_; 544 Isolate* isolate = data->isolate_;
545 CHECK_EQ(isolate, context->GetIsolate()); 545 CHECK_EQ(isolate, context->GetIsolate());
546 data->default_context_.Reset(isolate, context); 546 data->default_context_.Reset(isolate, context);
547 } 547 }
548 548
549 size_t SnapshotCreator::AddContext(Local<Context> context, 549 size_t SnapshotCreator::AddContext(Local<Context> context,
550 SerializeInternalFieldsCallback callback) { 550 SerializeEmbedderFieldsCallback callback) {
551 DCHECK(!context.IsEmpty()); 551 DCHECK(!context.IsEmpty());
552 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); 552 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
553 DCHECK(!data->created_); 553 DCHECK(!data->created_);
554 Isolate* isolate = data->isolate_; 554 Isolate* isolate = data->isolate_;
555 CHECK_EQ(isolate, context->GetIsolate()); 555 CHECK_EQ(isolate, context->GetIsolate());
556 size_t index = static_cast<int>(data->contexts_.Size()); 556 size_t index = static_cast<int>(data->contexts_.Size());
557 data->contexts_.Append(context); 557 data->contexts_.Append(context);
558 data->internal_fields_serializers_.push_back(callback); 558 data->embedder_fields_serializers_.push_back(callback);
559 return index; 559 return index;
560 } 560 }
561 561
562 size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) { 562 size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
563 DCHECK(!template_obj.IsEmpty()); 563 DCHECK(!template_obj.IsEmpty());
564 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); 564 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
565 DCHECK(!data->created_); 565 DCHECK(!data->created_);
566 DCHECK_EQ(reinterpret_cast<i::Isolate*>(data->isolate_), 566 DCHECK_EQ(reinterpret_cast<i::Isolate*>(data->isolate_),
567 Utils::OpenHandle(*template_obj)->GetIsolate()); 567 Utils::OpenHandle(*template_obj)->GetIsolate());
568 size_t index = static_cast<int>(data->templates_.Size()); 568 size_t index = static_cast<int>(data->templates_.Size());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 i::ExternalReferenceTable::instance(isolate)->ResetCount(); 630 i::ExternalReferenceTable::instance(isolate)->ResetCount();
631 #endif // DEBUG 631 #endif // DEBUG
632 632
633 i::StartupSerializer startup_serializer(isolate, function_code_handling); 633 i::StartupSerializer startup_serializer(isolate, function_code_handling);
634 startup_serializer.SerializeStrongReferences(); 634 startup_serializer.SerializeStrongReferences();
635 635
636 // Serialize each context with a new partial serializer. 636 // Serialize each context with a new partial serializer.
637 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1); 637 i::List<i::SnapshotData*> context_snapshots(num_additional_contexts + 1);
638 638
639 { 639 {
640 // The default snapshot does not support internal fields. 640 // The default snapshot does not support embedder fields.
641 i::PartialSerializer partial_serializer( 641 i::PartialSerializer partial_serializer(
642 isolate, &startup_serializer, v8::SerializeInternalFieldsCallback()); 642 isolate, &startup_serializer, v8::SerializeEmbedderFieldsCallback());
643 partial_serializer.Serialize(&default_context, false); 643 partial_serializer.Serialize(&default_context, false);
644 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); 644 context_snapshots.Add(new i::SnapshotData(&partial_serializer));
645 } 645 }
646 646
647 for (int i = 0; i < num_additional_contexts; i++) { 647 for (int i = 0; i < num_additional_contexts; i++) {
648 i::PartialSerializer partial_serializer( 648 i::PartialSerializer partial_serializer(
649 isolate, &startup_serializer, data->internal_fields_serializers_[i]); 649 isolate, &startup_serializer, data->embedder_fields_serializers_[i]);
650 partial_serializer.Serialize(&contexts[i], true); 650 partial_serializer.Serialize(&contexts[i], true);
651 context_snapshots.Add(new i::SnapshotData(&partial_serializer)); 651 context_snapshots.Add(new i::SnapshotData(&partial_serializer));
652 } 652 }
653 653
654 startup_serializer.SerializeWeakReferencesAndDeferred(); 654 startup_serializer.SerializeWeakReferencesAndDeferred();
655 655
656 #ifdef DEBUG 656 #ifdef DEBUG
657 if (i::FLAG_external_reference_stats) { 657 if (i::FLAG_external_reference_stats) {
658 i::ExternalReferenceTable::instance(isolate)->PrintCount(); 658 i::ExternalReferenceTable::instance(isolate)->PrintCount();
659 } 659 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 #endif // VERIFY_HEAP 899 #endif // VERIFY_HEAP
900 return result.location(); 900 return result.location();
901 } 901 }
902 902
903 void V8::RegisterExternallyReferencedObject(i::Object** object, 903 void V8::RegisterExternallyReferencedObject(i::Object** object,
904 i::Isolate* isolate) { 904 i::Isolate* isolate) {
905 isolate->heap()->RegisterExternallyReferencedObject(object); 905 isolate->heap()->RegisterExternallyReferencedObject(object);
906 } 906 }
907 907
908 void V8::MakeWeak(i::Object** location, void* parameter, 908 void V8::MakeWeak(i::Object** location, void* parameter,
909 int internal_field_index1, int internal_field_index2, 909 int embedder_field_index1, int embedder_field_index2,
910 WeakCallbackInfo<void>::Callback weak_callback) { 910 WeakCallbackInfo<void>::Callback weak_callback) {
911 WeakCallbackType type = WeakCallbackType::kParameter; 911 WeakCallbackType type = WeakCallbackType::kParameter;
912 if (internal_field_index1 == 0) { 912 if (embedder_field_index1 == 0) {
913 if (internal_field_index2 == 1) { 913 if (embedder_field_index2 == 1) {
914 type = WeakCallbackType::kInternalFields; 914 type = WeakCallbackType::kEmbedderFields;
915 } else { 915 } else {
916 DCHECK_EQ(internal_field_index2, -1); 916 DCHECK_EQ(embedder_field_index2, -1);
917 type = WeakCallbackType::kInternalFields; 917 type = WeakCallbackType::kEmbedderFields;
918 } 918 }
919 } else { 919 } else {
920 DCHECK_EQ(internal_field_index1, -1); 920 DCHECK_EQ(embedder_field_index1, -1);
921 DCHECK_EQ(internal_field_index2, -1); 921 DCHECK_EQ(embedder_field_index2, -1);
922 } 922 }
923 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); 923 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
924 } 924 }
925 925
926 void V8::MakeWeak(i::Object** location, void* parameter, 926 void V8::MakeWeak(i::Object** location, void* parameter,
927 WeakCallbackInfo<void>::Callback weak_callback, 927 WeakCallbackInfo<void>::Callback weak_callback,
928 WeakCallbackType type) { 928 WeakCallbackType type) {
929 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); 929 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
930 } 930 }
931 931
(...skipping 25 matching lines...) Expand all
957 957
958 void V8::FromJustIsNothing() { 958 void V8::FromJustIsNothing() {
959 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing."); 959 Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing.");
960 } 960 }
961 961
962 962
963 void V8::ToLocalEmpty() { 963 void V8::ToLocalEmpty() {
964 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal."); 964 Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal.");
965 } 965 }
966 966
967 967 void V8::EmbedderFieldOutOfBounds(int index) {
968 void V8::InternalFieldOutOfBounds(int index) { 968 Utils::ApiCheck(0 <= index && index < kEmbedderFieldsInWeakCallback,
969 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback, 969 "WeakCallbackInfo::GetEmbedderField",
970 "WeakCallbackInfo::GetInternalField",
971 "Internal field out of bounds."); 970 "Internal field out of bounds.");
972 } 971 }
973 972
974 973
975 // --- H a n d l e s --- 974 // --- H a n d l e s ---
976 975
977 976
978 HandleScope::HandleScope(Isolate* isolate) { 977 HandleScope::HandleScope(Isolate* isolate) {
979 Initialize(isolate); 978 Initialize(isolate);
980 } 979 }
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 i::Handle<i::CallHandlerInfo> obj = 1865 i::Handle<i::CallHandlerInfo> obj =
1867 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 1866 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
1868 SET_FIELD_WRAPPED(obj, set_callback, callback); 1867 SET_FIELD_WRAPPED(obj, set_callback, callback);
1869 if (data.IsEmpty()) { 1868 if (data.IsEmpty()) {
1870 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1869 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1871 } 1870 }
1872 obj->set_data(*Utils::OpenHandle(*data)); 1871 obj->set_data(*Utils::OpenHandle(*data));
1873 cons->set_instance_call_handler(*obj); 1872 cons->set_instance_call_handler(*obj);
1874 } 1873 }
1875 1874
1876 1875 int ObjectTemplate::EmbedderFieldCount() {
1877 int ObjectTemplate::InternalFieldCount() { 1876 return Utils::OpenHandle(this)->embedder_field_count();
1878 return Utils::OpenHandle(this)->internal_field_count();
1879 } 1877 }
1880 1878
1881 1879 void ObjectTemplate::SetEmbedderFieldCount(int value) {
1882 void ObjectTemplate::SetInternalFieldCount(int value) {
1883 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 1880 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1884 if (!Utils::ApiCheck(i::Smi::IsValid(value), 1881 if (!Utils::ApiCheck(i::Smi::IsValid(value),
1885 "v8::ObjectTemplate::SetInternalFieldCount()", 1882 "v8::ObjectTemplate::SetEmbedderFieldCount()",
1886 "Invalid internal field count")) { 1883 "Invalid embedder field count")) {
1887 return; 1884 return;
1888 } 1885 }
1889 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); 1886 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1890 if (value > 0) { 1887 if (value > 0) {
1891 // The internal field count is set by the constructor function's 1888 // The embedder field count is set by the constructor function's
1892 // construct code, so we ensure that there is a constructor 1889 // construct code, so we ensure that there is a constructor
1893 // function to do the setting. 1890 // function to do the setting.
1894 EnsureConstructor(isolate, this); 1891 EnsureConstructor(isolate, this);
1895 } 1892 }
1896 Utils::OpenHandle(this)->set_internal_field_count(value); 1893 Utils::OpenHandle(this)->set_embedder_field_count(value);
1897 } 1894 }
1898 1895
1899 bool ObjectTemplate::IsImmutableProto() { 1896 bool ObjectTemplate::IsImmutableProto() {
1900 return Utils::OpenHandle(this)->immutable_proto(); 1897 return Utils::OpenHandle(this)->immutable_proto();
1901 } 1898 }
1902 1899
1903 void ObjectTemplate::SetImmutableProto() { 1900 void ObjectTemplate::SetImmutableProto() {
1904 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 1901 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1905 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); 1902 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1906 Utils::OpenHandle(this)->set_immutable_proto(true); 1903 Utils::OpenHandle(this)->set_immutable_proto(true);
(...skipping 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after
6042 6039
6043 uint32_t Uint32::Value() const { 6040 uint32_t Uint32::Value() const {
6044 i::Handle<i::Object> obj = Utils::OpenHandle(this); 6041 i::Handle<i::Object> obj = Utils::OpenHandle(this);
6045 if (obj->IsSmi()) { 6042 if (obj->IsSmi()) {
6046 return i::Smi::cast(*obj)->value(); 6043 return i::Smi::cast(*obj)->value();
6047 } else { 6044 } else {
6048 return static_cast<uint32_t>(obj->Number()); 6045 return static_cast<uint32_t>(obj->Number());
6049 } 6046 }
6050 } 6047 }
6051 6048
6052 6049 int v8::Object::EmbedderFieldCount() {
6053 int v8::Object::InternalFieldCount() {
6054 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); 6050 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
6055 if (!self->IsJSObject()) return 0; 6051 if (!self->IsJSObject()) return 0;
6056 return i::Handle<i::JSObject>::cast(self)->GetInternalFieldCount(); 6052 return i::Handle<i::JSObject>::cast(self)->GetEmbedderFieldCount();
6057 } 6053 }
6058 6054
6059 6055 static bool EmbedderFieldOK(i::Handle<i::JSReceiver> obj, int index,
6060 static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index,
6061 const char* location) { 6056 const char* location) {
6062 return Utils::ApiCheck( 6057 return Utils::ApiCheck(
6063 obj->IsJSObject() && 6058 obj->IsJSObject() &&
6064 (index < i::Handle<i::JSObject>::cast(obj)->GetInternalFieldCount()), 6059 (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()),
6065 location, "Internal field out of bounds"); 6060 location, "Internal field out of bounds");
6066 } 6061 }
6067 6062
6068 6063 Local<Value> v8::Object::SlowGetEmbedderField(int index) {
6069 Local<Value> v8::Object::SlowGetInternalField(int index) {
6070 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6064 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6071 const char* location = "v8::Object::GetInternalField()"; 6065 const char* location = "v8::Object::GetEmbedderField()";
6072 if (!InternalFieldOK(obj, index, location)) return Local<Value>(); 6066 if (!EmbedderFieldOK(obj, index, location)) return Local<Value>();
6073 i::Handle<i::Object> value( 6067 i::Handle<i::Object> value(
6074 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), 6068 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index),
6075 obj->GetIsolate()); 6069 obj->GetIsolate());
6076 return Utils::ToLocal(value); 6070 return Utils::ToLocal(value);
6077 } 6071 }
6078 6072
6079 6073 void v8::Object::SetEmbedderField(int index, v8::Local<Value> value) {
6080 void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
6081 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6074 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6082 const char* location = "v8::Object::SetInternalField()"; 6075 const char* location = "v8::Object::SetEmbedderField()";
6083 if (!InternalFieldOK(obj, index, location)) return; 6076 if (!EmbedderFieldOK(obj, index, location)) return;
6084 i::Handle<i::Object> val = Utils::OpenHandle(*value); 6077 i::Handle<i::Object> val = Utils::OpenHandle(*value);
6085 i::Handle<i::JSObject>::cast(obj)->SetInternalField(index, *val); 6078 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
6086 } 6079 }
6087 6080
6088 6081 void* v8::Object::SlowGetAlignedPointerFromEmbedderField(int index) {
6089 void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
6090 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6082 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6091 const char* location = "v8::Object::GetAlignedPointerFromInternalField()"; 6083 const char* location = "v8::Object::GetAlignedPointerFromEmbedderField()";
6092 if (!InternalFieldOK(obj, index, location)) return NULL; 6084 if (!EmbedderFieldOK(obj, index, location)) return NULL;
6093 return DecodeSmiToAligned( 6085 return DecodeSmiToAligned(
6094 i::Handle<i::JSObject>::cast(obj)->GetInternalField(index), location); 6086 i::Handle<i::JSObject>::cast(obj)->GetEmbedderField(index), location);
6095 } 6087 }
6096 6088
6097 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) { 6089 void v8::Object::SetAlignedPointerInEmbedderField(int index, void* value) {
6098 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6090 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6099 const char* location = "v8::Object::SetAlignedPointerInInternalField()"; 6091 const char* location = "v8::Object::SetAlignedPointerInEmbedderField()";
6100 if (!InternalFieldOK(obj, index, location)) return; 6092 if (!EmbedderFieldOK(obj, index, location)) return;
6101 i::Handle<i::JSObject>::cast(obj) 6093 i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(
6102 ->SetInternalField(index, EncodeAlignedAsSmi(value, location)); 6094 index, EncodeAlignedAsSmi(value, location));
6103 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); 6095 DCHECK_EQ(value, GetAlignedPointerFromEmbedderField(index));
6104 } 6096 }
6105 6097
6106 void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[], 6098 void v8::Object::SetAlignedPointerInEmbedderFields(int argc, int indices[],
6107 void* values[]) { 6099 void* values[]) {
6108 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this); 6100 i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
6109 const char* location = "v8::Object::SetAlignedPointerInInternalFields()"; 6101 const char* location = "v8::Object::SetAlignedPointerInEmbedderFields()";
6110 i::DisallowHeapAllocation no_gc; 6102 i::DisallowHeapAllocation no_gc;
6111 i::JSObject* object = i::JSObject::cast(*obj); 6103 i::JSObject* object = i::JSObject::cast(*obj);
6112 int nof_internal_fields = object->GetInternalFieldCount(); 6104 int nof_embedder_fields = object->GetEmbedderFieldCount();
6113 for (int i = 0; i < argc; i++) { 6105 for (int i = 0; i < argc; i++) {
6114 int index = indices[i]; 6106 int index = indices[i];
6115 if (!Utils::ApiCheck(index < nof_internal_fields, location, 6107 if (!Utils::ApiCheck(index < nof_embedder_fields, location,
6116 "Internal field out of bounds")) { 6108 "Internal field out of bounds")) {
6117 return; 6109 return;
6118 } 6110 }
6119 void* value = values[i]; 6111 void* value = values[i];
6120 object->SetInternalField(index, EncodeAlignedAsSmi(value, location)); 6112 object->SetEmbedderField(index, EncodeAlignedAsSmi(value, location));
6121 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index)); 6113 DCHECK_EQ(value, GetAlignedPointerFromEmbedderField(index));
6122 } 6114 }
6123 } 6115 }
6124 6116
6125 static void* ExternalValue(i::Object* obj) { 6117 static void* ExternalValue(i::Object* obj) {
6126 // Obscure semantics for undefined, but somehow checked in our unit tests... 6118 // Obscure semantics for undefined, but somehow checked in our unit tests...
6127 if (!obj->IsSmi() && 6119 if (!obj->IsSmi() &&
6128 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) { 6120 obj->IsUndefined(i::HeapObject::cast(obj)->GetIsolate())) {
6129 return NULL; 6121 return NULL;
6130 } 6122 }
6131 i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0); 6123 i::Object* foreign = i::JSObject::cast(obj)->GetEmbedderField(0);
6132 return i::Foreign::cast(foreign)->foreign_address(); 6124 return i::Foreign::cast(foreign)->foreign_address();
6133 } 6125 }
6134 6126
6135 6127
6136 // --- E n v i r o n m e n t --- 6128 // --- E n v i r o n m e n t ---
6137 6129
6138 6130
6139 void v8::V8::InitializePlatform(Platform* platform) { 6131 void v8::V8::InitializePlatform(Platform* platform) {
6140 i::V8::InitializePlatform(platform); 6132 i::V8::InitializePlatform(platform);
6141 } 6133 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
6227 6219
6228 template <typename ObjectType> 6220 template <typename ObjectType>
6229 struct InvokeBootstrapper; 6221 struct InvokeBootstrapper;
6230 6222
6231 template <> 6223 template <>
6232 struct InvokeBootstrapper<i::Context> { 6224 struct InvokeBootstrapper<i::Context> {
6233 i::Handle<i::Context> Invoke( 6225 i::Handle<i::Context> Invoke(
6234 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, 6226 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
6235 v8::Local<v8::ObjectTemplate> global_object_template, 6227 v8::Local<v8::ObjectTemplate> global_object_template,
6236 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, 6228 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
6237 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6229 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
6238 return isolate->bootstrapper()->CreateEnvironment( 6230 return isolate->bootstrapper()->CreateEnvironment(
6239 maybe_global_proxy, global_object_template, extensions, 6231 maybe_global_proxy, global_object_template, extensions,
6240 context_snapshot_index, internal_fields_deserializer); 6232 context_snapshot_index, embedder_fields_deserializer);
6241 } 6233 }
6242 }; 6234 };
6243 6235
6244 template <> 6236 template <>
6245 struct InvokeBootstrapper<i::JSGlobalProxy> { 6237 struct InvokeBootstrapper<i::JSGlobalProxy> {
6246 i::Handle<i::JSGlobalProxy> Invoke( 6238 i::Handle<i::JSGlobalProxy> Invoke(
6247 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy, 6239 i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
6248 v8::Local<v8::ObjectTemplate> global_object_template, 6240 v8::Local<v8::ObjectTemplate> global_object_template,
6249 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index, 6241 v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
6250 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6242 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
6251 USE(extensions); 6243 USE(extensions);
6252 USE(context_snapshot_index); 6244 USE(context_snapshot_index);
6253 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy, 6245 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
6254 global_object_template); 6246 global_object_template);
6255 } 6247 }
6256 }; 6248 };
6257 6249
6258 template <typename ObjectType> 6250 template <typename ObjectType>
6259 static i::Handle<ObjectType> CreateEnvironment( 6251 static i::Handle<ObjectType> CreateEnvironment(
6260 i::Isolate* isolate, v8::ExtensionConfiguration* extensions, 6252 i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
6261 v8::MaybeLocal<ObjectTemplate> maybe_global_template, 6253 v8::MaybeLocal<ObjectTemplate> maybe_global_template,
6262 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index, 6254 v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index,
6263 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6255 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
6264 i::Handle<ObjectType> result; 6256 i::Handle<ObjectType> result;
6265 6257
6266 { 6258 {
6267 ENTER_V8_FOR_NEW_CONTEXT(isolate); 6259 ENTER_V8_FOR_NEW_CONTEXT(isolate);
6268 v8::Local<ObjectTemplate> proxy_template; 6260 v8::Local<ObjectTemplate> proxy_template;
6269 i::Handle<i::FunctionTemplateInfo> proxy_constructor; 6261 i::Handle<i::FunctionTemplateInfo> proxy_constructor;
6270 i::Handle<i::FunctionTemplateInfo> global_constructor; 6262 i::Handle<i::FunctionTemplateInfo> global_constructor;
6271 i::Handle<i::Object> named_interceptor( 6263 i::Handle<i::Object> named_interceptor(
6272 isolate->factory()->undefined_value()); 6264 isolate->factory()->undefined_value());
6273 i::Handle<i::Object> indexed_interceptor( 6265 i::Handle<i::Object> indexed_interceptor(
6274 isolate->factory()->undefined_value()); 6266 isolate->factory()->undefined_value());
6275 6267
6276 if (!maybe_global_template.IsEmpty()) { 6268 if (!maybe_global_template.IsEmpty()) {
6277 v8::Local<v8::ObjectTemplate> global_template = 6269 v8::Local<v8::ObjectTemplate> global_template =
6278 maybe_global_template.ToLocalChecked(); 6270 maybe_global_template.ToLocalChecked();
6279 // Make sure that the global_template has a constructor. 6271 // Make sure that the global_template has a constructor.
6280 global_constructor = EnsureConstructor(isolate, *global_template); 6272 global_constructor = EnsureConstructor(isolate, *global_template);
6281 6273
6282 // Create a fresh template for the global proxy object. 6274 // Create a fresh template for the global proxy object.
6283 proxy_template = ObjectTemplate::New( 6275 proxy_template = ObjectTemplate::New(
6284 reinterpret_cast<v8::Isolate*>(isolate)); 6276 reinterpret_cast<v8::Isolate*>(isolate));
6285 proxy_constructor = EnsureConstructor(isolate, *proxy_template); 6277 proxy_constructor = EnsureConstructor(isolate, *proxy_template);
6286 6278
6287 // Set the global template to be the prototype template of 6279 // Set the global template to be the prototype template of
6288 // global proxy template. 6280 // global proxy template.
6289 proxy_constructor->set_prototype_template( 6281 proxy_constructor->set_prototype_template(
6290 *Utils::OpenHandle(*global_template)); 6282 *Utils::OpenHandle(*global_template));
6291 6283
6292 proxy_template->SetInternalFieldCount( 6284 proxy_template->SetEmbedderFieldCount(
6293 global_template->InternalFieldCount()); 6285 global_template->EmbedderFieldCount());
6294 6286
6295 // Migrate security handlers from global_template to 6287 // Migrate security handlers from global_template to
6296 // proxy_template. Temporarily removing access check 6288 // proxy_template. Temporarily removing access check
6297 // information from the global template. 6289 // information from the global template.
6298 if (!global_constructor->access_check_info()->IsUndefined(isolate)) { 6290 if (!global_constructor->access_check_info()->IsUndefined(isolate)) {
6299 proxy_constructor->set_access_check_info( 6291 proxy_constructor->set_access_check_info(
6300 global_constructor->access_check_info()); 6292 global_constructor->access_check_info());
6301 proxy_constructor->set_needs_access_check( 6293 proxy_constructor->set_needs_access_check(
6302 global_constructor->needs_access_check()); 6294 global_constructor->needs_access_check());
6303 global_constructor->set_needs_access_check(false); 6295 global_constructor->set_needs_access_check(false);
(...skipping 22 matching lines...) Expand all
6326 6318
6327 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy; 6319 i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
6328 if (!maybe_global_proxy.IsEmpty()) { 6320 if (!maybe_global_proxy.IsEmpty()) {
6329 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast( 6321 maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(
6330 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked())); 6322 Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked()));
6331 } 6323 }
6332 // Create the environment. 6324 // Create the environment.
6333 InvokeBootstrapper<ObjectType> invoke; 6325 InvokeBootstrapper<ObjectType> invoke;
6334 result = 6326 result =
6335 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions, 6327 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
6336 context_snapshot_index, internal_fields_deserializer); 6328 context_snapshot_index, embedder_fields_deserializer);
6337 6329
6338 // Restore the access check info and interceptors on the global template. 6330 // Restore the access check info and interceptors on the global template.
6339 if (!maybe_global_template.IsEmpty()) { 6331 if (!maybe_global_template.IsEmpty()) {
6340 DCHECK(!global_constructor.is_null()); 6332 DCHECK(!global_constructor.is_null());
6341 DCHECK(!proxy_constructor.is_null()); 6333 DCHECK(!proxy_constructor.is_null());
6342 global_constructor->set_access_check_info( 6334 global_constructor->set_access_check_info(
6343 proxy_constructor->access_check_info()); 6335 proxy_constructor->access_check_info());
6344 global_constructor->set_needs_access_check( 6336 global_constructor->set_needs_access_check(
6345 proxy_constructor->needs_access_check()); 6337 proxy_constructor->needs_access_check());
6346 global_constructor->set_named_property_handler(*named_interceptor); 6338 global_constructor->set_named_property_handler(*named_interceptor);
6347 global_constructor->set_indexed_property_handler(*indexed_interceptor); 6339 global_constructor->set_indexed_property_handler(*indexed_interceptor);
6348 } 6340 }
6349 } 6341 }
6350 // Leave V8. 6342 // Leave V8.
6351 6343
6352 return result; 6344 return result;
6353 } 6345 }
6354 6346
6355 Local<Context> NewContext( 6347 Local<Context> NewContext(
6356 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, 6348 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
6357 v8::MaybeLocal<ObjectTemplate> global_template, 6349 v8::MaybeLocal<ObjectTemplate> global_template,
6358 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index, 6350 v8::MaybeLocal<Value> global_object, size_t context_snapshot_index,
6359 v8::DeserializeInternalFieldsCallback internal_fields_deserializer) { 6351 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
6360 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 6352 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
6361 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext"); 6353 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
6362 LOG_API(isolate, Context, New); 6354 LOG_API(isolate, Context, New);
6363 i::HandleScope scope(isolate); 6355 i::HandleScope scope(isolate);
6364 ExtensionConfiguration no_extensions; 6356 ExtensionConfiguration no_extensions;
6365 if (extensions == NULL) extensions = &no_extensions; 6357 if (extensions == NULL) extensions = &no_extensions;
6366 i::Handle<i::Context> env = CreateEnvironment<i::Context>( 6358 i::Handle<i::Context> env = CreateEnvironment<i::Context>(
6367 isolate, extensions, global_template, global_object, 6359 isolate, extensions, global_template, global_object,
6368 context_snapshot_index, internal_fields_deserializer); 6360 context_snapshot_index, embedder_fields_deserializer);
6369 if (env.is_null()) { 6361 if (env.is_null()) {
6370 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); 6362 if (isolate->has_pending_exception()) isolate->clear_pending_exception();
6371 return Local<Context>(); 6363 return Local<Context>();
6372 } 6364 }
6373 return Utils::ToLocal(scope.CloseAndEscape(env)); 6365 return Utils::ToLocal(scope.CloseAndEscape(env));
6374 } 6366 }
6375 6367
6376 Local<Context> v8::Context::New(v8::Isolate* external_isolate, 6368 Local<Context> v8::Context::New(v8::Isolate* external_isolate,
6377 v8::ExtensionConfiguration* extensions, 6369 v8::ExtensionConfiguration* extensions,
6378 v8::MaybeLocal<ObjectTemplate> global_template, 6370 v8::MaybeLocal<ObjectTemplate> global_template,
6379 v8::MaybeLocal<Value> global_object) { 6371 v8::MaybeLocal<Value> global_object) {
6380 return NewContext(external_isolate, extensions, global_template, 6372 return NewContext(external_isolate, extensions, global_template,
6381 global_object, 0, DeserializeInternalFieldsCallback()); 6373 global_object, 0, DeserializeEmbedderFieldsCallback());
6382 } 6374 }
6383 6375
6384 MaybeLocal<Context> v8::Context::FromSnapshot( 6376 MaybeLocal<Context> v8::Context::FromSnapshot(
6385 v8::Isolate* external_isolate, size_t context_snapshot_index, 6377 v8::Isolate* external_isolate, size_t context_snapshot_index,
6386 v8::DeserializeInternalFieldsCallback internal_fields_deserializer, 6378 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer,
6387 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) { 6379 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) {
6388 size_t index_including_default_context = context_snapshot_index + 1; 6380 size_t index_including_default_context = context_snapshot_index + 1;
6389 if (!i::Snapshot::HasContextSnapshot( 6381 if (!i::Snapshot::HasContextSnapshot(
6390 reinterpret_cast<i::Isolate*>(external_isolate), 6382 reinterpret_cast<i::Isolate*>(external_isolate),
6391 index_including_default_context)) { 6383 index_including_default_context)) {
6392 return MaybeLocal<Context>(); 6384 return MaybeLocal<Context>();
6393 } 6385 }
6394 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(), 6386 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
6395 global_object, index_including_default_context, 6387 global_object, index_including_default_context,
6396 internal_fields_deserializer); 6388 embedder_fields_deserializer);
6397 } 6389 }
6398 6390
6399 MaybeLocal<Object> v8::Context::NewRemoteContext( 6391 MaybeLocal<Object> v8::Context::NewRemoteContext(
6400 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template, 6392 v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template,
6401 v8::MaybeLocal<v8::Value> global_object) { 6393 v8::MaybeLocal<v8::Value> global_object) {
6402 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 6394 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
6403 LOG_API(isolate, Context, NewRemoteContext); 6395 LOG_API(isolate, Context, NewRemoteContext);
6404 i::HandleScope scope(isolate); 6396 i::HandleScope scope(isolate);
6405 i::Handle<i::FunctionTemplateInfo> global_constructor = 6397 i::Handle<i::FunctionTemplateInfo> global_constructor =
6406 EnsureConstructor(isolate, *global_template); 6398 EnsureConstructor(isolate, *global_template);
6407 Utils::ApiCheck(global_constructor->needs_access_check(), 6399 Utils::ApiCheck(global_constructor->needs_access_check(),
6408 "v8::Context::NewRemoteContext", 6400 "v8::Context::NewRemoteContext",
6409 "Global template needs to have access checks enabled."); 6401 "Global template needs to have access checks enabled.");
6410 i::Handle<i::AccessCheckInfo> access_check_info = i::handle( 6402 i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
6411 i::AccessCheckInfo::cast(global_constructor->access_check_info()), 6403 i::AccessCheckInfo::cast(global_constructor->access_check_info()),
6412 isolate); 6404 isolate);
6413 Utils::ApiCheck(access_check_info->named_interceptor() != nullptr, 6405 Utils::ApiCheck(access_check_info->named_interceptor() != nullptr,
6414 "v8::Context::NewRemoteContext", 6406 "v8::Context::NewRemoteContext",
6415 "Global template needs to have access check handlers."); 6407 "Global template needs to have access check handlers.");
6416 i::Handle<i::JSGlobalProxy> global_proxy = 6408 i::Handle<i::JSGlobalProxy> global_proxy =
6417 CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template, 6409 CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template,
6418 global_object, 0, 6410 global_object, 0,
6419 DeserializeInternalFieldsCallback()); 6411 DeserializeEmbedderFieldsCallback());
6420 if (global_proxy.is_null()) { 6412 if (global_proxy.is_null()) {
6421 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); 6413 if (isolate->has_pending_exception()) isolate->clear_pending_exception();
6422 return MaybeLocal<Object>(); 6414 return MaybeLocal<Object>();
6423 } 6415 }
6424 return Utils::ToLocal( 6416 return Utils::ToLocal(
6425 scope.CloseAndEscape(i::Handle<i::JSObject>::cast(global_proxy))); 6417 scope.CloseAndEscape(i::Handle<i::JSObject>::cast(global_proxy)));
6426 } 6418 }
6427 6419
6428 void v8::Context::SetSecurityToken(Local<Value> token) { 6420 void v8::Context::SetSecurityToken(Local<Value> token) {
6429 i::Handle<i::Context> env = Utils::OpenHandle(this); 6421 i::Handle<i::Context> env = Utils::OpenHandle(this);
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
7507 has_pending_exception = 7499 has_pending_exception =
7508 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); 7500 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
7509 RETURN_ON_FAILED_EXECUTION(Proxy); 7501 RETURN_ON_FAILED_EXECUTION(Proxy);
7510 RETURN_ESCAPED(result); 7502 RETURN_ESCAPED(result);
7511 } 7503 }
7512 7504
7513 Local<String> WasmCompiledModule::GetWasmWireBytes() { 7505 Local<String> WasmCompiledModule::GetWasmWireBytes() {
7514 i::Handle<i::JSObject> obj = 7506 i::Handle<i::JSObject> obj =
7515 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7507 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7516 i::Handle<i::WasmCompiledModule> compiled_part = 7508 i::Handle<i::WasmCompiledModule> compiled_part =
7517 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7509 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7518 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); 7510 i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
7519 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); 7511 return Local<String>::Cast(Utils::ToLocal(wire_bytes));
7520 } 7512 }
7521 7513
7522 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { 7514 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
7523 i::Handle<i::JSObject> obj = 7515 i::Handle<i::JSObject> obj =
7524 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 7516 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
7525 i::Handle<i::WasmCompiledModule> compiled_part = 7517 i::Handle<i::WasmCompiledModule> compiled_part =
7526 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); 7518 i::handle(i::WasmCompiledModule::cast(obj->GetEmbedderField(0)));
7527 7519
7528 std::unique_ptr<i::ScriptData> script_data = 7520 std::unique_ptr<i::ScriptData> script_data =
7529 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), 7521 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
7530 compiled_part); 7522 compiled_part);
7531 script_data->ReleaseDataOwnership(); 7523 script_data->ReleaseDataOwnership();
7532 7524
7533 size_t size = static_cast<size_t>(script_data->length()); 7525 size_t size = static_cast<size_t>(script_data->length());
7534 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; 7526 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
7535 } 7527 }
7536 7528
(...skipping 2706 matching lines...) Expand 10 before | Expand all | Expand 10 after
10243 Address callback_address = 10235 Address callback_address =
10244 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10236 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10245 VMState<EXTERNAL> state(isolate); 10237 VMState<EXTERNAL> state(isolate);
10246 ExternalCallbackScope call_scope(isolate, callback_address); 10238 ExternalCallbackScope call_scope(isolate, callback_address);
10247 callback(info); 10239 callback(info);
10248 } 10240 }
10249 10241
10250 10242
10251 } // namespace internal 10243 } // namespace internal
10252 } // namespace v8 10244 } // namespace v8
OLDNEW
« include/v8-experimental.h ('K') | « samples/process.cc ('k') | src/api-experimental.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698