зеркало из https://github.com/mozilla/gecko-dev.git
Bug 853541 - Partially revert bug 835552, making load() be cwd-relative again. r=njn
--HG-- extra : rebase_source : cc75800ec61f900ecf9d4a478eceaef7a67690dd
This commit is contained in:
Родитель
8e9bea61c5
Коммит
6f73405058
|
@ -1,12 +1,14 @@
|
|||
// load() should resolve paths relative to the current script. That's easily
|
||||
// tested. snarf() aka read() should resolve paths relative to the current
|
||||
// working directory, which is harder to test because the shell doesn't really
|
||||
// have any (portable) notion of the current directory (and it can't create
|
||||
// files to enforce an expected layout.)
|
||||
// load() and snarf() (aka read()) should resolve paths relative to the current
|
||||
// working directory. This is a little hard to test because the shell doesn't
|
||||
// really have any (portable) notion of the current directory (and it can't
|
||||
// create files to enforce an expected layout.) loadRelativeToScript() and
|
||||
// readRelativeToScript() do what their names say, which is much easier to
|
||||
// test.
|
||||
|
||||
loaded = {}
|
||||
snarfed = {}
|
||||
relatived = {}
|
||||
loadRel = {}
|
||||
snarfRel = {}
|
||||
for (let f of ['local.js', '../basic/local.js', 'Y.js']) {
|
||||
try {
|
||||
load(f);
|
||||
|
@ -24,28 +26,42 @@ for (let f of ['local.js', '../basic/local.js', 'Y.js']) {
|
|||
|
||||
try {
|
||||
readRelativeToScript(f);
|
||||
relatived[f] = true;
|
||||
snarfRel[f] = true;
|
||||
} catch(e) {
|
||||
relatived[f] = !/can't open/.test(e);
|
||||
snarfRel[f] = !/can't open/.test(e);
|
||||
}
|
||||
|
||||
try {
|
||||
loadRelativeToScript(f);
|
||||
loadRel[f] = true;
|
||||
} catch(e) {
|
||||
loadRel[f] = !/can't open/.test(e);
|
||||
}
|
||||
}
|
||||
|
||||
// local.js in the same dir as this script, so should be found by load() but
|
||||
// not snarf() -- unless you happen to be in that directory
|
||||
assertEq(loaded['local.js'], true);
|
||||
assertEq(loaded['../basic/local.js'], true);
|
||||
assertEq(relatived['local.js'], true);
|
||||
assertEq(relatived['../basic/local.js'], true);
|
||||
// local.js in the same dir as this script, so should be found by the
|
||||
// script-relative calls but not the cwd-relative ones -- unless you happen to
|
||||
// be in that directory
|
||||
assertEq(loadRel['local.js'], true);
|
||||
assertEq(loadRel['../basic/local.js'], true);
|
||||
assertEq(snarfRel['local.js'], true);
|
||||
assertEq(snarfRel['../basic/local.js'], true);
|
||||
if (('PWD' in environment) && !(/test.*[\/\\]basic[\/\\]/.test(environment['PWD']))) {
|
||||
assertEq(loaded['local.js'], false);
|
||||
assertEq(loaded['../basic/local.js'], false);
|
||||
assertEq(snarfed['local.js'], false);
|
||||
assertEq(snarfed['../basic/local.js'], false);
|
||||
}
|
||||
|
||||
// Y.js is in the root of the objdir, where |make check| is normally
|
||||
// run from.
|
||||
assertEq(loaded['Y.js'], false);
|
||||
assertEq(relatived['Y.js'], false);
|
||||
assertEq(loadRel['Y.js'], false);
|
||||
assertEq(snarfRel['Y.js'], false);
|
||||
if (!snarfed['Y.js']) {
|
||||
print("WARNING: expected to be able to find Y.js in current directory\n");
|
||||
print("(not failing because it depends on where this test was run from)\n");
|
||||
}
|
||||
if (!loaded['Y.js']) {
|
||||
print("WARNING: expected to be able to find Y.js in current directory\n");
|
||||
print("(not failing because it depends on where this test was run from)\n");
|
||||
}
|
||||
|
|
|
@ -743,7 +743,6 @@ ResolvePath(JSContext *cx, HandleString filenameStr, bool scriptRelative)
|
|||
const char *cwd = getcwd(buffer, PATH_MAX);
|
||||
if (!cwd)
|
||||
return NULL;
|
||||
strcpy(buffer, cwd);
|
||||
}
|
||||
|
||||
size_t len = strlen(buffer);
|
||||
|
@ -841,13 +840,13 @@ LoadScript(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
|
|||
static JSBool
|
||||
Load(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
return LoadScript(cx, argc, vp, true);
|
||||
return LoadScript(cx, argc, vp, false);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
LoadScriptRelativeToCwd(JSContext *cx, unsigned argc, jsval *vp)
|
||||
LoadScriptRelativeToScript(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
return LoadScript(cx, argc, vp, false);
|
||||
return LoadScript(cx, argc, vp, true);
|
||||
}
|
||||
|
||||
class AutoNewContext
|
||||
|
@ -3569,13 +3568,13 @@ static JSFunctionSpecWithHelp shell_functions[] = {
|
|||
JS_FN_HELP("load", Load, 1, 0,
|
||||
"load(['foo.js' ...])",
|
||||
" Load files named by string arguments. Filename is relative to the\n"
|
||||
" script calling the load()."),
|
||||
|
||||
JS_FN_HELP("loadRelativeToCwd", LoadScriptRelativeToCwd, 1, 0,
|
||||
"loadRelativeToCwd(['foo.js' ...])",
|
||||
" Load files named by string arguments. Filename is relative to the\n"
|
||||
" current working directory."),
|
||||
|
||||
JS_FN_HELP("loadRelativeToScript", LoadScriptRelativeToScript, 1, 0,
|
||||
"loadRelativeToScript(['foo.js' ...])",
|
||||
" Load files named by string arguments. Filename is relative to the\n"
|
||||
" calling script."),
|
||||
|
||||
JS_FN_HELP("evaluate", Evaluate, 2, 0,
|
||||
"evaluate(code[, options])",
|
||||
" Evaluate code as though it were the contents of a file.\n"
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(1, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(2, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(3, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(4, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(5, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(6, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(7, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runDictionaryPropertyPresentTestsFraction(8, 8);
|
||||
|
|
|
@ -8,7 +8,7 @@ var summary = 'ES5 Object.defineProperty(O, P, Attributes): Function.length';
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(1, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(2, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(3, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(4, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(5, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(6, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(7, 8);
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
runNonTerminalPropertyPresentTestsFraction(8, 8);
|
||||
|
|
|
@ -8,7 +8,7 @@ var summary = 'ES5 Object.defineProperty(O, P, Attributes): new definition';
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
|
@ -12,7 +12,7 @@ var summary =
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
|
@ -12,7 +12,7 @@ var summary =
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
|
@ -12,7 +12,7 @@ var summary =
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
|
@ -12,7 +12,7 @@ var summary =
|
|||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
load("defineProperty-setup.js");
|
||||
load("ecma_5/Object/defineProperty-setup.js");
|
||||
|
||||
/**************
|
||||
* BEGIN TEST *
|
||||
|
|
Загрузка…
Ссылка в новой задаче