OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 #ifndef CHECK | 69 #ifndef CHECK |
70 #define CHECK(condition) assert(condition) | 70 #define CHECK(condition) assert(condition) |
71 #endif | 71 #endif |
72 | 72 |
73 namespace v8 { | 73 namespace v8 { |
74 | 74 |
75 namespace { | 75 namespace { |
76 | 76 |
77 const int MB = 1024 * 1024; | 77 const int MB = 1024 * 1024; |
| 78 const int kMaxWorkers = 50; |
78 | 79 |
79 | 80 |
80 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 81 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
81 public: | 82 public: |
82 virtual void* Allocate(size_t length) { | 83 virtual void* Allocate(size_t length) { |
83 void* data = AllocateUninitialized(length); | 84 void* data = AllocateUninitialized(length); |
84 return data == NULL ? data : memset(data, 0, length); | 85 return data == NULL ? data : memset(data, 0, length); |
85 } | 86 } |
86 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | 87 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
87 virtual void Free(void* data, size_t) { free(data); } | 88 virtual void Free(void* data, size_t) { free(data); } |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 return; | 700 return; |
700 } | 701 } |
701 | 702 |
702 if (!args.IsConstructCall()) { | 703 if (!args.IsConstructCall()) { |
703 Throw(args.GetIsolate(), "Worker must be constructed with new"); | 704 Throw(args.GetIsolate(), "Worker must be constructed with new"); |
704 return; | 705 return; |
705 } | 706 } |
706 | 707 |
707 { | 708 { |
708 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer()); | 709 base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer()); |
| 710 if (workers_.length() >= kMaxWorkers) { |
| 711 Throw(args.GetIsolate(), "Too many workers, I won't let you create more"); |
| 712 return; |
| 713 } |
| 714 |
709 // Initialize the internal field to NULL; if we return early without | 715 // Initialize the internal field to NULL; if we return early without |
710 // creating a new Worker (because the main thread is terminating) we can | 716 // creating a new Worker (because the main thread is terminating) we can |
711 // early-out from the instance calls. | 717 // early-out from the instance calls. |
712 args.Holder()->SetAlignedPointerInInternalField(0, NULL); | 718 args.Holder()->SetAlignedPointerInInternalField(0, NULL); |
713 | 719 |
714 if (!allow_new_workers_) return; | 720 if (!allow_new_workers_) return; |
715 | 721 |
716 Worker* worker = new Worker; | 722 Worker* worker = new Worker; |
717 args.Holder()->SetAlignedPointerInInternalField(0, worker); | 723 args.Holder()->SetAlignedPointerInInternalField(0, worker); |
718 workers_.Add(worker); | 724 workers_.Add(worker); |
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2470 } | 2476 } |
2471 | 2477 |
2472 } // namespace v8 | 2478 } // namespace v8 |
2473 | 2479 |
2474 | 2480 |
2475 #ifndef GOOGLE3 | 2481 #ifndef GOOGLE3 |
2476 int main(int argc, char* argv[]) { | 2482 int main(int argc, char* argv[]) { |
2477 return v8::Shell::Main(argc, argv); | 2483 return v8::Shell::Main(argc, argv); |
2478 } | 2484 } |
2479 #endif | 2485 #endif |
OLD | NEW |