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

Side by Side Diff: src/d8.cc

Issue 12033011: Add Isolate parameter to Persistent class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added new kind of callback Created 7 years, 11 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
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = Persistent<Object>::New(buffer);
403 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); 403 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback);
404 persistent_array.MarkIndependent(); 404 persistent_array.MarkIndependent(isolate);
405 V8::AdjustAmountOfExternalAllocatedMemory(length); 405 V8::AdjustAmountOfExternalAllocatedMemory(length);
406 406
407 buffer->SetIndexedPropertiesToExternalArrayData( 407 buffer->SetIndexedPropertiesToExternalArrayData(
408 data, v8::kExternalByteArray, length); 408 data, v8::kExternalByteArray, length);
409 buffer->Set(Symbols::byteLength(isolate), Int32::New(length), ReadOnly); 409 buffer->Set(Symbols::byteLength(isolate), Int32::New(length), ReadOnly);
410 410
411 return buffer; 411 return buffer;
412 } 412 }
413 413
414 414
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // Different backing stores, safe to copy element-wise sequentially. 819 // Different backing stores, safe to copy element-wise sequentially.
820 for (int i = 0; i < source_length; ++i) 820 for (int i = 0; i < source_length; ++i)
821 self->Set(offset + i, source->Get(i)); 821 self->Set(offset + i, source->Get(i));
822 } 822 }
823 } 823 }
824 824
825 return Undefined(); 825 return Undefined();
826 } 826 }
827 827
828 828
829 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { 829 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
830 Persistent<Value> object,
831 void* data) {
830 HandleScope scope; 832 HandleScope scope;
831 Isolate* isolate = Isolate::GetCurrent();
832 int32_t length = 833 int32_t length =
833 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); 834 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value();
834 V8::AdjustAmountOfExternalAllocatedMemory(-length); 835 V8::AdjustAmountOfExternalAllocatedMemory(-length);
835 delete[] static_cast<uint8_t*>(data); 836 delete[] static_cast<uint8_t*>(data);
836 object.Dispose(); 837 object.Dispose(isolate);
837 } 838 }
838 839
839 840
840 Handle<Value> Shell::Int8Array(const Arguments& args) { 841 Handle<Value> Shell::Int8Array(const Arguments& args) {
841 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t)); 842 return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
842 } 843 }
843 844
844 845
845 Handle<Value> Shell::Uint8Array(const Arguments& args) { 846 Handle<Value> Shell::Uint8Array(const Arguments& args) {
846 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t)); 847 return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t));
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 1437
1437 uint8_t* data = reinterpret_cast<uint8_t*>( 1438 uint8_t* data = reinterpret_cast<uint8_t*>(
1438 ReadChars(args.GetIsolate(), *filename, &length)); 1439 ReadChars(args.GetIsolate(), *filename, &length));
1439 if (data == NULL) { 1440 if (data == NULL) {
1440 return Throw("Error reading file"); 1441 return Throw("Error reading file");
1441 } 1442 }
1442 Isolate* isolate = args.GetIsolate(); 1443 Isolate* isolate = args.GetIsolate();
1443 Handle<Object> buffer = Object::New(); 1444 Handle<Object> buffer = Object::New();
1444 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); 1445 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True());
1445 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer); 1446 Persistent<Object> persistent_buffer = Persistent<Object>::New(buffer);
1446 persistent_buffer.MakeWeak(data, ExternalArrayWeakCallback); 1447 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback);
1447 persistent_buffer.MarkIndependent(); 1448 persistent_buffer.MarkIndependent(isolate);
1448 V8::AdjustAmountOfExternalAllocatedMemory(length); 1449 V8::AdjustAmountOfExternalAllocatedMemory(length);
1449 1450
1450 buffer->SetIndexedPropertiesToExternalArrayData( 1451 buffer->SetIndexedPropertiesToExternalArrayData(
1451 data, kExternalUnsignedByteArray, length); 1452 data, kExternalUnsignedByteArray, length);
1452 buffer->Set(Symbols::byteLength(isolate), 1453 buffer->Set(Symbols::byteLength(isolate),
1453 Int32::New(static_cast<int32_t>(length)), ReadOnly); 1454 Int32::New(static_cast<int32_t>(length)), ReadOnly);
1454 return buffer; 1455 return buffer;
1455 } 1456 }
1456 1457
1457 1458
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 1559
1559 Handle<String> str = Shell::ReadFile(isolate_, filename); 1560 Handle<String> str = Shell::ReadFile(isolate_, filename);
1560 if (str.IsEmpty()) { 1561 if (str.IsEmpty()) {
1561 printf("File '%s' not found\n", filename); 1562 printf("File '%s' not found\n", filename);
1562 Shell::Exit(1); 1563 Shell::Exit(1);
1563 } 1564 }
1564 1565
1565 Shell::ExecuteString(str, String::New(filename), false, false); 1566 Shell::ExecuteString(str, String::New(filename), false, false);
1566 } 1567 }
1567 1568
1568 thread_context.Dispose(); 1569 thread_context.Dispose(thread_context->GetIsolate());
1569 ptr = next_line; 1570 ptr = next_line;
1570 } 1571 }
1571 } 1572 }
1572 #endif // V8_SHARED 1573 #endif // V8_SHARED
1573 1574
1574 1575
1575 SourceGroup::~SourceGroup() { 1576 SourceGroup::~SourceGroup() {
1576 #ifndef V8_SHARED 1577 #ifndef V8_SHARED
1577 delete next_semaphore_; 1578 delete next_semaphore_;
1578 next_semaphore_ = NULL; 1579 next_semaphore_ = NULL;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 { 1643 {
1643 Isolate::Scope iscope(isolate); 1644 Isolate::Scope iscope(isolate);
1644 Locker lock(isolate); 1645 Locker lock(isolate);
1645 HandleScope scope; 1646 HandleScope scope;
1646 Symbols symbols(isolate); 1647 Symbols symbols(isolate);
1647 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); 1648 Persistent<Context> context = Shell::CreateEvaluationContext(isolate);
1648 { 1649 {
1649 Context::Scope cscope(context); 1650 Context::Scope cscope(context);
1650 Execute(isolate); 1651 Execute(isolate);
1651 } 1652 }
1652 context.Dispose(); 1653 context.Dispose(isolate);
1653 if (Shell::options.send_idle_notification) { 1654 if (Shell::options.send_idle_notification) {
1654 const int kLongIdlePauseInMs = 1000; 1655 const int kLongIdlePauseInMs = 1000;
1655 V8::ContextDisposedNotification(); 1656 V8::ContextDisposedNotification();
1656 V8::IdleNotification(kLongIdlePauseInMs); 1657 V8::IdleNotification(kLongIdlePauseInMs);
1657 } 1658 }
1658 } 1659 }
1659 if (done_semaphore_ != NULL) done_semaphore_->Signal(); 1660 if (done_semaphore_ != NULL) done_semaphore_->Signal();
1660 } while (!Shell::options.last_run); 1661 } while (!Shell::options.last_run);
1661 isolate->Dispose(); 1662 isolate->Dispose();
1662 } 1663 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 if (i::FLAG_debugger) { 1852 if (i::FLAG_debugger) {
1852 InstallUtilityScript(isolate); 1853 InstallUtilityScript(isolate);
1853 } 1854 }
1854 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 1855 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
1855 } 1856 }
1856 { 1857 {
1857 Context::Scope cscope(context); 1858 Context::Scope cscope(context);
1858 options.isolate_sources[0].Execute(isolate); 1859 options.isolate_sources[0].Execute(isolate);
1859 } 1860 }
1860 if (!options.last_run) { 1861 if (!options.last_run) {
1861 context.Dispose(); 1862 context.Dispose(isolate);
1862 if (options.send_idle_notification) { 1863 if (options.send_idle_notification) {
1863 const int kLongIdlePauseInMs = 1000; 1864 const int kLongIdlePauseInMs = 1000;
1864 V8::ContextDisposedNotification(); 1865 V8::ContextDisposedNotification();
1865 V8::IdleNotification(kLongIdlePauseInMs); 1866 V8::IdleNotification(kLongIdlePauseInMs);
1866 } 1867 }
1867 } 1868 }
1868 1869
1869 #ifndef V8_SHARED 1870 #ifndef V8_SHARED
1870 // Start preemption if threads have been created and preemption is enabled. 1871 // Start preemption if threads have been created and preemption is enabled.
1871 if (threads.length() > 0 1872 if (threads.length() > 0
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 } 1962 }
1962 1963
1963 } // namespace v8 1964 } // namespace v8
1964 1965
1965 1966
1966 #ifndef GOOGLE3 1967 #ifndef GOOGLE3
1967 int main(int argc, char* argv[]) { 1968 int main(int argc, char* argv[]) {
1968 return v8::Shell::Main(argc, argv); 1969 return v8::Shell::Main(argc, argv);
1969 } 1970 }
1970 #endif 1971 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698