Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/d8.cc

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

Powered by Google App Engine
This is Rietveld 408576698