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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 V(byteOffset, "byteOffset") \ | 88 V(byteOffset, "byteOffset") \ |
89 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ | 89 V(BYTES_PER_ELEMENT, "BYTES_PER_ELEMENT") \ |
90 V(length, "length") | 90 V(length, "length") |
91 | 91 |
92 | 92 |
93 class Symbols { | 93 class Symbols { |
94 public: | 94 public: |
95 explicit Symbols(Isolate* isolate) : isolate_(isolate) { | 95 explicit Symbols(Isolate* isolate) : isolate_(isolate) { |
96 HandleScope scope; | 96 HandleScope scope; |
97 #define INIT_SYMBOL(name, value) \ | 97 #define INIT_SYMBOL(name, value) \ |
98 name##_ = Persistent<String>::New(String::NewSymbol(value)); | 98 name##_ = Persistent<String>::New(isolate, String::NewSymbol(value)); |
99 FOR_EACH_SYMBOL(INIT_SYMBOL) | 99 FOR_EACH_SYMBOL(INIT_SYMBOL) |
100 #undef INIT_SYMBOL | 100 #undef INIT_SYMBOL |
101 isolate->SetData(this); | 101 isolate->SetData(this); |
102 } | 102 } |
103 | 103 |
104 ~Symbols() { | 104 ~Symbols() { |
105 #define DISPOSE_SYMBOL(name, value) name##_.Dispose(); | 105 #define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_); |
106 FOR_EACH_SYMBOL(DISPOSE_SYMBOL) | 106 FOR_EACH_SYMBOL(DISPOSE_SYMBOL) |
107 #undef DISPOSE_SYMBOL | 107 #undef DISPOSE_SYMBOL |
108 isolate_->SetData(NULL); // Not really needed, just to be sure... | 108 isolate_->SetData(NULL); // Not really needed, just to be sure... |
109 } | 109 } |
110 | 110 |
111 #define DEFINE_SYMBOL_GETTER(name, value) \ | 111 #define DEFINE_SYMBOL_GETTER(name, value) \ |
112 static Persistent<String> name(Isolate* isolate) { \ | 112 static Persistent<String> name(Isolate* isolate) { \ |
113 return reinterpret_cast<Symbols*>(isolate->GetData())->name##_; \ | 113 return reinterpret_cast<Symbols*>(isolate->GetData())->name##_; \ |
114 } | 114 } |
115 FOR_EACH_SYMBOL(DEFINE_SYMBOL_GETTER) | 115 FOR_EACH_SYMBOL(DEFINE_SYMBOL_GETTER) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if (length < 0 || length > kMaxSize) { | 392 if (length < 0 || length > kMaxSize) { |
393 return Throw("ArrayBuffer exceeds maximum size (2G)"); | 393 return Throw("ArrayBuffer exceeds maximum size (2G)"); |
394 } | 394 } |
395 uint8_t* data = new uint8_t[length]; | 395 uint8_t* data = new uint8_t[length]; |
396 if (data == NULL) { | 396 if (data == NULL) { |
397 return Throw("Memory allocation failed"); | 397 return Throw("Memory allocation failed"); |
398 } | 398 } |
399 memset(data, 0, length); | 399 memset(data, 0, length); |
400 | 400 |
401 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); | 401 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); |
402 Persistent<Object> persistent_array = Persistent<Object>::New(buffer); | 402 Persistent<Object> persistent_array = |
403 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 403 Persistent<Object>::New(isolate, buffer); |
404 persistent_array.MarkIndependent(); | 404 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); |
| 405 persistent_array.MarkIndependent(isolate); |
405 V8::AdjustAmountOfExternalAllocatedMemory(length); | 406 V8::AdjustAmountOfExternalAllocatedMemory(length); |
406 | 407 |
407 buffer->SetIndexedPropertiesToExternalArrayData( | 408 buffer->SetIndexedPropertiesToExternalArrayData( |
408 data, v8::kExternalByteArray, length); | 409 data, v8::kExternalByteArray, length); |
409 buffer->Set(Symbols::byteLength(isolate), Int32::New(length), ReadOnly); | 410 buffer->Set(Symbols::byteLength(isolate), Int32::New(length), ReadOnly); |
410 | 411 |
411 return buffer; | 412 return buffer; |
412 } | 413 } |
413 | 414 |
414 | 415 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 // Different backing stores, safe to copy element-wise sequentially. | 820 // Different backing stores, safe to copy element-wise sequentially. |
820 for (int i = 0; i < source_length; ++i) | 821 for (int i = 0; i < source_length; ++i) |
821 self->Set(offset + i, source->Get(i)); | 822 self->Set(offset + i, source->Get(i)); |
822 } | 823 } |
823 } | 824 } |
824 | 825 |
825 return Undefined(); | 826 return Undefined(); |
826 } | 827 } |
827 | 828 |
828 | 829 |
829 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 830 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, |
| 831 Persistent<Value> object, |
| 832 void* data) { |
830 HandleScope scope; | 833 HandleScope scope; |
831 Isolate* isolate = Isolate::GetCurrent(); | |
832 int32_t length = | 834 int32_t length = |
833 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); | 835 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); |
834 V8::AdjustAmountOfExternalAllocatedMemory(-length); | 836 V8::AdjustAmountOfExternalAllocatedMemory(-length); |
835 delete[] static_cast<uint8_t*>(data); | 837 delete[] static_cast<uint8_t*>(data); |
836 object.Dispose(); | 838 object.Dispose(isolate); |
837 } | 839 } |
838 | 840 |
839 | 841 |
840 Handle<Value> Shell::Int8Array(const Arguments& args) { | 842 Handle<Value> Shell::Int8Array(const Arguments& args) { |
841 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); | 843 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); |
842 } | 844 } |
843 | 845 |
844 | 846 |
845 Handle<Value> Shell::Uint8Array(const Arguments& args) { | 847 Handle<Value> Shell::Uint8Array(const Arguments& args) { |
846 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t)); | 848 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t)); |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 } | 1437 } |
1436 | 1438 |
1437 uint8_t* data = reinterpret_cast<uint8_t*>( | 1439 uint8_t* data = reinterpret_cast<uint8_t*>( |
1438 ReadChars(args.GetIsolate(), *filename, &length)); | 1440 ReadChars(args.GetIsolate(), *filename, &length)); |
1439 if (data == NULL) { | 1441 if (data == NULL) { |
1440 return Throw("Error reading file"); | 1442 return Throw("Error reading file"); |
1441 } | 1443 } |
1442 Isolate* isolate = args.GetIsolate(); | 1444 Isolate* isolate = args.GetIsolate(); |
1443 Handle<Object> buffer = Object::New(); | 1445 Handle<Object> buffer = Object::New(); |
1444 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); | 1446 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); |
1445 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer); | 1447 Persistent<Object> persistent_buffer = |
1446 persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); | 1448 Persistent<Object>::New(isolate, buffer); |
1447 persistent_buffer.MarkIndependent(); | 1449 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); |
| 1450 persistent_buffer.MarkIndependent(isolate); |
1448 V8::AdjustAmountOfExternalAllocatedMemory(length); | 1451 V8::AdjustAmountOfExternalAllocatedMemory(length); |
1449 | 1452 |
1450 buffer->SetIndexedPropertiesToExternalArrayData( | 1453 buffer->SetIndexedPropertiesToExternalArrayData( |
1451 data, kExternalUnsignedByteArray, length); | 1454 data, kExternalUnsignedByteArray, length); |
1452 buffer->Set(Symbols::byteLength(isolate), | 1455 buffer->Set(Symbols::byteLength(isolate), |
1453 Int32::New(static_cast<int32_t>(length)), ReadOnly); | 1456 Int32::New(static_cast<int32_t>(length)), ReadOnly); |
1454 return buffer; | 1457 return buffer; |
1455 } | 1458 } |
1456 | 1459 |
1457 | 1460 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 | 1561 |
1559 Handle<String> str = Shell::ReadFile(isolate_, filename); | 1562 Handle<String> str = Shell::ReadFile(isolate_, filename); |
1560 if (str.IsEmpty()) { | 1563 if (str.IsEmpty()) { |
1561 printf("File '%s' not found\n", filename); | 1564 printf("File '%s' not found\n", filename); |
1562 Shell::Exit(1); | 1565 Shell::Exit(1); |
1563 } | 1566 } |
1564 | 1567 |
1565 Shell::ExecuteString(str, String::New(filename), false, false); | 1568 Shell::ExecuteString(str, String::New(filename), false, false); |
1566 } | 1569 } |
1567 | 1570 |
1568 thread_context.Dispose(); | 1571 thread_context.Dispose(thread_context->GetIsolate()); |
1569 ptr = next_line; | 1572 ptr = next_line; |
1570 } | 1573 } |
1571 } | 1574 } |
1572 #endif // V8_SHARED | 1575 #endif // V8_SHARED |
1573 | 1576 |
1574 | 1577 |
1575 SourceGroup::~SourceGroup() { | 1578 SourceGroup::~SourceGroup() { |
1576 #ifndef V8_SHARED | 1579 #ifndef V8_SHARED |
1577 delete next_semaphore_; | 1580 delete next_semaphore_; |
1578 next_semaphore_ = NULL; | 1581 next_semaphore_ = NULL; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 { | 1645 { |
1643 Isolate::Scope iscope(isolate); | 1646 Isolate::Scope iscope(isolate); |
1644 Locker lock(isolate); | 1647 Locker lock(isolate); |
1645 HandleScope scope; | 1648 HandleScope scope; |
1646 Symbols symbols(isolate); | 1649 Symbols symbols(isolate); |
1647 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); | 1650 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); |
1648 { | 1651 { |
1649 Context::Scope cscope(context); | 1652 Context::Scope cscope(context); |
1650 Execute(isolate); | 1653 Execute(isolate); |
1651 } | 1654 } |
1652 context.Dispose(); | 1655 context.Dispose(isolate); |
1653 if (Shell::options.send_idle_notification) { | 1656 if (Shell::options.send_idle_notification) { |
1654 const int kLongIdlePauseInMs = 1000; | 1657 const int kLongIdlePauseInMs = 1000; |
1655 V8::ContextDisposedNotification(); | 1658 V8::ContextDisposedNotification(); |
1656 V8::IdleNotification(kLongIdlePauseInMs); | 1659 V8::IdleNotification(kLongIdlePauseInMs); |
1657 } | 1660 } |
1658 } | 1661 } |
1659 if (done_semaphore_ != NULL) done_semaphore_->Signal(); | 1662 if (done_semaphore_ != NULL) done_semaphore_->Signal(); |
1660 } while (!Shell::options.last_run); | 1663 } while (!Shell::options.last_run); |
1661 isolate->Dispose(); | 1664 isolate->Dispose(); |
1662 } | 1665 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 if (i::FLAG_debugger) { | 1854 if (i::FLAG_debugger) { |
1852 InstallUtilityScript(isolate); | 1855 InstallUtilityScript(isolate); |
1853 } | 1856 } |
1854 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1857 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
1855 } | 1858 } |
1856 { | 1859 { |
1857 Context::Scope cscope(context); | 1860 Context::Scope cscope(context); |
1858 options.isolate_sources[0].Execute(isolate); | 1861 options.isolate_sources[0].Execute(isolate); |
1859 } | 1862 } |
1860 if (!options.last_run) { | 1863 if (!options.last_run) { |
1861 context.Dispose(); | 1864 context.Dispose(isolate); |
1862 if (options.send_idle_notification) { | 1865 if (options.send_idle_notification) { |
1863 const int kLongIdlePauseInMs = 1000; | 1866 const int kLongIdlePauseInMs = 1000; |
1864 V8::ContextDisposedNotification(); | 1867 V8::ContextDisposedNotification(); |
1865 V8::IdleNotification(kLongIdlePauseInMs); | 1868 V8::IdleNotification(kLongIdlePauseInMs); |
1866 } | 1869 } |
1867 } | 1870 } |
1868 | 1871 |
1869 #ifndef V8_SHARED | 1872 #ifndef V8_SHARED |
1870 // Start preemption if threads have been created and preemption is enabled. | 1873 // Start preemption if threads have been created and preemption is enabled. |
1871 if (threads.length() > 0 | 1874 if (threads.length() > 0 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 } | 1964 } |
1962 | 1965 |
1963 } // namespace v8 | 1966 } // namespace v8 |
1964 | 1967 |
1965 | 1968 |
1966 #ifndef GOOGLE3 | 1969 #ifndef GOOGLE3 |
1967 int main(int argc, char* argv[]) { | 1970 int main(int argc, char* argv[]) { |
1968 return v8::Shell::Main(argc, argv); | 1971 return v8::Shell::Main(argc, argv); |
1969 } | 1972 } |
1970 #endif | 1973 #endif |
OLD | NEW |