Chromium Code Reviews| Index: src/d8.cc |
| diff --git a/src/d8.cc b/src/d8.cc |
| index 09cd9631b03b1feb16804001aeac04040ebecc90..8facb20b8fdb9c37d171855dd78c0eb3685fcdc9 100644 |
| --- a/src/d8.cc |
| +++ b/src/d8.cc |
| @@ -66,6 +66,7 @@ namespace { |
| const int MB = 1024 * 1024; |
| const int kMaxWorkers = 50; |
| +const int kMaxSerializerMemoryUsage = 1 * MB; // Arbitrary maximum for testing. |
| #define USE_VM 1 |
| #define VM_THRESHOLD 65536 |
| @@ -2471,7 +2472,6 @@ bool Shell::SetOptions(int argc, char* argv[]) { |
| argv[i] = NULL; |
| } else if (strncmp(argv[i], "--lcov=", 7) == 0) { |
| options.lcov_file = argv[i] + 7; |
| - argv[i] = NULL; |
|
Yang
2017/02/16 07:59:32
Accidental change?
binji
2017/02/17 00:49:13
Oops, fixed.
|
| } |
| } |
| @@ -2571,7 +2571,9 @@ void Shell::EmptyMessageQueues(Isolate* isolate) { |
| class Serializer : public ValueSerializer::Delegate { |
| public: |
| explicit Serializer(Isolate* isolate) |
| - : isolate_(isolate), serializer_(isolate, this) {} |
| + : isolate_(isolate), |
| + serializer_(isolate, this), |
| + current_memory_usage_(0) {} |
| Maybe<bool> WriteValue(Local<Context> context, Local<Value> value, |
| Local<Value> transfer) { |
| @@ -2622,6 +2624,11 @@ class Serializer : public ValueSerializer::Delegate { |
| void* ReallocateBufferMemory(void* old_buffer, size_t size, |
| size_t* actual_size) override { |
| + // Not accurate, because we don't take into account reallocated buffers, |
| + // but this is fine for testing. |
| + current_memory_usage_ += size; |
| + if (current_memory_usage_ > kMaxSerializerMemoryUsage) return nullptr; |
| + |
| void* result = realloc(old_buffer, size); |
| *actual_size = result ? size : 0; |
| return result; |
| @@ -2699,6 +2706,7 @@ class Serializer : public ValueSerializer::Delegate { |
| std::unique_ptr<SerializationData> data_; |
| std::vector<Global<ArrayBuffer>> array_buffers_; |
| std::vector<Global<SharedArrayBuffer>> shared_array_buffers_; |
| + size_t current_memory_usage_; |
| DISALLOW_COPY_AND_ASSIGN(Serializer); |
| }; |