Commit ec36c513 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[test/inspector] remove any usage of v8::Extension

.. replace all of them with prepared global object template.

+ bonus: wrap inspector related methods with inspector namespace.

BUG=none
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2832723004
Cr-Commit-Position: refs/heads/master@{#44785}
parent dddfcfd0
......@@ -10,11 +10,11 @@ const expression = `
delete Object.prototype.RemoteObject;
this.RemoteObject = v;
detachInspector();
inspector.detachInspector();
setTimeout(function() {
// Attach the inspector again for the sake of establishing a
// communication channel with the frontend test runner.
attachInspector();
inspector.attachInspector();
console.log("End of test");
}, 0);
},
......@@ -23,8 +23,8 @@ const expression = `
// Before the whole script runs, the inspector is already attached.
// Re-attach the inspector and trigger the console API to make sure that the
// injected inspector script runs again (and triggers the above setter).
detachInspector();
attachInspector();
inspector.detachInspector();
inspector.attachInspector();
console.log("First inspector activity after attaching inspector");
console.log("End of test");
`;
......
......@@ -6,24 +6,24 @@ InspectorTest.log('Checks that we collect obsolete async tasks with async stacks
InspectorTest.addScript(`
function test() {
setMaxAsyncTaskStacks(128);
inspector.setMaxAsyncTaskStacks(128);
var p = Promise.resolve();
dumpAsyncTaskStacksStateForTest();
setMaxAsyncTaskStacks(128);
dumpAsyncTaskStacksStateForTest();
inspector.dumpAsyncTaskStacksStateForTest();
inspector.setMaxAsyncTaskStacks(128);
inspector.dumpAsyncTaskStacksStateForTest();
p.then(() => 42).then(() => 239);
dumpAsyncTaskStacksStateForTest();
setMaxAsyncTaskStacks(128);
dumpAsyncTaskStacksStateForTest();
inspector.dumpAsyncTaskStacksStateForTest();
inspector.setMaxAsyncTaskStacks(128);
inspector.dumpAsyncTaskStacksStateForTest();
setTimeout(() => 42, 0);
dumpAsyncTaskStacksStateForTest();
setMaxAsyncTaskStacks(128);
dumpAsyncTaskStacksStateForTest();
inspector.dumpAsyncTaskStacksStateForTest();
inspector.setMaxAsyncTaskStacks(128);
inspector.dumpAsyncTaskStacksStateForTest();
}
`);
......
Checks that we drop old async call chains.
Running test: testInfrastructure
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 5
actual async chain len: 5
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(1024)
inspector.setMaxAsyncTaskStacks(1024)
Run expression 'console.trace(42)' with async chain len: 5
actual async chain len: 5
Running test: testZeroLimit
setMaxAsyncTaskStacks(0)
inspector.setMaxAsyncTaskStacks(0)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 0
setMaxAsyncTaskStacks(0)
inspector.setMaxAsyncTaskStacks(0)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 0
setMaxAsyncTaskStacks(0)
inspector.setMaxAsyncTaskStacks(0)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 0
setMaxAsyncTaskStacks(0)
inspector.setMaxAsyncTaskStacks(0)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 0
Running test: testOneLimit
setMaxAsyncTaskStacks(1)
inspector.setMaxAsyncTaskStacks(1)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 0
setMaxAsyncTaskStacks(1)
inspector.setMaxAsyncTaskStacks(1)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 0
setMaxAsyncTaskStacks(1)
inspector.setMaxAsyncTaskStacks(1)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(1)
inspector.setMaxAsyncTaskStacks(1)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 1
Running test: testTwoLimit
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 0
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 0
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 0
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(2)
inspector.setMaxAsyncTaskStacks(2)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 1
Running test: testMoreThanTwoLimit
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 0
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 0
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(3)
inspector.setMaxAsyncTaskStacks(3)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 1
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 0
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(4)
inspector.setMaxAsyncTaskStacks(4)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 2
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(5)
inspector.setMaxAsyncTaskStacks(5)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 2
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(6)
inspector.setMaxAsyncTaskStacks(6)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 1
actual async chain len: 1
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 2
actual async chain len: 2
setMaxAsyncTaskStacks(7)
inspector.setMaxAsyncTaskStacks(7)
Run expression 'console.trace(42)' with async chain len: 3
actual async chain len: 3
......@@ -165,7 +165,7 @@ function dumpAsyncChainLength(message) {
}
async function setMaxAsyncTaskStacks(max) {
let expression = `setMaxAsyncTaskStacks(${max})`;
let expression = `inspector.setMaxAsyncTaskStacks(${max})`;
InspectorTest.log(expression);
await Protocol.Runtime.evaluate({expression});
}
......@@ -43,13 +43,13 @@ Running test: testDebuggerStatement
Running test: testSyncDOMBreakpoint
> all frames in framework:
> mixed, top frame in framework:
syncDOMBreakpoint (framework.js:33:2)
syncDOMBreakpoint (framework.js:33:12)
(anonymous) (user.js:0:0)
Running test: testSyncDOMBreakpointWithInlinedUserFrame
> mixed, top frame in framework:
syncDOMBreakpoint (framework.js:33:2)
syncDOMBreakpoint (framework.js:33:12)
userFunction (user.js:70:2)
inlinedWrapper (framework.js:64:4)
syncDOMBreakpointWithInlinedUserFrame (framework.js:67:2)
......
......@@ -30,7 +30,7 @@ function debuggerStatement() {
}
function syncDOMBreakpoint() {
breakProgram('', '');
inspector.breakProgram('', '');
}
function asyncDOMBreakpoint() {
......
......@@ -3,10 +3,10 @@ break reason: framework-break
break aux data: {
"data": "data for framework-break"
}
doFrameworkBreak (framework.js:20:2)
doFrameworkWork (framework.js:15:2)
frameworkCall (framework.js:9:2)
testFunction (user.js:27:2)
doFrameworkBreak (framework.js:20:12)
doFrameworkWork (framework.js:15:12)
frameworkCall (framework.js:9:12)
testFunction (user.js:27:12)
(anonymous) (expr.js:0:0)
break reason: ambiguous
......@@ -25,17 +25,17 @@ break aux data: {
}
callback (user.js:31:17)
doFrameworkWork (framework.js:16:2)
frameworkCall (framework.js:9:2)
testFunction (user.js:27:2)
frameworkCall (framework.js:9:12)
testFunction (user.js:27:12)
(anonymous) (expr.js:0:0)
break reason: user-break
break aux data: {
"data": "data for user-break"
}
callback (user.js:32:2)
callback (user.js:32:12)
doFrameworkWork (framework.js:16:2)
frameworkCall (framework.js:9:2)
testFunction (user.js:27:2)
frameworkCall (framework.js:9:12)
testFunction (user.js:27:12)
(anonymous) (expr.js:0:0)
......@@ -6,30 +6,30 @@ InspectorTest.log('Checks nested scheduled break in framework code.');
InspectorTest.addScript(`
function frameworkCall(callback) {
callWithScheduledBreak(doFrameworkWork.bind(null, callback),
inspector.callWithScheduledBreak(doFrameworkWork.bind(null, callback),
'top-framework-scheduled-break',
JSON.stringify({ data: 'data for top-framework-scheduled-break' }));
}
function doFrameworkWork(callback) {
callWithScheduledBreak(doFrameworkBreak, 'should-not-be-a-reason', '');
inspector.callWithScheduledBreak(doFrameworkBreak, 'should-not-be-a-reason', '');
callback();
}
function doFrameworkBreak() {
breakProgram('framework-break', JSON.stringify({ data: 'data for framework-break' }));
inspector.breakProgram('framework-break', JSON.stringify({ data: 'data for framework-break' }));
}
//# sourceURL=framework.js`, 7, 26);
InspectorTest.addScript(`
function testFunction() {
callWithScheduledBreak(frameworkCall.bind(null, callback),
inspector.callWithScheduledBreak(frameworkCall.bind(null, callback),
'top-scheduled-break', '');
}
function callback() {
breakProgram('user-break', JSON.stringify({ data: 'data for user-break' }));
inspector.breakProgram('user-break', JSON.stringify({ data: 'data for user-break' }));
return 42;
}
......
......@@ -67,7 +67,7 @@ testStepFromUser (user.js:31:2)
Executing resume...
Running test: testStepIntoFromFramework
frameworkBreakAndCall (framework.js:14:2)
frameworkBreakAndCall (framework.js:14:12)
testStepFromFramework (user.js:35:2)
(anonymous) (expr.js:0:0)
......@@ -80,7 +80,7 @@ testStepFromFramework (user.js:35:2)
Executing resume...
Running test: testStepOverFromFramework
frameworkBreakAndCall (framework.js:14:2)
frameworkBreakAndCall (framework.js:14:12)
testStepFromFramework (user.js:35:2)
(anonymous) (expr.js:0:0)
......@@ -91,7 +91,7 @@ testStepFromFramework (user.js:36:0)
Executing resume...
Running test: testStepOutFromFramework
frameworkBreakAndCall (framework.js:14:2)
frameworkBreakAndCall (framework.js:14:12)
testStepFromFramework (user.js:35:2)
(anonymous) (expr.js:0:0)
......
......@@ -11,7 +11,7 @@ function frameworkCall(funcs) {
}
function frameworkBreakAndCall(funcs) {
breakProgram('', '');
inspector.breakProgram('', '');
for (var f of funcs) f();
}
//# sourceURL=framework.js`,
......
......@@ -2,7 +2,7 @@ Checks breakProgram,(schedule|cancel)PauseOnNextStatement test API
Running test: testBreakProgram
Stack:
callBreakProgram (:9:2)
callBreakProgram (:9:12)
(anonymous) (:0:0)
Other data:
{
......
......@@ -6,7 +6,7 @@ InspectorTest.log("Checks breakProgram,(schedule|cancel)PauseOnNextStatement tes
InspectorTest.addScript(`
function callBreakProgram() {
breakProgram('reason', JSON.stringify({a: 42}));
inspector.breakProgram('reason', JSON.stringify({a: 42}));
}
function foo() {
......
......@@ -2,16 +2,16 @@ Checks that stepping is cleared after breakProgram.
paused at:
function callBreakProgram() {
#debugger;
breakProgram('reason', '');
inspector.breakProgram('reason', '');
paused at:
debugger;
#breakProgram('reason', '');
#inspector.breakProgram('reason', '');
}
paused at:
debugger;
#breakProgram('reason', '');
inspector.#breakProgram('reason', '');
}
paused at:
......
......@@ -7,7 +7,7 @@ InspectorTest.log('Checks that stepping is cleared after breakProgram.');
InspectorTest.addScript(`
function callBreakProgram() {
debugger;
breakProgram('reason', '');
inspector.breakProgram('reason', '');
}`);
InspectorTest.setupScriptMap();
......
......@@ -7,7 +7,7 @@ checks.');
InspectorTest.addScript(`
function testFunction() {
var array = [ createObjectWithStrictCheck() ];
var array = [ inspector.createObjectWithStrictCheck() ];
debugger;
}
//# sourceURL=test.js`);
......
......@@ -146,11 +146,11 @@ class DisconnectTask : public TaskRunner::Task {
class CreateContextGroupTask : public TaskRunner::Task {
public:
CreateContextGroupTask(InspectorClientImpl* client,
v8::ExtensionConfiguration* extensions,
TaskRunner::SetupGlobalTasks setup_global_tasks,
v8::base::Semaphore* ready_semaphore,
int* context_group_id)
: client_(client),
extensions_(extensions),
setup_global_tasks_(std::move(setup_global_tasks)),
ready_semaphore_(ready_semaphore),
context_group_id_(context_group_id) {}
virtual ~CreateContextGroupTask() = default;
......@@ -159,13 +159,13 @@ class CreateContextGroupTask : public TaskRunner::Task {
void Run(v8::Isolate* isolate,
const v8::Global<v8::Context>& global_context) {
*context_group_id_ = client_->createContextGroup(extensions_);
*context_group_id_ = client_->createContextGroup(setup_global_tasks_);
if (ready_semaphore_) ready_semaphore_->Signal();
}
private:
InspectorClientImpl* client_;
v8::ExtensionConfiguration* extensions_;
TaskRunner::SetupGlobalTasks setup_global_tasks_;
v8::base::Semaphore* ready_semaphore_;
int* context_group_id_;
};
......@@ -230,16 +230,17 @@ void InspectorClientImpl::disconnect() {
}
void InspectorClientImpl::scheduleCreateContextGroup(
v8::ExtensionConfiguration* extensions,
TaskRunner::SetupGlobalTasks setup_global_tasks,
v8::base::Semaphore* ready_semaphore, int* context_group_id) {
task_runner_->Append(new CreateContextGroupTask(
this, extensions, ready_semaphore, context_group_id));
this, std::move(setup_global_tasks), ready_semaphore, context_group_id));
}
int InspectorClientImpl::createContextGroup(
v8::ExtensionConfiguration* extensions) {
const TaskRunner::SetupGlobalTasks& setup_global_tasks) {
v8::HandleScope handle_scope(isolate_);
v8::Local<v8::Context> context = task_runner_->NewContextGroup();
v8::Local<v8::Context> context =
task_runner_->NewContextGroup(setup_global_tasks);
context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
int context_group_id = TaskRunner::GetContextGroupId(context);
v8_inspector::StringView state;
......@@ -371,11 +372,14 @@ class SendMessageToBackendTask : public TaskRunner::Task {
TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr;
v8::Local<v8::FunctionTemplate>
SendMessageToBackendExtension::GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
return v8::FunctionTemplate::New(
isolate, SendMessageToBackendExtension::SendMessageToBackend);
void SendMessageToBackendExtension::Run(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> global) {
global->Set(
v8::String::NewFromUtf8(isolate, "sendMessageToBackend",
v8::NewStringType::kNormal)
.ToLocalChecked(),
v8::FunctionTemplate::New(
isolate, &SendMessageToBackendExtension::SendMessageToBackend));
}
void SendMessageToBackendExtension::SendMessageToBackend(
......
......@@ -26,9 +26,9 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
virtual ~InspectorClientImpl();
void scheduleReconnect(v8::base::Semaphore* ready_semaphore);
void scheduleCreateContextGroup(v8::ExtensionConfiguration* extensions,
v8::base::Semaphore* ready_semaphore,
int* context_group_id);
void scheduleCreateContextGroup(
TaskRunner::SetupGlobalTasks setup_global_tasks,
v8::base::Semaphore* ready_semaphore, int* context_group_id);
static v8_inspector::V8Inspector* InspectorFromContext(
v8::Local<v8::Context> context);
......@@ -65,7 +65,8 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
friend class DisconnectTask;
void disconnect();
friend class CreateContextGroupTask;
int createContextGroup(v8::ExtensionConfiguration* extensions);
int createContextGroup(
const TaskRunner::SetupGlobalTasks& setup_global_tasks);
std::unique_ptr<v8_inspector::V8Inspector> inspector_;
std::unique_ptr<v8_inspector::V8Inspector::Channel> channel_;
......@@ -86,13 +87,9 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
DISALLOW_COPY_AND_ASSIGN(InspectorClientImpl);
};
class SendMessageToBackendExtension : public v8::Extension {
class SendMessageToBackendExtension : public TaskRunner::SetupGlobalTask {
public:
SendMessageToBackendExtension()
: v8::Extension("v8_inspector/frontend",
"native function sendMessageToBackend();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name);
void Run(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> global) override;
static void set_backend_task_runner(TaskRunner* task_runner) {
backend_task_runner_ = task_runner;
......
This diff is collapsed.
......@@ -62,7 +62,7 @@ Object.defineProperty(parentObj, 'propNotNamedProto', {
set: function() {}
});
var objInheritsGetterProperty = {__proto__: parentObj};
allowAccessorFormatting(objInheritsGetterProperty);
inspector.allowAccessorFormatting(objInheritsGetterProperty);
`);
InspectorTest.setupInjectedScriptEnvironment();
......
......@@ -32,11 +32,11 @@ v8::internal::Vector<uint16_t> ToVector(v8::Local<v8::String> str) {
} // namespace
TaskRunner::TaskRunner(v8::ExtensionConfiguration* extensions,
TaskRunner::TaskRunner(TaskRunner::SetupGlobalTasks setup_global_tasks,
bool catch_exceptions,
v8::base::Semaphore* ready_semaphore)
: Thread(Options("Task Runner")),
extensions_(extensions),
setup_global_tasks_(std::move(setup_global_tasks)),
catch_exceptions_(catch_exceptions),
ready_semaphore_(ready_semaphore),
isolate_(nullptr),
......@@ -55,15 +55,20 @@ void TaskRunner::InitializeIsolate() {
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
NewContextGroup();
NewContextGroup(setup_global_tasks_);
if (ready_semaphore_) ready_semaphore_->Signal();
}
v8::Local<v8::Context> TaskRunner::NewContextGroup() {
v8::Local<v8::Context> TaskRunner::NewContextGroup(
const TaskRunner::SetupGlobalTasks& setup_global_tasks) {
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate_);
for (auto it = setup_global_tasks.begin(); it != setup_global_tasks.end();
++it) {
(*it)->Run(isolate_, global_template);
}
v8::Local<v8::Context> context =
v8::Context::New(isolate_, extensions_, global_template);
v8::Context::New(isolate_, nullptr, global_template);
context->SetAlignedPointerInEmbedderData(kTaskRunnerIndex, this);
intptr_t context_group_id = ++last_context_group_id_;
// Should be 2-byte aligned.
......
......@@ -36,7 +36,15 @@ class TaskRunner : public v8::base::Thread {
const v8::Global<v8::Context>& context) = 0;
};
TaskRunner(v8::ExtensionConfiguration* extensions, bool catch_exceptions,
class SetupGlobalTask {
public:
virtual ~SetupGlobalTask() = default;
virtual void Run(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> global) = 0;
};
using SetupGlobalTasks = std::vector<std::unique_ptr<SetupGlobalTask>>;
TaskRunner(SetupGlobalTasks setup_global_tasks, bool catch_exceptions,
v8::base::Semaphore* ready_semaphore);
virtual ~TaskRunner();
......@@ -52,7 +60,8 @@ class TaskRunner : public v8::base::Thread {
static TaskRunner* FromContext(v8::Local<v8::Context>);
v8::Local<v8::Context> NewContextGroup();
v8::Local<v8::Context> NewContextGroup(
const SetupGlobalTasks& setup_global_tasks);
v8::Local<v8::Context> GetContext(int context_group_id);
static int GetContextGroupId(v8::Local<v8::Context> context);
......@@ -68,7 +77,7 @@ class TaskRunner : public v8::base::Thread {
void InitializeIsolate();
Task* GetNext(bool only_protocol);
v8::ExtensionConfiguration* extensions_;
SetupGlobalTasks setup_global_tasks_;
bool catch_exceptions_;
v8::base::Semaphore* ready_semaphore_;
......
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