src: revert -r/--require flags
This reverts commit 7bde3f1a8f53d82992a8fed73e5f93159bb400b3. The added test (test/parallel/test-preload.js) fails on Windows. PR-URL: https://github.com/iojs/io.js/pull/1150 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
7a5b023bac
commit
056ed4b0c9
@ -52,8 +52,6 @@ and servers.
|
|||||||
-i, --interactive always enter the REPL even if stdin
|
-i, --interactive always enter the REPL even if stdin
|
||||||
does not appear to be a terminal
|
does not appear to be a terminal
|
||||||
|
|
||||||
-r, --require module to preload at startup
|
|
||||||
|
|
||||||
--no-deprecation silence deprecation warnings
|
--no-deprecation silence deprecation warnings
|
||||||
|
|
||||||
--trace-deprecation show stack traces on deprecations
|
--trace-deprecation show stack traces on deprecations
|
||||||
|
37
src/node.cc
37
src/node.cc
@ -114,8 +114,6 @@ static bool trace_deprecation = false;
|
|||||||
static bool throw_deprecation = false;
|
static bool throw_deprecation = false;
|
||||||
static bool abort_on_uncaught_exception = false;
|
static bool abort_on_uncaught_exception = false;
|
||||||
static const char* eval_string = nullptr;
|
static const char* eval_string = nullptr;
|
||||||
static unsigned int preload_module_count = 0;
|
|
||||||
static const char** preload_modules = nullptr;
|
|
||||||
static bool use_debug_agent = false;
|
static bool use_debug_agent = false;
|
||||||
static bool debug_wait_connect = false;
|
static bool debug_wait_connect = false;
|
||||||
static int debug_port = 5858;
|
static int debug_port = 5858;
|
||||||
@ -2767,19 +2765,6 @@ void SetupProcessObject(Environment* env,
|
|||||||
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
|
READONLY_PROPERTY(process, "_forceRepl", True(env->isolate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preload_module_count) {
|
|
||||||
CHECK(preload_modules);
|
|
||||||
Local<Array> array = Array::New(env->isolate());
|
|
||||||
for (unsigned int i = 0; i < preload_module_count; ++i) {
|
|
||||||
Local<String> module = String::NewFromUtf8(env->isolate(),
|
|
||||||
preload_modules[i]);
|
|
||||||
array->Set(i, module);
|
|
||||||
}
|
|
||||||
READONLY_PROPERTY(process,
|
|
||||||
"_preload_modules",
|
|
||||||
array);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --no-deprecation
|
// --no-deprecation
|
||||||
if (no_deprecation) {
|
if (no_deprecation) {
|
||||||
READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
|
READONLY_PROPERTY(process, "noDeprecation", True(env->isolate()));
|
||||||
@ -3004,7 +2989,6 @@ static void PrintHelp() {
|
|||||||
" -p, --print evaluate script and print result\n"
|
" -p, --print evaluate script and print result\n"
|
||||||
" -i, --interactive always enter the REPL even if stdin\n"
|
" -i, --interactive always enter the REPL even if stdin\n"
|
||||||
" does not appear to be a terminal\n"
|
" does not appear to be a terminal\n"
|
||||||
" -r, --require module to preload (option can be repeated)\n"
|
|
||||||
" --no-deprecation silence deprecation warnings\n"
|
" --no-deprecation silence deprecation warnings\n"
|
||||||
" --throw-deprecation throw an exception anytime a deprecated "
|
" --throw-deprecation throw an exception anytime a deprecated "
|
||||||
"function is used\n"
|
"function is used\n"
|
||||||
@ -3062,13 +3046,11 @@ static void ParseArgs(int* argc,
|
|||||||
const char** new_exec_argv = new const char*[nargs];
|
const char** new_exec_argv = new const char*[nargs];
|
||||||
const char** new_v8_argv = new const char*[nargs];
|
const char** new_v8_argv = new const char*[nargs];
|
||||||
const char** new_argv = new const char*[nargs];
|
const char** new_argv = new const char*[nargs];
|
||||||
const char** local_preload_modules = new const char*[nargs];
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < nargs; ++i) {
|
for (unsigned int i = 0; i < nargs; ++i) {
|
||||||
new_exec_argv[i] = nullptr;
|
new_exec_argv[i] = nullptr;
|
||||||
new_v8_argv[i] = nullptr;
|
new_v8_argv[i] = nullptr;
|
||||||
new_argv[i] = nullptr;
|
new_argv[i] = nullptr;
|
||||||
local_preload_modules[i] = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exec_argv starts with the first option, the other two start with argv[0].
|
// exec_argv starts with the first option, the other two start with argv[0].
|
||||||
@ -3117,15 +3099,6 @@ static void ParseArgs(int* argc,
|
|||||||
eval_string += 1;
|
eval_string += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (strcmp(arg, "--require") == 0 ||
|
|
||||||
strcmp(arg, "-r") == 0) {
|
|
||||||
const char* module = argv[index + 1];
|
|
||||||
if (module == nullptr) {
|
|
||||||
fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
|
|
||||||
exit(9);
|
|
||||||
}
|
|
||||||
args_consumed += 1;
|
|
||||||
local_preload_modules[preload_module_count++] = module;
|
|
||||||
} else if (strcmp(arg, "--interactive") == 0 || strcmp(arg, "-i") == 0) {
|
} else if (strcmp(arg, "--interactive") == 0 || strcmp(arg, "-i") == 0) {
|
||||||
force_repl = true;
|
force_repl = true;
|
||||||
} else if (strcmp(arg, "--no-deprecation") == 0) {
|
} else if (strcmp(arg, "--no-deprecation") == 0) {
|
||||||
@ -3172,16 +3145,6 @@ static void ParseArgs(int* argc,
|
|||||||
memcpy(argv, new_argv, new_argc * sizeof(*argv));
|
memcpy(argv, new_argv, new_argc * sizeof(*argv));
|
||||||
delete[] new_argv;
|
delete[] new_argv;
|
||||||
*argc = static_cast<int>(new_argc);
|
*argc = static_cast<int>(new_argc);
|
||||||
|
|
||||||
// Copy the preload_modules from the local array to an appropriately sized
|
|
||||||
// global array.
|
|
||||||
if (preload_module_count > 0) {
|
|
||||||
CHECK(!preload_modules);
|
|
||||||
preload_modules = new const char*[preload_module_count];
|
|
||||||
memcpy(preload_modules, local_preload_modules,
|
|
||||||
preload_module_count * sizeof(*preload_modules));
|
|
||||||
}
|
|
||||||
delete[] local_preload_modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
14
src/node.js
14
src/node.js
@ -68,18 +68,7 @@
|
|||||||
var d = NativeModule.require('_debug_agent');
|
var d = NativeModule.require('_debug_agent');
|
||||||
d.start();
|
d.start();
|
||||||
|
|
||||||
} else {
|
} else if (process._eval != null) {
|
||||||
// There is user code to be run
|
|
||||||
|
|
||||||
// Load any preload modules
|
|
||||||
if (process._preload_modules) {
|
|
||||||
var Module = NativeModule.require('module');
|
|
||||||
process._preload_modules.forEach(function(module) {
|
|
||||||
Module._load(module);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process._eval != null) {
|
|
||||||
// User passed '-e' or '--eval' arguments to Node.
|
// User passed '-e' or '--eval' arguments to Node.
|
||||||
evalScript('[eval]');
|
evalScript('[eval]');
|
||||||
} else if (process.argv[1]) {
|
} else if (process.argv[1]) {
|
||||||
@ -160,7 +149,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
startup.globalVariables = function() {
|
startup.globalVariables = function() {
|
||||||
global.process = process;
|
global.process = process;
|
||||||
|
1
test/fixtures/printA.js
vendored
1
test/fixtures/printA.js
vendored
@ -1 +0,0 @@
|
|||||||
console.log('A')
|
|
1
test/fixtures/printB.js
vendored
1
test/fixtures/printB.js
vendored
@ -1 +0,0 @@
|
|||||||
console.log('B')
|
|
1
test/fixtures/printC.js
vendored
1
test/fixtures/printC.js
vendored
@ -1 +0,0 @@
|
|||||||
console.log('C')
|
|
@ -1,75 +0,0 @@
|
|||||||
var common = require('../common'),
|
|
||||||
assert = require('assert'),
|
|
||||||
path = require('path'),
|
|
||||||
child_process = require('child_process');
|
|
||||||
|
|
||||||
var nodeBinary = process.argv[0];
|
|
||||||
|
|
||||||
var preloadOption = function(preloads) {
|
|
||||||
var option = '';
|
|
||||||
preloads.forEach(function(preload, index) {
|
|
||||||
// TODO: randomly pick -r or --require
|
|
||||||
option += '-r ' + preload + ' ';
|
|
||||||
});
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fixture = function(name) {
|
|
||||||
return path.join(__dirname, '../fixtures/' + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
var fixtureA = fixture('printA.js');
|
|
||||||
var fixtureB = fixture('printB.js');
|
|
||||||
var fixtureC = fixture('printC.js')
|
|
||||||
var fixtureThrows = fixture('throws_error4.js');
|
|
||||||
|
|
||||||
// test preloading a single module works
|
|
||||||
child_process.exec(nodeBinary + ' '
|
|
||||||
+ preloadOption([fixtureA]) + ' '
|
|
||||||
+ fixtureB,
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.equal(stdout, 'A\nB\n');
|
|
||||||
});
|
|
||||||
|
|
||||||
// test preloading multiple modules works
|
|
||||||
child_process.exec(nodeBinary + ' '
|
|
||||||
+ preloadOption([fixtureA, fixtureB]) + ' '
|
|
||||||
+ fixtureC,
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.equal(stdout, 'A\nB\nC\n');
|
|
||||||
});
|
|
||||||
|
|
||||||
// test that preloading a throwing module aborts
|
|
||||||
child_process.exec(nodeBinary + ' '
|
|
||||||
+ preloadOption([fixtureA, fixtureThrows]) + ' '
|
|
||||||
+ fixtureB,
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) {
|
|
||||||
assert.equal(stdout, 'A\n');
|
|
||||||
} else {
|
|
||||||
throw new Error('Preload should have failed');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// test that preload can be used with --eval
|
|
||||||
child_process.exec(nodeBinary + ' '
|
|
||||||
+ preloadOption([fixtureA])
|
|
||||||
+ '-e \'console.log("hello");\'',
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.equal(stdout, 'A\nhello\n');
|
|
||||||
});
|
|
||||||
|
|
||||||
// test that preload placement at other points in the cmdline
|
|
||||||
// also test that duplicated preload only gets loaded once
|
|
||||||
child_process.exec(nodeBinary + ' '
|
|
||||||
+ preloadOption([fixtureA])
|
|
||||||
+ '-e \'console.log("hello");\' '
|
|
||||||
+ preloadOption([fixtureA, fixtureB]),
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) throw err;
|
|
||||||
assert.equal(stdout, 'A\nB\nhello\n');
|
|
||||||
});
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user