| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 data_->realm_switch_ = 0; | 264 data_->realm_switch_ = 0; |
| 265 data_->realms_ = new Persistent<Context>[1]; | 265 data_->realms_ = new Persistent<Context>[1]; |
| 266 data_->realms_[0].Reset(data_->isolate_, Context::GetEntered()); | 266 data_->realms_[0].Reset(data_->isolate_, Context::GetEntered()); |
| 267 data_->realm_shared_.Clear(); | 267 data_->realm_shared_.Clear(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 PerIsolateData::RealmScope::~RealmScope() { | 271 PerIsolateData::RealmScope::~RealmScope() { |
| 272 // Drop realms to avoid keeping them alive. | 272 // Drop realms to avoid keeping them alive. |
| 273 for (int i = 0; i < data_->realm_count_; ++i) | 273 for (int i = 0; i < data_->realm_count_; ++i) |
| 274 data_->realms_[i].Dispose(data_->isolate_); | 274 data_->realms_[i].Dispose(); |
| 275 delete[] data_->realms_; | 275 delete[] data_->realms_; |
| 276 if (!data_->realm_shared_.IsEmpty()) | 276 if (!data_->realm_shared_.IsEmpty()) |
| 277 data_->realm_shared_.Dispose(data_->isolate_); | 277 data_->realm_shared_.Dispose(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 | 280 |
| 281 int PerIsolateData::RealmFind(Handle<Context> context) { | 281 int PerIsolateData::RealmFind(Handle<Context> context) { |
| 282 for (int i = 0; i < realm_count_; ++i) { | 282 for (int i = 0; i < realm_count_; ++i) { |
| 283 if (realms_[i] == context) return i; | 283 if (realms_[i] == context) return i; |
| 284 } | 284 } |
| 285 return -1; | 285 return -1; |
| 286 } | 286 } |
| 287 | 287 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 Throw("Invalid argument"); | 354 Throw("Invalid argument"); |
| 355 return; | 355 return; |
| 356 } | 356 } |
| 357 int index = args[0]->Uint32Value(); | 357 int index = args[0]->Uint32Value(); |
| 358 if (index >= data->realm_count_ || data->realms_[index].IsEmpty() || | 358 if (index >= data->realm_count_ || data->realms_[index].IsEmpty() || |
| 359 index == 0 || | 359 index == 0 || |
| 360 index == data->realm_current_ || index == data->realm_switch_) { | 360 index == data->realm_current_ || index == data->realm_switch_) { |
| 361 Throw("Invalid realm index"); | 361 Throw("Invalid realm index"); |
| 362 return; | 362 return; |
| 363 } | 363 } |
| 364 data->realms_[index].Dispose(isolate); | 364 data->realms_[index].Dispose(); |
| 365 data->realms_[index].Clear(); | 365 data->realms_[index].Clear(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 | 368 |
| 369 // Realm.switch(i) switches to the realm i for consecutive interactive inputs. | 369 // Realm.switch(i) switches to the realm i for consecutive interactive inputs. |
| 370 void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 370 void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 371 Isolate* isolate = args.GetIsolate(); | 371 Isolate* isolate = args.GetIsolate(); |
| 372 PerIsolateData* data = PerIsolateData::Get(isolate); | 372 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 373 if (args.Length() < 1 || !args[0]->IsNumber()) { | 373 if (args.Length() < 1 || !args[0]->IsNumber()) { |
| 374 Throw("Invalid argument"); | 374 Throw("Invalid argument"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 PerIsolateData* data = PerIsolateData::Get(isolate); | 413 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 414 if (data->realm_shared_.IsEmpty()) return; | 414 if (data->realm_shared_.IsEmpty()) return; |
| 415 info.GetReturnValue().Set(data->realm_shared_); | 415 info.GetReturnValue().Set(data->realm_shared_); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void Shell::RealmSharedSet(Local<String> property, | 418 void Shell::RealmSharedSet(Local<String> property, |
| 419 Local<Value> value, | 419 Local<Value> value, |
| 420 const PropertyCallbackInfo<void>& info) { | 420 const PropertyCallbackInfo<void>& info) { |
| 421 Isolate* isolate = info.GetIsolate(); | 421 Isolate* isolate = info.GetIsolate(); |
| 422 PerIsolateData* data = PerIsolateData::Get(isolate); | 422 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 423 if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate); | 423 if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(); |
| 424 data->realm_shared_.Reset(isolate, value); | 424 data->realm_shared_.Reset(isolate, value); |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 void Shell::Print(const v8::FunctionCallbackInfo<v8::Value>& args) { | 428 void Shell::Print(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 429 Write(args); | 429 Write(args); |
| 430 printf("\n"); | 430 printf("\n"); |
| 431 fflush(stdout); | 431 fflush(stdout); |
| 432 } | 432 } |
| 433 | 433 |
| (...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 } // namespace v8 | 1730 } // namespace v8 |
| 1731 | 1731 |
| 1732 | 1732 |
| 1733 #ifndef GOOGLE3 | 1733 #ifndef GOOGLE3 |
| 1734 int main(int argc, char* argv[]) { | 1734 int main(int argc, char* argv[]) { |
| 1735 return v8::Shell::Main(argc, argv); | 1735 return v8::Shell::Main(argc, argv); |
| 1736 } | 1736 } |
| 1737 #endif | 1737 #endif |
| OLD | NEW |