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 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // Realm.global(i) returns the global object of realm i. | 516 // Realm.global(i) returns the global object of realm i. |
517 // (Note that properties of global objects cannot be read/written cross-realm.) | 517 // (Note that properties of global objects cannot be read/written cross-realm.) |
518 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { | 518 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { |
519 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); | 519 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); |
520 int index = data->RealmIndexOrThrow(args, 0); | 520 int index = data->RealmIndexOrThrow(args, 0); |
521 if (index == -1) return; | 521 if (index == -1) return; |
522 args.GetReturnValue().Set( | 522 args.GetReturnValue().Set( |
523 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global()); | 523 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global()); |
524 } | 524 } |
525 | 525 |
526 | 526 MaybeLocal<Context> Shell::CreateRealm( |
527 // Realm.create() creates a new realm and returns its index. | 527 const v8::FunctionCallbackInfo<v8::Value>& args) { |
528 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
529 Isolate* isolate = args.GetIsolate(); | 528 Isolate* isolate = args.GetIsolate(); |
530 TryCatch try_catch(isolate); | 529 TryCatch try_catch(isolate); |
531 PerIsolateData* data = PerIsolateData::Get(isolate); | 530 PerIsolateData* data = PerIsolateData::Get(isolate); |
532 Global<Context>* old_realms = data->realms_; | 531 Global<Context>* old_realms = data->realms_; |
533 int index = data->realm_count_; | 532 int index = data->realm_count_; |
534 data->realms_ = new Global<Context>[++data->realm_count_]; | 533 data->realms_ = new Global<Context>[++data->realm_count_]; |
535 for (int i = 0; i < index; ++i) { | 534 for (int i = 0; i < index; ++i) { |
536 data->realms_[i].Reset(isolate, old_realms[i]); | 535 data->realms_[i].Reset(isolate, old_realms[i]); |
537 old_realms[i].Reset(); | 536 old_realms[i].Reset(); |
538 } | 537 } |
539 delete[] old_realms; | 538 delete[] old_realms; |
540 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 539 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
541 Local<Context> context = Context::New(isolate, NULL, global_template); | 540 Local<Context> context = Context::New(isolate, NULL, global_template); |
542 if (context.IsEmpty()) { | 541 if (context.IsEmpty()) { |
543 DCHECK(try_catch.HasCaught()); | 542 DCHECK(try_catch.HasCaught()); |
544 try_catch.ReThrow(); | 543 try_catch.ReThrow(); |
545 return; | 544 return MaybeLocal<Context>(); |
546 } | 545 } |
547 data->realms_[index].Reset(isolate, context); | 546 data->realms_[index].Reset(isolate, context); |
548 args.GetReturnValue().Set(index); | 547 args.GetReturnValue().Set(index); |
| 548 return context; |
549 } | 549 } |
550 | 550 |
| 551 // Realm.create() creates a new realm with a distinct security token |
| 552 // and returns its index. |
| 553 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 554 CreateRealm(args); |
| 555 } |
| 556 |
| 557 // Realm.createAllowCrossRealmAccess() creates a new realm with the same |
| 558 // security token as the current realm. |
| 559 void Shell::RealmCreateAllowCrossRealmAccess( |
| 560 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 561 Local<Context> context; |
| 562 if (CreateRealm(args).ToLocal(&context)) { |
| 563 context->SetSecurityToken( |
| 564 args.GetIsolate()->GetEnteredContext()->GetSecurityToken()); |
| 565 } |
| 566 } |
551 | 567 |
552 // Realm.dispose(i) disposes the reference to the realm i. | 568 // Realm.dispose(i) disposes the reference to the realm i. |
553 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { | 569 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { |
554 Isolate* isolate = args.GetIsolate(); | 570 Isolate* isolate = args.GetIsolate(); |
555 PerIsolateData* data = PerIsolateData::Get(isolate); | 571 PerIsolateData* data = PerIsolateData::Get(isolate); |
556 int index = data->RealmIndexOrThrow(args, 0); | 572 int index = data->RealmIndexOrThrow(args, 0); |
557 if (index == -1) return; | 573 if (index == -1) return; |
558 if (index == 0 || | 574 if (index == 0 || |
559 index == data->realm_current_ || index == data->realm_switch_) { | 575 index == data->realm_current_ || index == data->realm_switch_) { |
560 Throw(args.GetIsolate(), "Invalid realm index"); | 576 Throw(args.GetIsolate(), "Invalid realm index"); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 FunctionTemplate::New(isolate, RealmOwner)); | 1145 FunctionTemplate::New(isolate, RealmOwner)); |
1130 realm_template->Set( | 1146 realm_template->Set( |
1131 String::NewFromUtf8(isolate, "global", NewStringType::kNormal) | 1147 String::NewFromUtf8(isolate, "global", NewStringType::kNormal) |
1132 .ToLocalChecked(), | 1148 .ToLocalChecked(), |
1133 FunctionTemplate::New(isolate, RealmGlobal)); | 1149 FunctionTemplate::New(isolate, RealmGlobal)); |
1134 realm_template->Set( | 1150 realm_template->Set( |
1135 String::NewFromUtf8(isolate, "create", NewStringType::kNormal) | 1151 String::NewFromUtf8(isolate, "create", NewStringType::kNormal) |
1136 .ToLocalChecked(), | 1152 .ToLocalChecked(), |
1137 FunctionTemplate::New(isolate, RealmCreate)); | 1153 FunctionTemplate::New(isolate, RealmCreate)); |
1138 realm_template->Set( | 1154 realm_template->Set( |
| 1155 String::NewFromUtf8(isolate, "createAllowCrossRealmAccess", |
| 1156 NewStringType::kNormal) |
| 1157 .ToLocalChecked(), |
| 1158 FunctionTemplate::New(isolate, RealmCreateAllowCrossRealmAccess)); |
| 1159 realm_template->Set( |
1139 String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal) | 1160 String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal) |
1140 .ToLocalChecked(), | 1161 .ToLocalChecked(), |
1141 FunctionTemplate::New(isolate, RealmDispose)); | 1162 FunctionTemplate::New(isolate, RealmDispose)); |
1142 realm_template->Set( | 1163 realm_template->Set( |
1143 String::NewFromUtf8(isolate, "switch", NewStringType::kNormal) | 1164 String::NewFromUtf8(isolate, "switch", NewStringType::kNormal) |
1144 .ToLocalChecked(), | 1165 .ToLocalChecked(), |
1145 FunctionTemplate::New(isolate, RealmSwitch)); | 1166 FunctionTemplate::New(isolate, RealmSwitch)); |
1146 realm_template->Set( | 1167 realm_template->Set( |
1147 String::NewFromUtf8(isolate, "eval", NewStringType::kNormal) | 1168 String::NewFromUtf8(isolate, "eval", NewStringType::kNormal) |
1148 .ToLocalChecked(), | 1169 .ToLocalChecked(), |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 } | 2547 } |
2527 | 2548 |
2528 } // namespace v8 | 2549 } // namespace v8 |
2529 | 2550 |
2530 | 2551 |
2531 #ifndef GOOGLE3 | 2552 #ifndef GOOGLE3 |
2532 int main(int argc, char* argv[]) { | 2553 int main(int argc, char* argv[]) { |
2533 return v8::Shell::Main(argc, argv); | 2554 return v8::Shell::Main(argc, argv); |
2534 } | 2555 } |
2535 #endif | 2556 #endif |
OLD | NEW |