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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 return ThrowException(String::New(message)); | 76 return ThrowException(String::New(message)); |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 // TODO(rossberg): should replace these by proper uses of HasInstance, | 80 // TODO(rossberg): should replace these by proper uses of HasInstance, |
81 // once we figure out a good way to make the templates global. | 81 // once we figure out a good way to make the templates global. |
82 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; | 82 const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; |
83 const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; | 83 const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; |
84 | 84 |
85 | 85 |
86 #define FOR_EACH_SYMBOL(V) \ | 86 #define FOR_EACH_STRING(V) \ |
87 V(ArrayBuffer, "ArrayBuffer") \ | 87 V(ArrayBuffer, "ArrayBuffer") \ |
88 V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \ | 88 V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \ |
89 V(ArrayMarkerPropName, kArrayMarkerPropName) \ | 89 V(ArrayMarkerPropName, kArrayMarkerPropName) \ |
90 V(buffer, "buffer") \ | 90 V(buffer, "buffer") \ |
91 V(byteLength, "byteLength") \ | 91 V(byteLength, "byteLength") \ |
92 V(byteOffset, "byteOffset") \ | 92 V(byteOffset, "byteOffset") \ |
93 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ | 93 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ |
94 V(length, "length") | 94 V(length, "length") |
95 | 95 |
96 | 96 |
97 class Symbols { | 97 class PerIsolateData { |
98 public: | 98 public: |
99 explicit Symbols(Isolate* isolate) : isolate_(isolate) { | 99 explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { |
100 HandleScope scope(isolate); | 100 HandleScope scope(isolate); |
101 #define INIT_SYMBOL(name, value) \ | 101 #define INIT_STRING(name, value) \ |
102 name##_ = Persistent<String>::New(isolate, String::NewSymbol(value)); | 102 name##_string_ = Persistent<String>::New(isolate, String::NewSymbol(value)); |
103 FOR_EACH_SYMBOL(INIT_SYMBOL) | 103 FOR_EACH_STRING(INIT_STRING) |
104 #undef INIT_SYMBOL | 104 #undef INIT_STRING |
105 isolate->SetData(this); | 105 isolate->SetData(this); |
106 } | 106 } |
107 | 107 |
108 ~Symbols() { | 108 ~PerIsolateData() { |
109 #define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_); | 109 #define DISPOSE_STRING(name, value) name##_string_.Dispose(isolate_); |
110 FOR_EACH_SYMBOL(DISPOSE_SYMBOL) | 110 FOR_EACH_STRING(DISPOSE_STRING) |
111 #undef DISPOSE_SYMBOL | 111 #undef DISPOSE_STRING |
112 isolate_->SetData(NULL); // Not really needed, just to be sure... | 112 isolate_->SetData(NULL); // Not really needed, just to be sure... |
113 } | 113 } |
114 | 114 |
115 #define DEFINE_SYMBOL_GETTER(name, value) \ | 115 inline static PerIsolateData* Get(Isolate* isolate) { |
116 static Persistent<String> name(Isolate* isolate) { \ | 116 return reinterpret_cast<PerIsolateData*>(isolate->GetData()); |
117 return reinterpret_cast<Symbols*>(isolate->GetData())->name##_; \ | |
118 } | 117 } |
119 FOR_EACH_SYMBOL(DEFINE_SYMBOL_GETTER) | 118 |
120 #undef DEFINE_SYMBOL_GETTER | 119 #define DEFINE_STRING_GETTER(name, value) \ |
| 120 static Persistent<String> name##_string(Isolate* isolate) { \ |
| 121 return Get(isolate)->name##_string_; \ |
| 122 } |
| 123 FOR_EACH_STRING(DEFINE_STRING_GETTER) |
| 124 #undef DEFINE_STRING_GETTER |
121 | 125 |
122 private: | 126 private: |
| 127 friend class Shell; |
123 Isolate* isolate_; | 128 Isolate* isolate_; |
124 #define DEFINE_MEMBER(name, value) Persistent<String> name##_; | 129 int realm_count_; |
125 FOR_EACH_SYMBOL(DEFINE_MEMBER) | 130 int realm_current_; |
| 131 int realm_switch_; |
| 132 Persistent<Context>* realms_; |
| 133 Persistent<Value> realm_shared_; |
| 134 |
| 135 #define DEFINE_MEMBER(name, value) Persistent<String> name##_string_; |
| 136 FOR_EACH_STRING(DEFINE_MEMBER) |
126 #undef DEFINE_MEMBER | 137 #undef DEFINE_MEMBER |
| 138 |
| 139 void RealmInit(); |
| 140 int RealmFind(Handle<Context> context); |
127 }; | 141 }; |
128 | 142 |
129 | 143 |
130 LineEditor *LineEditor::current_ = NULL; | 144 LineEditor *LineEditor::current_ = NULL; |
131 | 145 |
132 | 146 |
133 LineEditor::LineEditor(Type type, const char* name) | 147 LineEditor::LineEditor(Type type, const char* name) |
134 : type_(type), name_(name) { | 148 : type_(type), name_(name) { |
135 if (current_ == NULL || current_->type_ < type) current_ = this; | 149 if (current_ == NULL || current_->type_ < type) current_ = this; |
136 } | 150 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 #else | 214 #else |
201 bool FLAG_debugger = false; | 215 bool FLAG_debugger = false; |
202 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 216 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
203 HandleScope handle_scope(isolate); | 217 HandleScope handle_scope(isolate); |
204 TryCatch try_catch; | 218 TryCatch try_catch; |
205 options.script_executed = true; | 219 options.script_executed = true; |
206 if (FLAG_debugger) { | 220 if (FLAG_debugger) { |
207 // When debugging make exceptions appear to be uncaught. | 221 // When debugging make exceptions appear to be uncaught. |
208 try_catch.SetVerbose(true); | 222 try_catch.SetVerbose(true); |
209 } | 223 } |
210 Handle<Script> script = Script::Compile(source, name); | 224 Handle<Script> script = Script::New(source, name); |
211 if (script.IsEmpty()) { | 225 if (script.IsEmpty()) { |
212 // Print errors that happened during compilation. | 226 // Print errors that happened during compilation. |
213 if (report_exceptions && !FLAG_debugger) | 227 if (report_exceptions && !FLAG_debugger) |
214 ReportException(isolate, &try_catch); | 228 ReportException(isolate, &try_catch); |
215 return false; | 229 return false; |
216 } else { | 230 } else { |
| 231 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 232 Local<Context> realm = |
| 233 Local<Context>::New(data->realms_[data->realm_current_]); |
| 234 realm->Enter(); |
217 Handle<Value> result = script->Run(); | 235 Handle<Value> result = script->Run(); |
| 236 realm->Exit(); |
| 237 data->realm_current_ = data->realm_switch_; |
218 if (result.IsEmpty()) { | 238 if (result.IsEmpty()) { |
219 ASSERT(try_catch.HasCaught()); | 239 ASSERT(try_catch.HasCaught()); |
220 // Print errors that happened during execution. | 240 // Print errors that happened during execution. |
221 if (report_exceptions && !FLAG_debugger) | 241 if (report_exceptions && !FLAG_debugger) |
222 ReportException(isolate, &try_catch); | 242 ReportException(isolate, &try_catch); |
223 return false; | 243 return false; |
224 } else { | 244 } else { |
225 ASSERT(!try_catch.HasCaught()); | 245 ASSERT(!try_catch.HasCaught()); |
226 if (print_result) { | 246 if (print_result) { |
227 #if !defined(V8_SHARED) | 247 #if !defined(V8_SHARED) |
(...skipping 20 matching lines...) Expand all Loading... |
248 printf("\n"); | 268 printf("\n"); |
249 } | 269 } |
250 #endif | 270 #endif |
251 } | 271 } |
252 return true; | 272 return true; |
253 } | 273 } |
254 } | 274 } |
255 } | 275 } |
256 | 276 |
257 | 277 |
| 278 void PerIsolateData::RealmInit() { |
| 279 if (realms_ != NULL) { |
| 280 // Drop realms from previous run. |
| 281 for (int i = 0; i < realm_count_; ++i) realms_[i].Dispose(isolate_); |
| 282 delete[] realms_; |
| 283 if (!realm_shared_.IsEmpty()) realm_shared_.Dispose(isolate_); |
| 284 } |
| 285 realm_count_ = 1; |
| 286 realm_current_ = 0; |
| 287 realm_switch_ = 0; |
| 288 realms_ = new Persistent<Context>[1]; |
| 289 realms_[0] = Persistent<Context>::New(isolate_, Context::GetEntered()); |
| 290 realm_shared_.Clear(); |
| 291 } |
| 292 |
| 293 |
| 294 int PerIsolateData::RealmFind(Handle<Context> context) { |
| 295 for (int i = 0; i < realm_count_; ++i) { |
| 296 if (realms_[i] == context) return i; |
| 297 } |
| 298 return -1; |
| 299 } |
| 300 |
| 301 |
| 302 // Realm.current() returns the index of the currently active realm. |
| 303 Handle<Value> Shell::RealmCurrent(const Arguments& args) { |
| 304 Isolate* isolate = args.GetIsolate(); |
| 305 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 306 int index = data->RealmFind(Context::GetEntered()); |
| 307 if (index == -1) return Undefined(isolate); |
| 308 return Number::New(index); |
| 309 } |
| 310 |
| 311 |
| 312 // Realm.owner(o) returns the index of the realm that created o. |
| 313 Handle<Value> Shell::RealmOwner(const Arguments& args) { |
| 314 Isolate* isolate = args.GetIsolate(); |
| 315 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 316 if (args.Length() < 1 || !args[0]->IsObject()) { |
| 317 return Throw("Invalid argument"); |
| 318 } |
| 319 int index = data->RealmFind(args[0]->ToObject()->CreationContext()); |
| 320 if (index == -1) return Undefined(isolate); |
| 321 return Number::New(index); |
| 322 } |
| 323 |
| 324 |
| 325 // Realm.global(i) returns the global object of realm i. |
| 326 // (Note that properties of global objects cannot be read/written cross-realm.) |
| 327 Handle<Value> Shell::RealmGlobal(const Arguments& args) { |
| 328 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); |
| 329 if (args.Length() < 1 || !args[0]->IsNumber()) { |
| 330 return Throw("Invalid argument"); |
| 331 } |
| 332 int index = args[0]->Uint32Value(); |
| 333 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { |
| 334 return Throw("Invalid realm index"); |
| 335 } |
| 336 return data->realms_[index]->Global(); |
| 337 } |
| 338 |
| 339 |
| 340 // Realm.create() creates a new realm and returns its index. |
| 341 Handle<Value> Shell::RealmCreate(const Arguments& args) { |
| 342 Isolate* isolate = args.GetIsolate(); |
| 343 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 344 Persistent<Context>* old_realms = data->realms_; |
| 345 int index = data->realm_count_; |
| 346 data->realms_ = new Persistent<Context>[++data->realm_count_]; |
| 347 for (int i = 0; i < index; ++i) data->realms_[i] = old_realms[i]; |
| 348 delete[] old_realms; |
| 349 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
| 350 data->realms_[index] = Persistent<Context>::New( |
| 351 isolate, Context::New(isolate, NULL, global_template)); |
| 352 return Number::New(index); |
| 353 } |
| 354 |
| 355 |
| 356 // Realm.dispose(i) disposes the reference to the realm i. |
| 357 Handle<Value> Shell::RealmDispose(const Arguments& args) { |
| 358 Isolate* isolate = args.GetIsolate(); |
| 359 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 360 if (args.Length() < 1 || !args[0]->IsNumber()) { |
| 361 return Throw("Invalid argument"); |
| 362 } |
| 363 int index = args[0]->Uint32Value(); |
| 364 if (index >= data->realm_count_ || data->realms_[index].IsEmpty() || |
| 365 index == 0 || |
| 366 index == data->realm_current_ || index == data->realm_switch_) { |
| 367 return Throw("Invalid realm index"); |
| 368 } |
| 369 data->realms_[index].Dispose(isolate); |
| 370 data->realms_[index].Clear(); |
| 371 return Undefined(isolate); |
| 372 } |
| 373 |
| 374 |
| 375 // Realm.switch(i) switches to the realm i for consecutive interactive inputs. |
| 376 Handle<Value> Shell::RealmSwitch(const Arguments& args) { |
| 377 Isolate* isolate = args.GetIsolate(); |
| 378 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 379 if (args.Length() < 1 || !args[0]->IsNumber()) { |
| 380 return Throw("Invalid argument"); |
| 381 } |
| 382 int index = args[0]->Uint32Value(); |
| 383 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { |
| 384 return Throw("Invalid realm index"); |
| 385 } |
| 386 data->realm_switch_ = index; |
| 387 return Undefined(isolate); |
| 388 } |
| 389 |
| 390 |
| 391 // Realm.eval(i, s) evaluates s in realm i and returns the result. |
| 392 Handle<Value> Shell::RealmEval(const Arguments& args) { |
| 393 Isolate* isolate = args.GetIsolate(); |
| 394 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 395 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) { |
| 396 return Throw("Invalid argument"); |
| 397 } |
| 398 int index = args[0]->Uint32Value(); |
| 399 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { |
| 400 return Throw("Invalid realm index"); |
| 401 } |
| 402 Handle<Script> script = Script::New(args[1]->ToString()); |
| 403 if (script.IsEmpty()) return Undefined(isolate); |
| 404 Local<Context> realm = Local<Context>::New(data->realms_[index]); |
| 405 realm->Enter(); |
| 406 Handle<Value> result = script->Run(); |
| 407 realm->Exit(); |
| 408 return result; |
| 409 } |
| 410 |
| 411 |
| 412 // Realm.shared is an accessor for a single shared value across realms. |
| 413 Handle<Value> Shell::RealmSharedGet(Local<String> property, |
| 414 const AccessorInfo& info) { |
| 415 Isolate* isolate = info.GetIsolate(); |
| 416 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 417 if (data->realm_shared_.IsEmpty()) return Undefined(isolate); |
| 418 return data->realm_shared_; |
| 419 } |
| 420 |
| 421 void Shell::RealmSharedSet(Local<String> property, |
| 422 Local<Value> value, |
| 423 const AccessorInfo& info) { |
| 424 Isolate* isolate = info.GetIsolate(); |
| 425 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 426 if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate); |
| 427 data->realm_shared_ = Persistent<Value>::New(isolate, value); |
| 428 } |
| 429 |
| 430 |
258 Handle<Value> Shell::Print(const Arguments& args) { | 431 Handle<Value> Shell::Print(const Arguments& args) { |
259 Handle<Value> val = Write(args); | 432 Handle<Value> val = Write(args); |
260 printf("\n"); | 433 printf("\n"); |
261 fflush(stdout); | 434 fflush(stdout); |
262 return val; | 435 return val; |
263 } | 436 } |
264 | 437 |
265 | 438 |
266 Handle<Value> Shell::Write(const Arguments& args) { | 439 Handle<Value> Shell::Write(const Arguments& args) { |
267 for (int i = 0; i < args.Length(); i++) { | 440 for (int i = 0; i < args.Length(); i++) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // Make sure the total size fits into a (signed) int. | 582 // Make sure the total size fits into a (signed) int. |
410 if (length < 0 || length > kMaxSize) { | 583 if (length < 0 || length > kMaxSize) { |
411 return Throw("ArrayBuffer exceeds maximum size (2G)"); | 584 return Throw("ArrayBuffer exceeds maximum size (2G)"); |
412 } | 585 } |
413 uint8_t* data = new uint8_t[length]; | 586 uint8_t* data = new uint8_t[length]; |
414 if (data == NULL) { | 587 if (data == NULL) { |
415 return Throw("Memory allocation failed"); | 588 return Throw("Memory allocation failed"); |
416 } | 589 } |
417 memset(data, 0, length); | 590 memset(data, 0, length); |
418 | 591 |
419 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); | 592 buffer->SetHiddenValue( |
| 593 PerIsolateData::ArrayBufferMarkerPropName_string(isolate), True()); |
420 Persistent<Object> persistent_array = | 594 Persistent<Object> persistent_array = |
421 Persistent<Object>::New(isolate, buffer); | 595 Persistent<Object>::New(isolate, buffer); |
422 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); | 596 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); |
423 persistent_array.MarkIndependent(isolate); | 597 persistent_array.MarkIndependent(isolate); |
424 isolate->AdjustAmountOfExternalAllocatedMemory(length); | 598 isolate->AdjustAmountOfExternalAllocatedMemory(length); |
425 | 599 |
426 buffer->SetIndexedPropertiesToExternalArrayData( | 600 buffer->SetIndexedPropertiesToExternalArrayData( |
427 data, v8::kExternalByteArray, length); | 601 data, v8::kExternalByteArray, length); |
428 buffer->Set(Symbols::byteLength(isolate), | 602 buffer->Set(PerIsolateData::byteLength_string(isolate), |
429 Int32::New(length, isolate), | 603 Int32::New(length, isolate), |
430 ReadOnly); | 604 ReadOnly); |
431 | 605 |
432 return buffer; | 606 return buffer; |
433 } | 607 } |
434 | 608 |
435 | 609 |
436 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { | 610 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { |
437 if (!args.IsConstructCall()) { | 611 if (!args.IsConstructCall()) { |
438 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; | 612 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; |
(...skipping 24 matching lines...) Expand all Loading... |
463 int32_t element_size) { | 637 int32_t element_size) { |
464 ASSERT(element_size == 1 || element_size == 2 || | 638 ASSERT(element_size == 1 || element_size == 2 || |
465 element_size == 4 || element_size == 8); | 639 element_size == 4 || element_size == 8); |
466 ASSERT(byteLength == length * element_size); | 640 ASSERT(byteLength == length * element_size); |
467 | 641 |
468 void* data = buffer->GetIndexedPropertiesExternalArrayData(); | 642 void* data = buffer->GetIndexedPropertiesExternalArrayData(); |
469 ASSERT(data != NULL); | 643 ASSERT(data != NULL); |
470 | 644 |
471 array->SetIndexedPropertiesToExternalArrayData( | 645 array->SetIndexedPropertiesToExternalArrayData( |
472 static_cast<uint8_t*>(data) + byteOffset, type, length); | 646 static_cast<uint8_t*>(data) + byteOffset, type, length); |
473 array->SetHiddenValue(Symbols::ArrayMarkerPropName(isolate), | 647 array->SetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate), |
474 Int32::New(type, isolate)); | 648 Int32::New(type, isolate)); |
475 array->Set(Symbols::byteLength(isolate), | 649 array->Set(PerIsolateData::byteLength_string(isolate), |
476 Int32::New(byteLength, isolate), | 650 Int32::New(byteLength, isolate), |
477 ReadOnly); | 651 ReadOnly); |
478 array->Set(Symbols::byteOffset(isolate), | 652 array->Set(PerIsolateData::byteOffset_string(isolate), |
479 Int32::New(byteOffset, isolate), | 653 Int32::New(byteOffset, isolate), |
480 ReadOnly); | 654 ReadOnly); |
481 array->Set(Symbols::length(isolate), | 655 array->Set(PerIsolateData::length_string(isolate), |
482 Int32::New(length, isolate), | 656 Int32::New(length, isolate), |
483 ReadOnly); | 657 ReadOnly); |
484 array->Set(Symbols::BYTES_PER_ELEMENT(isolate), | 658 array->Set(PerIsolateData::BYTES_PER_ELEMENT_string(isolate), |
485 Int32::New(element_size, isolate)); | 659 Int32::New(element_size, isolate)); |
486 array->Set(Symbols::buffer(isolate), | 660 array->Set(PerIsolateData::buffer_string(isolate), |
487 buffer, | 661 buffer, |
488 ReadOnly); | 662 ReadOnly); |
489 | 663 |
490 return array; | 664 return array; |
491 } | 665 } |
492 | 666 |
493 | 667 |
494 Handle<Value> Shell::CreateExternalArray(const Arguments& args, | 668 Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
495 ExternalArrayType type, | 669 ExternalArrayType type, |
496 int32_t element_size) { | 670 int32_t element_size) { |
(...skipping 20 matching lines...) Expand all Loading... |
517 Handle<Object> buffer; | 691 Handle<Object> buffer; |
518 int32_t length; | 692 int32_t length; |
519 int32_t byteLength; | 693 int32_t byteLength; |
520 int32_t byteOffset; | 694 int32_t byteOffset; |
521 bool init_from_array = false; | 695 bool init_from_array = false; |
522 if (args.Length() == 0) { | 696 if (args.Length() == 0) { |
523 return Throw("Array constructor must have at least one argument"); | 697 return Throw("Array constructor must have at least one argument"); |
524 } | 698 } |
525 if (args[0]->IsObject() && | 699 if (args[0]->IsObject() && |
526 !args[0]->ToObject()->GetHiddenValue( | 700 !args[0]->ToObject()->GetHiddenValue( |
527 Symbols::ArrayBufferMarkerPropName(isolate)).IsEmpty()) { | 701 PerIsolateData::ArrayBufferMarkerPropName_string(isolate)).IsEmpty()) { |
528 // Construct from ArrayBuffer. | 702 // Construct from ArrayBuffer. |
529 buffer = args[0]->ToObject(); | 703 buffer = args[0]->ToObject(); |
530 int32_t bufferLength = | 704 int32_t bufferLength = convertToUint( |
531 convertToUint(buffer->Get(Symbols::byteLength(isolate)), &try_catch); | 705 buffer->Get(PerIsolateData::byteLength_string(isolate)), &try_catch); |
532 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 706 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
533 | 707 |
534 if (args.Length() < 2 || args[1]->IsUndefined()) { | 708 if (args.Length() < 2 || args[1]->IsUndefined()) { |
535 byteOffset = 0; | 709 byteOffset = 0; |
536 } else { | 710 } else { |
537 byteOffset = convertToUint(args[1], &try_catch); | 711 byteOffset = convertToUint(args[1], &try_catch); |
538 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 712 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
539 if (byteOffset > bufferLength) { | 713 if (byteOffset > bufferLength) { |
540 return Throw("byteOffset out of bounds"); | 714 return Throw("byteOffset out of bounds"); |
541 } | 715 } |
(...skipping 11 matching lines...) Expand all Loading... |
553 } else { | 727 } else { |
554 length = convertToUint(args[2], &try_catch); | 728 length = convertToUint(args[2], &try_catch); |
555 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 729 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
556 byteLength = length * element_size; | 730 byteLength = length * element_size; |
557 if (byteOffset + byteLength > bufferLength) { | 731 if (byteOffset + byteLength > bufferLength) { |
558 return Throw("length out of bounds"); | 732 return Throw("length out of bounds"); |
559 } | 733 } |
560 } | 734 } |
561 } else { | 735 } else { |
562 if (args[0]->IsObject() && | 736 if (args[0]->IsObject() && |
563 args[0]->ToObject()->Has(Symbols::length(isolate))) { | 737 args[0]->ToObject()->Has(PerIsolateData::length_string(isolate))) { |
564 // Construct from array. | 738 // Construct from array. |
565 Local<Value> value = args[0]->ToObject()->Get(Symbols::length(isolate)); | 739 Local<Value> value = |
| 740 args[0]->ToObject()->Get(PerIsolateData::length_string(isolate)); |
566 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 741 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
567 length = convertToUint(value, &try_catch); | 742 length = convertToUint(value, &try_catch); |
568 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 743 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
569 init_from_array = true; | 744 init_from_array = true; |
570 } else { | 745 } else { |
571 // Construct from size. | 746 // Construct from size. |
572 length = convertToUint(args[0], &try_catch); | 747 length = convertToUint(args[0], &try_catch); |
573 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 748 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
574 } | 749 } |
575 byteLength = length * element_size; | 750 byteLength = length * element_size; |
576 byteOffset = 0; | 751 byteOffset = 0; |
577 | 752 |
578 Handle<Object> global = Context::GetCurrent()->Global(); | 753 Handle<Object> global = Context::GetCurrent()->Global(); |
579 Handle<Value> array_buffer = global->Get(Symbols::ArrayBuffer(isolate)); | 754 Handle<Value> array_buffer = |
| 755 global->Get(PerIsolateData::ArrayBuffer_string(isolate)); |
580 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); | 756 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); |
581 Handle<Value> buffer_args[] = { Uint32::New(byteLength, isolate) }; | 757 Handle<Value> buffer_args[] = { Uint32::New(byteLength, isolate) }; |
582 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( | 758 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( |
583 1, buffer_args); | 759 1, buffer_args); |
584 if (try_catch.HasCaught()) return result; | 760 if (try_catch.HasCaught()) return result; |
585 buffer = result->ToObject(); | 761 buffer = result->ToObject(); |
586 } | 762 } |
587 | 763 |
588 Handle<Object> array = | 764 Handle<Object> array = |
589 CreateExternalArray(isolate, args.This(), buffer, type, length, | 765 CreateExternalArray(isolate, args.This(), buffer, type, length, |
(...skipping 14 matching lines...) Expand all Loading... |
604 | 780 |
605 Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) { | 781 Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) { |
606 TryCatch try_catch; | 782 TryCatch try_catch; |
607 | 783 |
608 if (!args.This()->IsObject()) { | 784 if (!args.This()->IsObject()) { |
609 return Throw("'slice' invoked on non-object receiver"); | 785 return Throw("'slice' invoked on non-object receiver"); |
610 } | 786 } |
611 | 787 |
612 Isolate* isolate = args.GetIsolate(); | 788 Isolate* isolate = args.GetIsolate(); |
613 Local<Object> self = args.This(); | 789 Local<Object> self = args.This(); |
614 Local<Value> marker = | 790 Local<Value> marker = self->GetHiddenValue( |
615 self->GetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate)); | 791 PerIsolateData::ArrayBufferMarkerPropName_string(isolate)); |
616 if (marker.IsEmpty()) { | 792 if (marker.IsEmpty()) { |
617 return Throw("'slice' invoked on wrong receiver type"); | 793 return Throw("'slice' invoked on wrong receiver type"); |
618 } | 794 } |
619 | 795 |
620 int32_t length = | 796 int32_t length = convertToUint( |
621 convertToUint(self->Get(Symbols::byteLength(isolate)), &try_catch); | 797 self->Get(PerIsolateData::byteLength_string(isolate)), &try_catch); |
622 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 798 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
623 | 799 |
624 if (args.Length() == 0) { | 800 if (args.Length() == 0) { |
625 return Throw("'slice' must have at least one argument"); | 801 return Throw("'slice' must have at least one argument"); |
626 } | 802 } |
627 int32_t begin = convertToInt(args[0], &try_catch); | 803 int32_t begin = convertToInt(args[0], &try_catch); |
628 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 804 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
629 if (begin < 0) begin += length; | 805 if (begin < 0) begin += length; |
630 if (begin < 0) begin = 0; | 806 if (begin < 0) begin = 0; |
631 if (begin > length) begin = length; | 807 if (begin > length) begin = length; |
(...skipping 28 matching lines...) Expand all Loading... |
660 Handle<Value> Shell::ArraySubArray(const Arguments& args) { | 836 Handle<Value> Shell::ArraySubArray(const Arguments& args) { |
661 TryCatch try_catch; | 837 TryCatch try_catch; |
662 | 838 |
663 if (!args.This()->IsObject()) { | 839 if (!args.This()->IsObject()) { |
664 return Throw("'subarray' invoked on non-object receiver"); | 840 return Throw("'subarray' invoked on non-object receiver"); |
665 } | 841 } |
666 | 842 |
667 Isolate* isolate = args.GetIsolate(); | 843 Isolate* isolate = args.GetIsolate(); |
668 Local<Object> self = args.This(); | 844 Local<Object> self = args.This(); |
669 Local<Value> marker = | 845 Local<Value> marker = |
670 self->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate)); | 846 self->GetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate)); |
671 if (marker.IsEmpty()) { | 847 if (marker.IsEmpty()) { |
672 return Throw("'subarray' invoked on wrong receiver type"); | 848 return Throw("'subarray' invoked on wrong receiver type"); |
673 } | 849 } |
674 | 850 |
675 Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject(); | 851 Handle<Object> buffer = |
| 852 self->Get(PerIsolateData::buffer_string(isolate))->ToObject(); |
676 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 853 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
677 int32_t length = | 854 int32_t length = convertToUint( |
678 convertToUint(self->Get(Symbols::length(isolate)), &try_catch); | 855 self->Get(PerIsolateData::length_string(isolate)), &try_catch); |
679 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 856 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
680 int32_t byteOffset = | 857 int32_t byteOffset = convertToUint( |
681 convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch); | 858 self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); |
682 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 859 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
683 int32_t element_size = | 860 int32_t element_size = convertToUint( |
684 convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT(isolate)), &try_catch); | 861 self->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), &try_catch); |
685 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 862 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
686 | 863 |
687 if (args.Length() == 0) { | 864 if (args.Length() == 0) { |
688 return Throw("'subarray' must have at least one argument"); | 865 return Throw("'subarray' must have at least one argument"); |
689 } | 866 } |
690 int32_t begin = convertToInt(args[0], &try_catch); | 867 int32_t begin = convertToInt(args[0], &try_catch); |
691 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 868 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
692 if (begin < 0) begin += length; | 869 if (begin < 0) begin += length; |
693 if (begin < 0) begin = 0; | 870 if (begin < 0) begin = 0; |
694 if (begin > length) begin = length; | 871 if (begin > length) begin = length; |
(...skipping 24 matching lines...) Expand all Loading... |
719 Handle<Value> Shell::ArraySet(const Arguments& args) { | 896 Handle<Value> Shell::ArraySet(const Arguments& args) { |
720 TryCatch try_catch; | 897 TryCatch try_catch; |
721 | 898 |
722 if (!args.This()->IsObject()) { | 899 if (!args.This()->IsObject()) { |
723 return Throw("'set' invoked on non-object receiver"); | 900 return Throw("'set' invoked on non-object receiver"); |
724 } | 901 } |
725 | 902 |
726 Isolate* isolate = args.GetIsolate(); | 903 Isolate* isolate = args.GetIsolate(); |
727 Local<Object> self = args.This(); | 904 Local<Object> self = args.This(); |
728 Local<Value> marker = | 905 Local<Value> marker = |
729 self->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate)); | 906 self->GetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate)); |
730 if (marker.IsEmpty()) { | 907 if (marker.IsEmpty()) { |
731 return Throw("'set' invoked on wrong receiver type"); | 908 return Throw("'set' invoked on wrong receiver type"); |
732 } | 909 } |
733 int32_t length = | 910 int32_t length = convertToUint( |
734 convertToUint(self->Get(Symbols::length(isolate)), &try_catch); | 911 self->Get(PerIsolateData::length_string(isolate)), &try_catch); |
735 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 912 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
736 int32_t element_size = | 913 int32_t element_size = convertToUint( |
737 convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT(isolate)), &try_catch); | 914 self->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), &try_catch); |
738 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 915 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
739 | 916 |
740 if (args.Length() == 0) { | 917 if (args.Length() == 0) { |
741 return Throw("'set' must have at least one argument"); | 918 return Throw("'set' must have at least one argument"); |
742 } | 919 } |
743 if (!args[0]->IsObject() || | 920 if (!args[0]->IsObject() || |
744 !args[0]->ToObject()->Has(Symbols::length(isolate))) { | 921 !args[0]->ToObject()->Has(PerIsolateData::length_string(isolate))) { |
745 return Throw("'set' invoked with non-array argument"); | 922 return Throw("'set' invoked with non-array argument"); |
746 } | 923 } |
747 Handle<Object> source = args[0]->ToObject(); | 924 Handle<Object> source = args[0]->ToObject(); |
748 int32_t source_length = | 925 int32_t source_length = convertToUint( |
749 convertToUint(source->Get(Symbols::length(isolate)), &try_catch); | 926 source->Get(PerIsolateData::length_string(isolate)), &try_catch); |
750 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 927 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
751 | 928 |
752 int32_t offset; | 929 int32_t offset; |
753 if (args.Length() < 2 || args[1]->IsUndefined()) { | 930 if (args.Length() < 2 || args[1]->IsUndefined()) { |
754 offset = 0; | 931 offset = 0; |
755 } else { | 932 } else { |
756 offset = convertToUint(args[1], &try_catch); | 933 offset = convertToUint(args[1], &try_catch); |
757 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 934 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
758 } | 935 } |
759 if (offset + source_length > length) { | 936 if (offset + source_length > length) { |
760 return Throw("offset or source length out of bounds"); | 937 return Throw("offset or source length out of bounds"); |
761 } | 938 } |
762 | 939 |
763 int32_t source_element_size; | 940 int32_t source_element_size; |
764 if (source->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate)).IsEmpty()) { | 941 if (source->GetHiddenValue( |
| 942 PerIsolateData::ArrayMarkerPropName_string(isolate)).IsEmpty()) { |
765 source_element_size = 0; | 943 source_element_size = 0; |
766 } else { | 944 } else { |
767 source_element_size = | 945 source_element_size = convertToUint( |
768 convertToUint(source->Get(Symbols::BYTES_PER_ELEMENT(isolate)), | 946 source->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), |
769 &try_catch); | 947 &try_catch); |
770 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 948 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
771 } | 949 } |
772 | 950 |
773 if (element_size == source_element_size && | 951 if (element_size == source_element_size && |
774 self->GetConstructor()->StrictEquals(source->GetConstructor())) { | 952 self->GetConstructor()->StrictEquals(source->GetConstructor())) { |
775 // Use memmove on the array buffers. | 953 // Use memmove on the array buffers. |
776 Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject(); | 954 Handle<Object> buffer = |
| 955 self->Get(PerIsolateData::buffer_string(isolate))->ToObject(); |
777 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 956 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
778 Handle<Object> source_buffer = | 957 Handle<Object> source_buffer = |
779 source->Get(Symbols::buffer(isolate))->ToObject(); | 958 source->Get(PerIsolateData::buffer_string(isolate))->ToObject(); |
780 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 959 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
781 int32_t byteOffset = | 960 int32_t byteOffset = convertToUint( |
782 convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch); | 961 self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); |
783 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 962 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
784 int32_t source_byteOffset = | 963 int32_t source_byteOffset = convertToUint( |
785 convertToUint(source->Get(Symbols::byteOffset(isolate)), &try_catch); | 964 source->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); |
786 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 965 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
787 | 966 |
788 uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>( | 967 uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>( |
789 buffer->GetIndexedPropertiesExternalArrayData()); | 968 buffer->GetIndexedPropertiesExternalArrayData()); |
790 uint8_t* src = source_byteOffset + static_cast<uint8_t*>( | 969 uint8_t* src = source_byteOffset + static_cast<uint8_t*>( |
791 source_buffer->GetIndexedPropertiesExternalArrayData()); | 970 source_buffer->GetIndexedPropertiesExternalArrayData()); |
792 memmove(dest, src, source_length * element_size); | 971 memmove(dest, src, source_length * element_size); |
793 } else if (source_element_size == 0) { | 972 } else if (source_element_size == 0) { |
794 // Source is not a typed array, copy element-wise sequentially. | 973 // Source is not a typed array, copy element-wise sequentially. |
795 for (int i = 0; i < source_length; ++i) { | 974 for (int i = 0; i < source_length; ++i) { |
796 self->Set(offset + i, source->Get(i)); | 975 self->Set(offset + i, source->Get(i)); |
797 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 976 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
798 } | 977 } |
799 } else { | 978 } else { |
800 // Need to copy element-wise to make the right conversions. | 979 // Need to copy element-wise to make the right conversions. |
801 Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject(); | 980 Handle<Object> buffer = |
| 981 self->Get(PerIsolateData::buffer_string(isolate))->ToObject(); |
802 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 982 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
803 Handle<Object> source_buffer = | 983 Handle<Object> source_buffer = |
804 source->Get(Symbols::buffer(isolate))->ToObject(); | 984 source->Get(PerIsolateData::buffer_string(isolate))->ToObject(); |
805 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 985 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
806 | 986 |
807 if (buffer->StrictEquals(source_buffer)) { | 987 if (buffer->StrictEquals(source_buffer)) { |
808 // Same backing store, need to handle overlap correctly. | 988 // Same backing store, need to handle overlap correctly. |
809 // This gets a bit tricky in the case of different element sizes | 989 // This gets a bit tricky in the case of different element sizes |
810 // (which, of course, is extremely unlikely to ever occur in practice). | 990 // (which, of course, is extremely unlikely to ever occur in practice). |
811 int32_t byteOffset = | 991 int32_t byteOffset = convertToUint( |
812 convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch); | 992 self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); |
813 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 993 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
814 int32_t source_byteOffset = | 994 int32_t source_byteOffset = convertToUint( |
815 convertToUint(source->Get(Symbols::byteOffset(isolate)), &try_catch); | 995 source->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); |
816 if (try_catch.HasCaught()) return try_catch.ReThrow(); | 996 if (try_catch.HasCaught()) return try_catch.ReThrow(); |
817 | 997 |
818 // Copy as much as we can from left to right. | 998 // Copy as much as we can from left to right. |
819 int i = 0; | 999 int i = 0; |
820 int32_t next_dest_offset = byteOffset + (offset + 1) * element_size; | 1000 int32_t next_dest_offset = byteOffset + (offset + 1) * element_size; |
821 int32_t next_src_offset = source_byteOffset + source_element_size; | 1001 int32_t next_src_offset = source_byteOffset + source_element_size; |
822 while (i < length && next_dest_offset <= next_src_offset) { | 1002 while (i < length && next_dest_offset <= next_src_offset) { |
823 self->Set(offset + i, source->Get(i)); | 1003 self->Set(offset + i, source->Get(i)); |
824 ++i; | 1004 ++i; |
825 next_dest_offset += element_size; | 1005 next_dest_offset += element_size; |
(...skipping 27 matching lines...) Expand all Loading... |
853 } | 1033 } |
854 | 1034 |
855 return Undefined(args.GetIsolate()); | 1035 return Undefined(args.GetIsolate()); |
856 } | 1036 } |
857 | 1037 |
858 | 1038 |
859 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, | 1039 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, |
860 Persistent<Value> object, | 1040 Persistent<Value> object, |
861 void* data) { | 1041 void* data) { |
862 HandleScope scope(isolate); | 1042 HandleScope scope(isolate); |
863 int32_t length = | 1043 int32_t length = object->ToObject()->Get( |
864 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); | 1044 PerIsolateData::byteLength_string(isolate))->Uint32Value(); |
865 isolate->AdjustAmountOfExternalAllocatedMemory(-length); | 1045 isolate->AdjustAmountOfExternalAllocatedMemory(-length); |
866 delete[] static_cast<uint8_t*>(data); | 1046 delete[] static_cast<uint8_t*>(data); |
867 object.Dispose(isolate); | 1047 object.Dispose(isolate); |
868 } | 1048 } |
869 | 1049 |
870 | 1050 |
871 Handle<Value> Shell::Int8Array(const Arguments& args) { | 1051 Handle<Value> Shell::Int8Array(const Arguments& args) { |
872 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); | 1052 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); |
873 } | 1053 } |
874 | 1054 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 global_template->Set(String::New("readline"), | 1411 global_template->Set(String::New("readline"), |
1232 FunctionTemplate::New(ReadLine)); | 1412 FunctionTemplate::New(ReadLine)); |
1233 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); | 1413 global_template->Set(String::New("load"), FunctionTemplate::New(Load)); |
1234 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); | 1414 global_template->Set(String::New("quit"), FunctionTemplate::New(Quit)); |
1235 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); | 1415 global_template->Set(String::New("version"), FunctionTemplate::New(Version)); |
1236 global_template->Set(String::New("enableProfiler"), | 1416 global_template->Set(String::New("enableProfiler"), |
1237 FunctionTemplate::New(EnableProfiler)); | 1417 FunctionTemplate::New(EnableProfiler)); |
1238 global_template->Set(String::New("disableProfiler"), | 1418 global_template->Set(String::New("disableProfiler"), |
1239 FunctionTemplate::New(DisableProfiler)); | 1419 FunctionTemplate::New(DisableProfiler)); |
1240 | 1420 |
| 1421 // Bind the Realm object. |
| 1422 Handle<ObjectTemplate> realm_template = ObjectTemplate::New(); |
| 1423 realm_template->Set(String::New("current"), |
| 1424 FunctionTemplate::New(RealmCurrent)); |
| 1425 realm_template->Set(String::New("owner"), |
| 1426 FunctionTemplate::New(RealmOwner)); |
| 1427 realm_template->Set(String::New("global"), |
| 1428 FunctionTemplate::New(RealmGlobal)); |
| 1429 realm_template->Set(String::New("create"), |
| 1430 FunctionTemplate::New(RealmCreate)); |
| 1431 realm_template->Set(String::New("dispose"), |
| 1432 FunctionTemplate::New(RealmDispose)); |
| 1433 realm_template->Set(String::New("switch"), |
| 1434 FunctionTemplate::New(RealmSwitch)); |
| 1435 realm_template->Set(String::New("eval"), |
| 1436 FunctionTemplate::New(RealmEval)); |
| 1437 realm_template->SetAccessor(String::New("shared"), |
| 1438 RealmSharedGet, RealmSharedSet); |
| 1439 global_template->Set(String::New("Realm"), realm_template); |
| 1440 |
1241 // Bind the handlers for external arrays. | 1441 // Bind the handlers for external arrays. |
1242 PropertyAttribute attr = | 1442 PropertyAttribute attr = |
1243 static_cast<PropertyAttribute>(ReadOnly | DontDelete); | 1443 static_cast<PropertyAttribute>(ReadOnly | DontDelete); |
1244 global_template->Set(Symbols::ArrayBuffer(isolate), | 1444 global_template->Set(PerIsolateData::ArrayBuffer_string(isolate), |
1245 CreateArrayBufferTemplate(ArrayBuffer), attr); | 1445 CreateArrayBufferTemplate(ArrayBuffer), attr); |
1246 global_template->Set(String::New("Int8Array"), | 1446 global_template->Set(String::New("Int8Array"), |
1247 CreateArrayTemplate(Int8Array), attr); | 1447 CreateArrayTemplate(Int8Array), attr); |
1248 global_template->Set(String::New("Uint8Array"), | 1448 global_template->Set(String::New("Uint8Array"), |
1249 CreateArrayTemplate(Uint8Array), attr); | 1449 CreateArrayTemplate(Uint8Array), attr); |
1250 global_template->Set(String::New("Int16Array"), | 1450 global_template->Set(String::New("Int16Array"), |
1251 CreateArrayTemplate(Int16Array), attr); | 1451 CreateArrayTemplate(Int16Array), attr); |
1252 global_template->Set(String::New("Uint16Array"), | 1452 global_template->Set(String::New("Uint16Array"), |
1253 CreateArrayTemplate(Uint16Array), attr); | 1453 CreateArrayTemplate(Uint16Array), attr); |
1254 global_template->Set(String::New("Int32Array"), | 1454 global_template->Set(String::New("Int32Array"), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 1518 Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
1319 #ifndef V8_SHARED | 1519 #ifndef V8_SHARED |
1320 // This needs to be a critical section since this is not thread-safe | 1520 // This needs to be a critical section since this is not thread-safe |
1321 i::ScopedLock lock(context_mutex_); | 1521 i::ScopedLock lock(context_mutex_); |
1322 #endif // V8_SHARED | 1522 #endif // V8_SHARED |
1323 // Initialize the global objects | 1523 // Initialize the global objects |
1324 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1524 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
1325 Persistent<Context> context = Context::New(NULL, global_template); | 1525 Persistent<Context> context = Context::New(NULL, global_template); |
1326 ASSERT(!context.IsEmpty()); | 1526 ASSERT(!context.IsEmpty()); |
1327 Context::Scope scope(context); | 1527 Context::Scope scope(context); |
| 1528 PerIsolateData::Get(isolate)->RealmInit(); |
1328 | 1529 |
1329 #ifndef V8_SHARED | 1530 #ifndef V8_SHARED |
1330 i::JSArguments js_args = i::FLAG_js_arguments; | 1531 i::JSArguments js_args = i::FLAG_js_arguments; |
1331 i::Handle<i::FixedArray> arguments_array = | 1532 i::Handle<i::FixedArray> arguments_array = |
1332 FACTORY->NewFixedArray(js_args.argc()); | 1533 FACTORY->NewFixedArray(js_args.argc()); |
1333 for (int j = 0; j < js_args.argc(); j++) { | 1534 for (int j = 0; j < js_args.argc(); j++) { |
1334 i::Handle<i::String> arg = | 1535 i::Handle<i::String> arg = |
1335 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 1536 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
1336 arguments_array->set(j, *arg); | 1537 arguments_array->set(j, *arg); |
1337 } | 1538 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 return Throw("Error loading file"); | 1663 return Throw("Error loading file"); |
1463 } | 1664 } |
1464 | 1665 |
1465 uint8_t* data = reinterpret_cast<uint8_t*>( | 1666 uint8_t* data = reinterpret_cast<uint8_t*>( |
1466 ReadChars(args.GetIsolate(), *filename, &length)); | 1667 ReadChars(args.GetIsolate(), *filename, &length)); |
1467 if (data == NULL) { | 1668 if (data == NULL) { |
1468 return Throw("Error reading file"); | 1669 return Throw("Error reading file"); |
1469 } | 1670 } |
1470 Isolate* isolate = args.GetIsolate(); | 1671 Isolate* isolate = args.GetIsolate(); |
1471 Handle<Object> buffer = Object::New(); | 1672 Handle<Object> buffer = Object::New(); |
1472 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); | 1673 buffer->SetHiddenValue( |
| 1674 PerIsolateData::ArrayBufferMarkerPropName_string(isolate), True()); |
1473 Persistent<Object> persistent_buffer = | 1675 Persistent<Object> persistent_buffer = |
1474 Persistent<Object>::New(isolate, buffer); | 1676 Persistent<Object>::New(isolate, buffer); |
1475 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); | 1677 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); |
1476 persistent_buffer.MarkIndependent(isolate); | 1678 persistent_buffer.MarkIndependent(isolate); |
1477 isolate->AdjustAmountOfExternalAllocatedMemory(length); | 1679 isolate->AdjustAmountOfExternalAllocatedMemory(length); |
1478 | 1680 |
1479 buffer->SetIndexedPropertiesToExternalArrayData( | 1681 buffer->SetIndexedPropertiesToExternalArrayData( |
1480 data, kExternalUnsignedByteArray, length); | 1682 data, kExternalUnsignedByteArray, length); |
1481 buffer->Set(Symbols::byteLength(isolate), | 1683 buffer->Set(PerIsolateData::byteLength_string(isolate), |
1482 Int32::New(static_cast<int32_t>(length), isolate), ReadOnly); | 1684 Int32::New(static_cast<int32_t>(length), isolate), ReadOnly); |
1483 return buffer; | 1685 return buffer; |
1484 } | 1686 } |
1485 | 1687 |
1486 | 1688 |
1487 #ifndef V8_SHARED | 1689 #ifndef V8_SHARED |
1488 static char* ReadToken(char* data, char token) { | 1690 static char* ReadToken(char* data, char token) { |
1489 char* next = i::OS::StrChr(data, token); | 1691 char* next = i::OS::StrChr(data, token); |
1490 if (next != NULL) { | 1692 if (next != NULL) { |
1491 *next = '\0'; | 1693 *next = '\0'; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 | 1866 |
1665 | 1867 |
1666 void SourceGroup::ExecuteInThread() { | 1868 void SourceGroup::ExecuteInThread() { |
1667 Isolate* isolate = Isolate::New(); | 1869 Isolate* isolate = Isolate::New(); |
1668 do { | 1870 do { |
1669 if (next_semaphore_ != NULL) next_semaphore_->Wait(); | 1871 if (next_semaphore_ != NULL) next_semaphore_->Wait(); |
1670 { | 1872 { |
1671 Isolate::Scope iscope(isolate); | 1873 Isolate::Scope iscope(isolate); |
1672 Locker lock(isolate); | 1874 Locker lock(isolate); |
1673 HandleScope scope(isolate); | 1875 HandleScope scope(isolate); |
1674 Symbols symbols(isolate); | 1876 PerIsolateData data(isolate); |
1675 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); | 1877 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); |
1676 { | 1878 { |
1677 Context::Scope cscope(context); | 1879 Context::Scope cscope(context); |
1678 Execute(isolate); | 1880 Execute(isolate); |
1679 } | 1881 } |
1680 context.Dispose(isolate); | 1882 context.Dispose(isolate); |
1681 if (Shell::options.send_idle_notification) { | 1883 if (Shell::options.send_idle_notification) { |
1682 const int kLongIdlePauseInMs = 1000; | 1884 const int kLongIdlePauseInMs = 1000; |
1683 V8::ContextDisposedNotification(); | 1885 V8::ContextDisposedNotification(); |
1684 V8::IdleNotification(kLongIdlePauseInMs); | 1886 V8::IdleNotification(kLongIdlePauseInMs); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 int Shell::Main(int argc, char* argv[]) { | 2128 int Shell::Main(int argc, char* argv[]) { |
1927 if (!SetOptions(argc, argv)) return 1; | 2129 if (!SetOptions(argc, argv)) return 1; |
1928 int result = 0; | 2130 int result = 0; |
1929 Isolate* isolate = Isolate::GetCurrent(); | 2131 Isolate* isolate = Isolate::GetCurrent(); |
1930 DumbLineEditor dumb_line_editor(isolate); | 2132 DumbLineEditor dumb_line_editor(isolate); |
1931 { | 2133 { |
1932 Initialize(isolate); | 2134 Initialize(isolate); |
1933 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 2135 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
1934 vTune::InitilizeVtuneForV8(); | 2136 vTune::InitilizeVtuneForV8(); |
1935 #endif | 2137 #endif |
1936 Symbols symbols(isolate); | 2138 PerIsolateData data(isolate); |
1937 InitializeDebugger(isolate); | 2139 InitializeDebugger(isolate); |
1938 | 2140 |
1939 if (options.stress_opt || options.stress_deopt) { | 2141 if (options.stress_opt || options.stress_deopt) { |
1940 Testing::SetStressRunType(options.stress_opt | 2142 Testing::SetStressRunType(options.stress_opt |
1941 ? Testing::kStressTypeOpt | 2143 ? Testing::kStressTypeOpt |
1942 : Testing::kStressTypeDeopt); | 2144 : Testing::kStressTypeDeopt); |
1943 int stress_runs = Testing::GetStressRuns(); | 2145 int stress_runs = Testing::GetStressRuns(); |
1944 for (int i = 0; i < stress_runs && result == 0; i++) { | 2146 for (int i = 0; i < stress_runs && result == 0; i++) { |
1945 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); | 2147 printf("============ Stress %d/%d ============\n", i + 1, stress_runs); |
1946 Testing::PrepareStressRun(i); | 2148 Testing::PrepareStressRun(i); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 } | 2195 } |
1994 | 2196 |
1995 } // namespace v8 | 2197 } // namespace v8 |
1996 | 2198 |
1997 | 2199 |
1998 #ifndef GOOGLE3 | 2200 #ifndef GOOGLE3 |
1999 int main(int argc, char* argv[]) { | 2201 int main(int argc, char* argv[]) { |
2000 return v8::Shell::Main(argc, argv); | 2202 return v8::Shell::Main(argc, argv); |
2001 } | 2203 } |
2002 #endif | 2204 #endif |
OLD | NEW |