Chromium Code Reviews| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 Local<Context> context = Context::New(isolate, NULL, global_template); | 541 Local<Context> context = Context::New(isolate, NULL, global_template); |
| 542 if (context.IsEmpty()) { | 542 if (context.IsEmpty()) { |
| 543 DCHECK(try_catch.HasCaught()); | 543 DCHECK(try_catch.HasCaught()); |
| 544 try_catch.ReThrow(); | 544 try_catch.ReThrow(); |
| 545 return; | 545 return; |
| 546 } | 546 } |
| 547 data->realms_[index].Reset(isolate, context); | 547 data->realms_[index].Reset(isolate, context); |
| 548 args.GetReturnValue().Set(index); | 548 args.GetReturnValue().Set(index); |
| 549 } | 549 } |
| 550 | 550 |
| 551 // Realm.createAllowCrossRealmAccess(i) jreates a new realm with the same | |
|
adamk
2016/05/19 19:23:20
s/jreates/creates/
Dan Ehrenberg
2016/05/27 13:51:39
Done
| |
| 552 // security token as the current realm. | |
| 553 void Shell::RealmCreateAllowCrossRealmAccess( | |
|
rossberg
2016/05/19 06:07:00
I wouldn't mind factoring out the commonalities be
adamk
2016/05/19 19:23:20
Agreed, the fewer places we have to write 'delete[
Dan Ehrenberg
2016/05/27 13:51:39
Done
| |
| 554 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 555 Isolate* isolate = args.GetIsolate(); | |
| 556 TryCatch try_catch(isolate); | |
| 557 PerIsolateData* data = PerIsolateData::Get(isolate); | |
| 558 Global<Context>* old_realms = data->realms_; | |
| 559 int index = data->realm_count_; | |
| 560 data->realms_ = new Global<Context>[++data->realm_count_]; | |
| 561 for (int i = 0; i < index; ++i) { | |
| 562 data->realms_[i].Reset(isolate, old_realms[i]); | |
| 563 old_realms[i].Reset(); | |
| 564 } | |
| 565 delete[] old_realms; | |
| 566 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | |
| 567 Local<Context> context = Context::New(isolate, NULL, global_template); | |
| 568 if (context.IsEmpty()) { | |
| 569 DCHECK(try_catch.HasCaught()); | |
| 570 try_catch.ReThrow(); | |
| 571 return; | |
| 572 } | |
| 573 context->SetSecurityToken(isolate->GetEnteredContext()->GetSecurityToken()); | |
| 574 data->realms_[index].Reset(isolate, context); | |
| 575 args.GetReturnValue().Set(index); | |
| 576 } | |
| 551 | 577 |
| 552 // Realm.dispose(i) disposes the reference to the realm i. | 578 // Realm.dispose(i) disposes the reference to the realm i. |
| 553 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { | 579 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 554 Isolate* isolate = args.GetIsolate(); | 580 Isolate* isolate = args.GetIsolate(); |
| 555 PerIsolateData* data = PerIsolateData::Get(isolate); | 581 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 556 int index = data->RealmIndexOrThrow(args, 0); | 582 int index = data->RealmIndexOrThrow(args, 0); |
| 557 if (index == -1) return; | 583 if (index == -1) return; |
| 558 if (index == 0 || | 584 if (index == 0 || |
| 559 index == data->realm_current_ || index == data->realm_switch_) { | 585 index == data->realm_current_ || index == data->realm_switch_) { |
| 560 Throw(args.GetIsolate(), "Invalid realm index"); | 586 Throw(args.GetIsolate(), "Invalid realm index"); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 FunctionTemplate::New(isolate, RealmOwner)); | 1155 FunctionTemplate::New(isolate, RealmOwner)); |
| 1130 realm_template->Set( | 1156 realm_template->Set( |
| 1131 String::NewFromUtf8(isolate, "global", NewStringType::kNormal) | 1157 String::NewFromUtf8(isolate, "global", NewStringType::kNormal) |
| 1132 .ToLocalChecked(), | 1158 .ToLocalChecked(), |
| 1133 FunctionTemplate::New(isolate, RealmGlobal)); | 1159 FunctionTemplate::New(isolate, RealmGlobal)); |
| 1134 realm_template->Set( | 1160 realm_template->Set( |
| 1135 String::NewFromUtf8(isolate, "create", NewStringType::kNormal) | 1161 String::NewFromUtf8(isolate, "create", NewStringType::kNormal) |
| 1136 .ToLocalChecked(), | 1162 .ToLocalChecked(), |
| 1137 FunctionTemplate::New(isolate, RealmCreate)); | 1163 FunctionTemplate::New(isolate, RealmCreate)); |
| 1138 realm_template->Set( | 1164 realm_template->Set( |
| 1165 String::NewFromUtf8(isolate, "createAllowCrossRealmAccess", | |
| 1166 NewStringType::kNormal) | |
| 1167 .ToLocalChecked(), | |
| 1168 FunctionTemplate::New(isolate, RealmCreateAllowCrossRealmAccess)); | |
| 1169 realm_template->Set( | |
| 1139 String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal) | 1170 String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal) |
| 1140 .ToLocalChecked(), | 1171 .ToLocalChecked(), |
| 1141 FunctionTemplate::New(isolate, RealmDispose)); | 1172 FunctionTemplate::New(isolate, RealmDispose)); |
| 1142 realm_template->Set( | 1173 realm_template->Set( |
| 1143 String::NewFromUtf8(isolate, "switch", NewStringType::kNormal) | 1174 String::NewFromUtf8(isolate, "switch", NewStringType::kNormal) |
| 1144 .ToLocalChecked(), | 1175 .ToLocalChecked(), |
| 1145 FunctionTemplate::New(isolate, RealmSwitch)); | 1176 FunctionTemplate::New(isolate, RealmSwitch)); |
| 1146 realm_template->Set( | 1177 realm_template->Set( |
| 1147 String::NewFromUtf8(isolate, "eval", NewStringType::kNormal) | 1178 String::NewFromUtf8(isolate, "eval", NewStringType::kNormal) |
| 1148 .ToLocalChecked(), | 1179 .ToLocalChecked(), |
| (...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2526 } | 2557 } |
| 2527 | 2558 |
| 2528 } // namespace v8 | 2559 } // namespace v8 |
| 2529 | 2560 |
| 2530 | 2561 |
| 2531 #ifndef GOOGLE3 | 2562 #ifndef GOOGLE3 |
| 2532 int main(int argc, char* argv[]) { | 2563 int main(int argc, char* argv[]) { |
| 2533 return v8::Shell::Main(argc, argv); | 2564 return v8::Shell::Main(argc, argv); |
| 2534 } | 2565 } |
| 2535 #endif | 2566 #endif |
| OLD | NEW |