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

Unified Diff: src/d8.cc

Issue 1218553004: Change d8 Worker API so it takes a string instead of a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use template strings Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-worker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 4c6060b948849e3333ea96f4544b4f4a381e7bf4..7db6f3ed9e442081528e05140bd25b8911e26cb6 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -690,8 +690,8 @@ void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
- if (args.Length() < 1 || !args[0]->IsFunction()) {
- Throw(args.GetIsolate(), "1st argument must be function");
+ if (args.Length() < 1 || !args[0]->IsString()) {
+ Throw(args.GetIsolate(), "1st argument must be string");
return;
}
@@ -703,12 +703,12 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.This()->SetInternalField(0, External::New(isolate, worker));
workers_.Add(worker);
- String::Utf8Value function_string(args[0]->ToString());
- if (!*function_string) {
- Throw(args.GetIsolate(), "Function.prototype.toString failed");
+ String::Utf8Value script(args[0]);
+ if (!*script) {
+ Throw(args.GetIsolate(), "Can't get worker script");
return;
}
- worker->StartExecuteInThread(isolate, *function_string);
+ worker->StartExecuteInThread(isolate, *script);
}
}
@@ -1641,19 +1641,15 @@ Worker::Worker()
Worker::~Worker() { Cleanup(); }
-void Worker::StartExecuteInThread(Isolate* isolate,
- const char* function_string) {
- DCHECK(base::NoBarrier_Load(&state_) == IDLE);
- static const char format[] = "(%s).call(this);";
- size_t len = strlen(function_string) + sizeof(format);
-
- script_ = new char[len + 1];
- i::Vector<char> vec(script_, static_cast<int>(len + 1));
- i::SNPrintF(vec, format, function_string);
-
- base::NoBarrier_Store(&state_, RUNNING);
- thread_ = new WorkerThread(this);
- thread_->Start();
+void Worker::StartExecuteInThread(Isolate* isolate, const char* script) {
+ if (base::NoBarrier_CompareAndSwap(&state_, IDLE, RUNNING) == IDLE) {
+ script_ = i::StrDup(script);
+ thread_ = new WorkerThread(this);
+ thread_->Start();
+ } else {
+ // Somehow the Worker was started twice.
+ UNREACHABLE();
+ }
}
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/d8-worker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698