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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 int index = data->RealmIndexOrThrow(args, 0); | 467 int index = data->RealmIndexOrThrow(args, 0); |
468 if (index == -1) return; | 468 if (index == -1) return; |
469 args.GetReturnValue().Set( | 469 args.GetReturnValue().Set( |
470 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global()); | 470 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global()); |
471 } | 471 } |
472 | 472 |
473 | 473 |
474 // Realm.create() creates a new realm and returns its index. | 474 // Realm.create() creates a new realm and returns its index. |
475 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 475 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
476 Isolate* isolate = args.GetIsolate(); | 476 Isolate* isolate = args.GetIsolate(); |
| 477 TryCatch try_catch(isolate); |
477 PerIsolateData* data = PerIsolateData::Get(isolate); | 478 PerIsolateData* data = PerIsolateData::Get(isolate); |
478 Persistent<Context>* old_realms = data->realms_; | 479 Persistent<Context>* old_realms = data->realms_; |
479 int index = data->realm_count_; | 480 int index = data->realm_count_; |
480 data->realms_ = new Persistent<Context>[++data->realm_count_]; | 481 data->realms_ = new Persistent<Context>[++data->realm_count_]; |
481 for (int i = 0; i < index; ++i) { | 482 for (int i = 0; i < index; ++i) { |
482 data->realms_[i].Reset(isolate, old_realms[i]); | 483 data->realms_[i].Reset(isolate, old_realms[i]); |
483 } | 484 } |
484 delete[] old_realms; | 485 delete[] old_realms; |
485 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 486 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
486 data->realms_[index].Reset( | 487 Local<Context> context = Context::New(isolate, NULL, global_template); |
487 isolate, Context::New(isolate, NULL, global_template)); | 488 if (context.IsEmpty()) { |
| 489 DCHECK(try_catch.HasCaught()); |
| 490 try_catch.ReThrow(); |
| 491 return; |
| 492 } |
| 493 data->realms_[index].Reset(isolate, context); |
488 args.GetReturnValue().Set(index); | 494 args.GetReturnValue().Set(index); |
489 } | 495 } |
490 | 496 |
491 | 497 |
492 // Realm.dispose(i) disposes the reference to the realm i. | 498 // Realm.dispose(i) disposes the reference to the realm i. |
493 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { | 499 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { |
494 Isolate* isolate = args.GetIsolate(); | 500 Isolate* isolate = args.GetIsolate(); |
495 PerIsolateData* data = PerIsolateData::Get(isolate); | 501 PerIsolateData* data = PerIsolateData::Get(isolate); |
496 int index = data->RealmIndexOrThrow(args, 0); | 502 int index = data->RealmIndexOrThrow(args, 0); |
497 if (index == -1) return; | 503 if (index == -1) return; |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 } | 1761 } |
1756 | 1762 |
1757 } // namespace v8 | 1763 } // namespace v8 |
1758 | 1764 |
1759 | 1765 |
1760 #ifndef GOOGLE3 | 1766 #ifndef GOOGLE3 |
1761 int main(int argc, char* argv[]) { | 1767 int main(int argc, char* argv[]) { |
1762 return v8::Shell::Main(argc, argv); | 1768 return v8::Shell::Main(argc, argv); |
1763 } | 1769 } |
1764 #endif | 1770 #endif |
OLD | NEW |