Commit 29e44142 authored by binji's avatar binji Committed by Commit bot

[d8 Workers] Add max worker count, throw an exception if too many.

BUG=chromium:518748
R=mstarzinger@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1284683004

Cr-Commit-Position: refs/heads/master@{#30230}
parent 41fa3573
......@@ -75,6 +75,7 @@ namespace v8 {
namespace {
const int MB = 1024 * 1024;
const int kMaxWorkers = 50;
class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
......@@ -706,6 +707,11 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
{
base::LockGuard<base::Mutex> lock_guard(workers_mutex_.Pointer());
if (workers_.length() >= kMaxWorkers) {
Throw(args.GetIsolate(), "Too many workers, I won't let you create more");
return;
}
// Initialize the internal field to NULL; if we return early without
// creating a new Worker (because the main thread is terminating) we can
// early-out from the instance calls.
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
if (this.Worker) {
var workersToCreate = 1000;
var workers = [];
assertThrows(function() {
for (var i = 0; i < workersToCreate; i++) {
workers.push(new Worker(''));
}
});
print('#workers: ', workers.length);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment