Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit ced0471

Browse files
committed
meta: merge node/master into node-chakracore/master
Merge 52e869b as of 2018-03-13 This commit was automatically generated. For any problems, please contact jackhorton Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
2 parents ae9a06b + 52e869b commit ced0471

File tree

14 files changed

+258
-78
lines changed

14 files changed

+258
-78
lines changed

doc/STYLE_GUIDE.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"color" vs. "colour", etc.
1515
* Use [serial commas][].
1616
* Avoid personal pronouns in reference documentation ("I", "you", "we").
17-
* Pronouns are acceptable in more colloquial documentation, like guides.
18-
* Use gender-neutral pronouns and mass nouns. Non-comprehensive
19-
examples:
17+
* Personal pronouns are acceptable in colloquial documentation such as guides.
18+
* Use gender-neutral pronouns and gender-neutral plural nouns.
2019
* OK: "they", "their", "them", "folks", "people", "developers"
2120
* NOT OK: "his", "hers", "him", "her", "guys", "dudes"
2221
* When combining wrapping elements (parentheses and quotes), terminal

doc/api/vm.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ added: v0.3.1
495495
value of the [`url.origin`][] property of a [`URL`][] object. Most notably,
496496
this string should omit the trailing slash, as that denotes a path.
497497
**Default:** `''`.
498+
* `contextCodeGeneration` {Object}
499+
* `strings` {boolean} If set to false any calls to `eval` or function
500+
constructors (`Function`, `GeneratorFunction`, etc) will throw an
501+
`EvalError`.
502+
**Default**: `true`.
503+
* `wasm` {boolean} If set to false any attempt to compile a WebAssembly
504+
module will throw a `WebAssembly.CompileError`.
505+
**Default**: `true`.
498506

499507
First contextifies the given `sandbox`, runs the compiled code contained by
500508
the `vm.Script` object within the created sandbox, and returns the result.
@@ -578,6 +586,14 @@ added: v0.3.1
578586
the [`url.origin`][] property of a [`URL`][] object. Most notably, this
579587
string should omit the trailing slash, as that denotes a path.
580588
**Default:** `''`.
589+
* `codeGeneration` {Object}
590+
* `strings` {boolean} If set to false any calls to `eval` or function
591+
constructors (`Function`, `GeneratorFunction`, etc) will throw an
592+
`EvalError`.
593+
**Default**: `true`.
594+
* `wasm` {boolean} If set to false any attempt to compile a WebAssembly
595+
module will throw a `WebAssembly.CompileError`.
596+
**Default**: `true`.
581597

582598
If given a `sandbox` object, the `vm.createContext()` method will [prepare
583599
that sandbox][contextified] so that it can be used in calls to

lib/vm.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,36 @@ function validateString(prop, propName) {
8484
throw new ERR_INVALID_ARG_TYPE(propName, 'string', prop);
8585
}
8686

87+
function validateBool(prop, propName) {
88+
if (prop !== undefined && typeof prop !== 'boolean')
89+
throw new ERR_INVALID_ARG_TYPE(propName, 'boolean', prop);
90+
}
91+
92+
function validateObject(prop, propName) {
93+
if (prop !== undefined && (typeof prop !== 'object' || prop === null))
94+
throw new ERR_INVALID_ARG_TYPE(propName, 'Object', prop);
95+
}
96+
8797
function getContextOptions(options) {
8898
if (options) {
99+
validateObject(options.contextCodeGeneration,
100+
'options.contextCodeGeneration');
89101
const contextOptions = {
90102
name: options.contextName,
91-
origin: options.contextOrigin
103+
origin: options.contextOrigin,
104+
codeGeneration: typeof options.contextCodeGeneration === 'object' ? {
105+
strings: options.contextCodeGeneration.strings,
106+
wasm: options.contextCodeGeneration.wasm,
107+
} : undefined,
92108
};
93109
validateString(contextOptions.name, 'options.contextName');
94110
validateString(contextOptions.origin, 'options.contextOrigin');
111+
if (contextOptions.codeGeneration) {
112+
validateBool(contextOptions.codeGeneration.strings,
113+
'options.contextCodeGeneration.strings');
114+
validateBool(contextOptions.codeGeneration.wasm,
115+
'options.contextCodeGeneration.wasm');
116+
}
95117
return contextOptions;
96118
}
97119
return {};
@@ -109,10 +131,21 @@ function createContext(sandbox, options) {
109131
if (typeof options !== 'object' || options === null) {
110132
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
111133
}
134+
validateObject(options.codeGeneration, 'options.codeGeneration');
112135
options = {
113136
name: options.name,
114-
origin: options.origin
137+
origin: options.origin,
138+
codeGeneration: typeof options.codeGeneration === 'object' ? {
139+
strings: options.codeGeneration.strings,
140+
wasm: options.codeGeneration.wasm,
141+
} : undefined,
115142
};
143+
if (options.codeGeneration !== undefined) {
144+
validateBool(options.codeGeneration.strings,
145+
'options.codeGeneration.strings');
146+
validateBool(options.codeGeneration.wasm,
147+
'options.codeGeneration.wasm');
148+
}
116149
if (options.name === undefined) {
117150
options.name = `VM Context ${defaultContextNameIndex++}`;
118151
} else if (typeof options.name !== 'string') {

node.gyp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@
205205
'sources': [
206206
'src/node_main.cc'
207207
],
208+
'includes': [
209+
'node.gypi'
210+
],
208211
'include_dirs': [
209212
'src',
210213
],
@@ -235,9 +238,6 @@
235238
}],
236239
[ 'node_intermediate_lib_type=="static_library" and '
237240
'node_shared=="false"', {
238-
'includes': [
239-
'node.gypi'
240-
],
241241
'xcode_settings': {
242242
'OTHER_LDFLAGS': [
243243
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)'
@@ -500,19 +500,6 @@
500500
],
501501
}],
502502
],
503-
'defines!': [
504-
'NODE_PLATFORM="win"',
505-
],
506-
'defines': [
507-
'FD_SETSIZE=1024',
508-
# we need to use node's preferred "win32" rather than gyp's preferred "win"
509-
'NODE_PLATFORM="win32"',
510-
# Stop <windows.h> from defining macros that conflict with
511-
# std::min() and std::max(). We don't use <windows.h> (much)
512-
# but we still inherit it from uv.h.
513-
'NOMINMAX',
514-
'_UNICODE=1',
515-
],
516503
'libraries': [ '-lpsapi.lib' ],
517504
'conditions': [
518505
# this is only necessary for chakra on windows because chakra is dynamically linked on windows
@@ -521,7 +508,6 @@
521508
}],
522509
],
523510
}, { # POSIX
524-
'defines': [ '__POSIX__' ],
525511
'sources': [ 'src/backtrace_posix.cc' ],
526512
}],
527513
[ 'node_use_etw=="true"', {

node.gypi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@
3737
'NODE_SHARED_MODE',
3838
],
3939
}],
40+
[ 'OS=="win"', {
41+
'defines!': [
42+
'NODE_PLATFORM="win"',
43+
],
44+
'defines': [
45+
'FD_SETSIZE=1024',
46+
# we need to use node's preferred "win32" rather than gyp's preferred "win"
47+
'NODE_PLATFORM="win32"',
48+
# Stop <windows.h> from defining macros that conflict with
49+
# std::min() and std::max(). We don't use <windows.h> (much)
50+
# but we still inherit it from uv.h.
51+
'NOMINMAX',
52+
'_UNICODE=1',
53+
],
54+
}, { # POSIX
55+
'defines': [ '__POSIX__' ],
56+
}],
57+
4058
[ 'node_enable_d8=="true"', {
4159
'dependencies': [ 'deps/v8/src/d8.gyp:d8' ],
4260
}],

src/node.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "node_revert.h"
2929
#include "node_debug_options.h"
3030
#include "node_perf.h"
31+
#include "node_context_data.h"
3132

3233
#if defined HAVE_PERFCTR
3334
#include "node_counters.h"
@@ -4577,6 +4578,8 @@ Local<Context> NewContext(Isolate* isolate,
45774578
HandleScope handle_scope(isolate);
45784579
auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl");
45794580
auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator");
4581+
context->SetEmbedderData(
4582+
ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate));
45804583
Local<Value> intl_v;
45814584
if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) &&
45824585
intl_v->IsObject()) {
@@ -4686,6 +4689,13 @@ inline int Start(Isolate* isolate, void* isolate_context,
46864689
return exit_code;
46874690
}
46884691

4692+
bool AllowWasmCodeGenerationCallback(
4693+
Local<Context> context, Local<String>) {
4694+
Local<Value> wasm_code_gen =
4695+
context->GetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration);
4696+
return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue();
4697+
}
4698+
46894699
inline int Start(uv_loop_t* event_loop,
46904700
int argc, const char* const* argv,
46914701
int exec_argc, const char* const* exec_argv) {
@@ -4718,6 +4728,7 @@ inline int Start(uv_loop_t* event_loop,
47184728
isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
47194729
isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
47204730
isolate->SetFatalErrorHandler(OnFatalError);
4731+
isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback);
47214732

47224733
{
47234734
Mutex::ScopedLock scoped_lock(node_isolate_mutex);

src/node_context_data.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ namespace node {
1515
#define NODE_CONTEXT_SANDBOX_OBJECT_INDEX 33
1616
#endif
1717

18+
#ifndef NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX
19+
#define NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX 34
20+
#endif
21+
1822
enum ContextEmbedderIndex {
1923
kEnvironment = NODE_CONTEXT_EMBEDDER_DATA_INDEX,
2024
kSandboxObject = NODE_CONTEXT_SANDBOX_OBJECT_INDEX,
25+
kAllowWasmCodeGeneration = NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX,
2126
};
2227

2328
} // namespace node

src/node_contextify.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,30 @@ Local<Context> ContextifyContext::CreateV8Context(
190190
CHECK(name->IsString());
191191
Utf8Value name_val(env->isolate(), name);
192192

193+
Local<Value> codegen = options_obj->Get(env->context(),
194+
FIXED_ONE_BYTE_STRING(env->isolate(), "codeGeneration"))
195+
.ToLocalChecked();
196+
197+
if (!codegen->IsUndefined()) {
198+
CHECK(codegen->IsObject());
199+
Local<Object> codegen_obj = codegen.As<Object>();
200+
201+
Local<Value> allow_code_gen_from_strings =
202+
codegen_obj->Get(env->context(),
203+
FIXED_ONE_BYTE_STRING(env->isolate(), "strings"))
204+
.ToLocalChecked();
205+
ctx->AllowCodeGenerationFromStrings(
206+
allow_code_gen_from_strings->IsUndefined() ||
207+
allow_code_gen_from_strings->IsTrue());
208+
209+
Local<Value> allow_wasm_code_gen = codegen_obj->Get(env->context(),
210+
FIXED_ONE_BYTE_STRING(env->isolate(), "wasm"))
211+
.ToLocalChecked();
212+
ctx->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,
213+
Boolean::New(env->isolate(), allow_wasm_code_gen->IsUndefined() ||
214+
allow_wasm_code_gen->IsTrue()));
215+
}
216+
193217
ContextInfo info(*name_val);
194218

195219
Local<Value> origin =

src/node_contextify.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class ContextifyContext {
2424
v8::Local<v8::Object> sandbox_obj, v8::Local<v8::Object> options_obj);
2525
static void Init(Environment* env, v8::Local<v8::Object> target);
2626

27+
static bool AllowWasmCodeGeneration(
28+
v8::Local<v8::Context> context, v8::Local<v8::String>);
29+
2730
static ContextifyContext* ContextFromContextifiedSandbox(
2831
Environment* env,
2932
const v8::Local<v8::Object>& sandbox);

src/node_main.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,30 @@ int wmain(int argc, wchar_t *wargv[]) {
8282
#endif // __LP64__
8383
extern char** environ;
8484
#endif // __linux__
85+
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
86+
#include <string.h>
87+
#include <signal.h>
88+
#endif
8589

8690
namespace node {
8791
extern bool linux_at_secure;
8892
} // namespace node
8993

9094
int main(int argc, char *argv[]) {
95+
#if defined(__POSIX__) && defined(NODE_SHARED_MODE)
96+
// In node::PlatformInit(), we squash all signal handlers for non-shared lib
97+
// build. In order to run test cases against shared lib build, we also need
98+
// to do the same thing for shared lib build here, but only for SIGPIPE for
99+
// now. If node::PlatformInit() is moved to here, then this section could be
100+
// removed.
101+
{
102+
struct sigaction act;
103+
memset(&act, 0, sizeof(act));
104+
act.sa_handler = SIG_IGN;
105+
sigaction(SIGPIPE, &act, nullptr);
106+
}
107+
#endif
108+
91109
#if defined(__linux__)
92110
char** envp = environ;
93111
while (*envp++ != nullptr) {}

0 commit comments

Comments
 (0)