Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
yaelhe committed Jan 13, 2019
commit a0993a34d37b7a727fb291e5a1c75aecddd65883
1 change: 1 addition & 0 deletions doc/api/worker_threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ if (isMainThread) {
* `stderr` {boolean} If this is set to `true`, then `worker.stderr` will
not automatically be piped through to `process.stderr` in the parent.
* `execArgv` {string[]} List of node CLI options passed to the worker.
Comment thread
yaelhe marked this conversation as resolved.
V8 options and options that affect the process are not supported.

Comment thread
jdalton marked this conversation as resolved.
### Event: 'error'
<!-- YAML
Expand Down
8 changes: 1 addition & 7 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ function validateNumber(value, name) {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
}

function validateArray(value, name) {
if (!Array.isArray(value))
throw new ERR_INVALID_ARG_TYPE(name, 'array', value);
}

module.exports = {
isInt32,
isUint32,
Expand All @@ -143,6 +138,5 @@ module.exports = {
validateInt32,
validateUint32,
validateString,
validateNumber,
validateArray,
validateNumber
};
9 changes: 6 additions & 3 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const {
ERR_WORKER_UNSERIALIZABLE_ERROR,
ERR_WORKER_UNSUPPORTED_EXTENSION,
ERR_WORKER_INVALID_EXEC_ARGV,
ERR_INVALID_ARG_TYPE,
} = require('internal/errors').codes;
const { validateString, validateArray } = require('internal/validators');
const { validateString } = require('internal/validators');

const {
drainMessagePort,
Expand Down Expand Up @@ -50,8 +51,10 @@ class Worker extends EventEmitter {
super();
debug(`[${threadId}] create new worker`, filename, options);
validateString(filename, 'filename');
if (options.execArgv) {
validateArray(options.execArgv, 'options.execArgv');
if (options.execArgv && !Array.isArray(options.execArgv)) {
throw new ERR_INVALID_ARG_TYPE('options.execArgv',
'array',
options.execArgv);
}
if (!options.eval) {
if (!path.isAbsolute(filename) &&
Expand Down
19 changes: 11 additions & 8 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ Worker::Worker(Environment* env,
Isolate::Scope isolate_scope(isolate_);
HandleScope handle_scope(isolate_);

IsolateData* isolate_data =
CreateIsolateData(isolate_,
&loop_,
env->isolate_data()->platform(),
array_buffer_allocator_.get());
isolate_data_.reset(CreateIsolateData(isolate_,
&loop_,
env->isolate_data()->platform(),
array_buffer_allocator_.get()));
if (per_isolate_opts != nullptr) {
isolate_data->set_options(per_isolate_opts);
isolate_data_->set_options(per_isolate_opts);
}
isolate_data_.reset(isolate_data);
CHECK(isolate_data_);

Local<Context> context = NewContext(isolate_);
Expand Down Expand Up @@ -419,9 +417,14 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
if (!array->Get(env->context(), i).ToLocal(&arg)) {
return;
}
v8::MaybeLocal<v8::String> arg_v8_string =
arg->ToString(env->context());
if (arg_v8_string.IsEmpty()) {
return;
}
Utf8Value arg_utf8_value(
args.GetIsolate(),
arg->ToString(env->context()).FromMaybe(v8::Local<v8::String>()));
arg_v8_string.FromMaybe(v8::Local<v8::String>()));
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
exec_argv.push_back(arg_string);
}
Expand Down