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

Side by Side Diff: src/api.cc

Issue 2100073002: [snapshot] revisit snapshot API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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/snapshot/snapshot.h » ('j') | no next file with comments »
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 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 int length) { 1193 int length) {
1194 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1194 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1195 // Changes to the environment cannot be captured in the snapshot. Expect no 1195 // Changes to the environment cannot be captured in the snapshot. Expect no
1196 // function templates when the isolate is created for serialization. 1196 // function templates when the isolate is created for serialization.
1197 LOG_API(i_isolate, FunctionTemplate, New); 1197 LOG_API(i_isolate, FunctionTemplate, New);
1198 ENTER_V8(i_isolate); 1198 ENTER_V8(i_isolate);
1199 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, 1199 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature,
1200 length, false); 1200 length, false);
1201 } 1201 }
1202 1202
1203 Local<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate, 1203 MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate,
1204 size_t index) { 1204 size_t index) {
1205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1206 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); 1206 i::FixedArray* templates = i_isolate->heap()->serialized_templates();
1207 int int_index = static_cast<int>(index); 1207 int int_index = static_cast<int>(index);
1208 if (int_index < templates->length()) { 1208 if (int_index < templates->length()) {
1209 i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index); 1209 i::Object* info = templates->get(int_index);
1210 if (info->IsFunctionTemplateInfo()) { 1210 if (info->IsFunctionTemplateInfo()) {
1211 return Utils::ToLocal(i::Handle<i::FunctionTemplateInfo>( 1211 return Utils::ToLocal(i::Handle<i::FunctionTemplateInfo>(
1212 i::FunctionTemplateInfo::cast(info))); 1212 i::FunctionTemplateInfo::cast(info)));
1213 } 1213 }
1214 } 1214 }
1215 return Local<FunctionTemplate>(); 1215 return Local<FunctionTemplate>();
1216 } 1216 }
1217 1217
1218 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( 1218 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler(
1219 Isolate* isolate, FunctionCallback callback, 1219 Isolate* isolate, FunctionCallback callback,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 obj->set_constructor(*Utils::OpenHandle(*constructor)); 1418 obj->set_constructor(*Utils::OpenHandle(*constructor));
1419 obj->set_internal_field_count(i::Smi::FromInt(0)); 1419 obj->set_internal_field_count(i::Smi::FromInt(0));
1420 return Utils::ToLocal(obj); 1420 return Utils::ToLocal(obj);
1421 } 1421 }
1422 1422
1423 Local<ObjectTemplate> ObjectTemplate::New( 1423 Local<ObjectTemplate> ObjectTemplate::New(
1424 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { 1424 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
1425 return ObjectTemplateNew(isolate, constructor, false); 1425 return ObjectTemplateNew(isolate, constructor, false);
1426 } 1426 }
1427 1427
1428 Local<ObjectTemplate> ObjectTemplate::FromSnapshot(Isolate* isolate, 1428 MaybeLocal<ObjectTemplate> ObjectTemplate::FromSnapshot(Isolate* isolate,
1429 size_t index) { 1429 size_t index) {
1430 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1430 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1431 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); 1431 i::FixedArray* templates = i_isolate->heap()->serialized_templates();
1432 int int_index = static_cast<int>(index); 1432 int int_index = static_cast<int>(index);
1433 if (int_index < templates->length()) { 1433 if (int_index < templates->length()) {
1434 i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index); 1434 i::Object* info = templates->get(int_index);
1435 if (info->IsObjectTemplateInfo()) { 1435 if (info->IsObjectTemplateInfo()) {
1436 return Utils::ToLocal( 1436 return Utils::ToLocal(
1437 i::Handle<i::ObjectTemplateInfo>(i::ObjectTemplateInfo::cast(info))); 1437 i::Handle<i::ObjectTemplateInfo>(i::ObjectTemplateInfo::cast(info)));
1438 } 1438 }
1439 } 1439 }
1440 return Local<ObjectTemplate>(); 1440 return Local<ObjectTemplate>();
1441 } 1441 }
1442 1442
1443 // Ensure that the object template has a constructor. If no 1443 // Ensure that the object template has a constructor. If no
1444 // constructor is available we create one. 1444 // constructor is available we create one.
(...skipping 4218 matching lines...) Expand 10 before | Expand all | Expand 10 after
5663 proxy_constructor->access_check_info()); 5663 proxy_constructor->access_check_info());
5664 global_constructor->set_needs_access_check( 5664 global_constructor->set_needs_access_check(
5665 proxy_constructor->needs_access_check()); 5665 proxy_constructor->needs_access_check());
5666 } 5666 }
5667 } 5667 }
5668 // Leave V8. 5668 // Leave V8.
5669 5669
5670 return env; 5670 return env;
5671 } 5671 }
5672 5672
5673 Local<Context> v8::Context::New(v8::Isolate* external_isolate, 5673 Local<Context> NewContext(v8::Isolate* external_isolate,
5674 v8::ExtensionConfiguration* extensions, 5674 v8::ExtensionConfiguration* extensions,
5675 v8::Local<ObjectTemplate> global_template, 5675 v8::Local<ObjectTemplate> global_template,
5676 v8::Local<Value> global_object, 5676 v8::Local<Value> global_object,
5677 size_t context_snapshot_index) { 5677 size_t context_snapshot_index) {
5678 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 5678 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
5679 LOG_API(isolate, Context, New); 5679 LOG_API(isolate, Context, New);
5680 i::HandleScope scope(isolate); 5680 i::HandleScope scope(isolate);
5681 ExtensionConfiguration no_extensions; 5681 ExtensionConfiguration no_extensions;
5682 if (extensions == NULL) extensions = &no_extensions; 5682 if (extensions == NULL) extensions = &no_extensions;
5683 i::Handle<i::Context> env = 5683 i::Handle<i::Context> env =
5684 CreateEnvironment(isolate, extensions, global_template, global_object, 5684 CreateEnvironment(isolate, extensions, global_template, global_object,
5685 context_snapshot_index); 5685 context_snapshot_index);
5686 if (env.is_null()) { 5686 if (env.is_null()) {
5687 if (isolate->has_pending_exception()) { 5687 if (isolate->has_pending_exception()) {
5688 isolate->OptionalRescheduleException(true); 5688 isolate->OptionalRescheduleException(true);
5689 } 5689 }
5690 return Local<Context>(); 5690 return Local<Context>();
5691 } 5691 }
5692 return Utils::ToLocal(scope.CloseAndEscape(env)); 5692 return Utils::ToLocal(scope.CloseAndEscape(env));
5693 } 5693 }
5694 5694
5695 Local<Context> v8::Context::New(v8::Isolate* external_isolate,
5696 v8::ExtensionConfiguration* extensions,
5697 v8::Local<ObjectTemplate> global_template,
5698 v8::Local<Value> global_object) {
5699 return NewContext(external_isolate, extensions, global_template,
5700 global_object, 0);
5701 }
5702
5703 MaybeLocal<Context> v8::Context::FromSnapshot(
5704 v8::Isolate* external_isolate, size_t context_snapshot_index,
5705 v8::ExtensionConfiguration* extensions,
5706 v8::Local<ObjectTemplate> global_template, v8::Local<Value> global_object) {
5707 if (!i::Snapshot::HasContextSnapshot(
5708 reinterpret_cast<i::Isolate*>(external_isolate),
5709 context_snapshot_index)) {
5710 return MaybeLocal<Context>();
5711 }
5712 return NewContext(external_isolate, extensions, global_template,
5713 global_object, context_snapshot_index);
5714 }
5695 5715
5696 void v8::Context::SetSecurityToken(Local<Value> token) { 5716 void v8::Context::SetSecurityToken(Local<Value> token) {
5697 i::Handle<i::Context> env = Utils::OpenHandle(this); 5717 i::Handle<i::Context> env = Utils::OpenHandle(this);
5698 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); 5718 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
5699 env->set_security_token(*token_handle); 5719 env->set_security_token(*token_handle);
5700 } 5720 }
5701 5721
5702 5722
5703 void v8::Context::UseDefaultSecurityToken() { 5723 void v8::Context::UseDefaultSecurityToken() {
5704 i::Handle<i::Context> env = Utils::OpenHandle(this); 5724 i::Handle<i::Context> env = Utils::OpenHandle(this);
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after
8885 Address callback_address = 8905 Address callback_address =
8886 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8906 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8887 VMState<EXTERNAL> state(isolate); 8907 VMState<EXTERNAL> state(isolate);
8888 ExternalCallbackScope call_scope(isolate, callback_address); 8908 ExternalCallbackScope call_scope(isolate, callback_address);
8889 callback(info); 8909 callback(info);
8890 } 8910 }
8891 8911
8892 8912
8893 } // namespace internal 8913 } // namespace internal
8894 } // namespace v8 8914 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/snapshot/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698