Back out c9f5d3ebba39 (bug 835552) for Windows build bustage

CLOSED TREE
This commit is contained in:
Phil Ringnalda 2013-03-09 08:15:42 -08:00
parent c916e7babb
commit 70e53ca277
26 changed files with 114 additions and 181 deletions

View File

@ -1,3 +0,0 @@
// A file in the same directory as testPaths.js
x = 'local';

View File

@ -1,51 +0,0 @@
// 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.)
loaded = {}
snarfed = {}
relatived = {}
for (let f of ['local.js', '../basic/local.js', 'selfhosted.js']) {
try {
load(f);
loaded[f] = true;
} catch(e) {
loaded[f] = !/can't open/.test(e);
}
try {
snarf(f);
snarfed[f] = true;
} catch(e) {
snarfed[f] = !/can't open/.test(e);
}
try {
readRelativeToScript(f);
relatived[f] = true;
} catch(e) {
relatived[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);
if (('PWD' in environment) && !(/test.*[\/\\]basic[\/\\]/.test(environment['PWD']))) {
assertEq(snarfed['local.js'], false);
assertEq(snarfed['../basic/local.js'], false);
}
// selfhosted.js is in the root of the objdir, where |make check| is normally
// run from.
assertEq(loaded['selfhosted.js'], false);
assertEq(relatived['selfhosted.js'], false);
if (!snarfed['selfhosted.js']) {
print("WARNING: expected to be able to find selfhosted.js in current directory\n");
print("(not failing because it depends on where this test was run from)\n");
}

View File

@ -71,12 +71,7 @@
#endif
#ifdef XP_WIN
# include <io.h>
# include <direct.h>
# include "jswin.h"
# define PATH_MAX MAX_PATH
#else
# include <libgen.h>
#include "jswin.h"
#endif
#if JS_TRACE_LOGGING
@ -680,60 +675,6 @@ RevertVersion(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
static JSScript *
GetTopScript(JSContext *cx)
{
RootedScript script(cx);
JS_DescribeScriptedCaller(cx, script.address(), NULL);
return script;
}
/*
* Resolve a (possibly) relative filename to an absolute path. If
* |scriptRelative| is true, then the result will be relative to the directory
* containing the currently-running script. Otherwise, it will be relative to
* the current working directory.
*/
static JSString *
ResolvePath(JSContext *cx, HandleString filenameStr, bool scriptRelative)
{
JSAutoByteString filename(cx, filenameStr);
if (!filename)
return NULL;
const char *pathname = filename.ptr();
if (pathname[0] == '/')
return filenameStr;
static char buffer[PATH_MAX+1];
RootedScript script(cx);
if (scriptRelative) {
/* Get the currently executing script's name. */
script = GetTopScript(cx);
JS_ASSERT(script->filename);
strncpy(buffer, script->filename, PATH_MAX+1);
if (buffer[PATH_MAX] != '\0')
return NULL;
// dirname(buffer) might return buffer, or it might return a
// statically-allocated string
memmove(buffer, dirname(buffer), strlen(buffer) + 1);
} else {
const char *cwd = getcwd(buffer, PATH_MAX);
if (!cwd)
return NULL;
strcpy(buffer, cwd);
}
size_t len = strlen(buffer);
buffer[len] = '/';
strncpy(buffer + len + 1, pathname, sizeof(buffer) - (len+1));
if (buffer[PATH_MAX] != '\0')
return NULL;
return JS_NewStringCopyZ(cx, buffer);
}
static JSBool
Options(JSContext *cx, unsigned argc, jsval *vp)
{
@ -792,14 +733,11 @@ Load(JSContext *cx, unsigned argc, jsval *vp)
return false;
jsval *argv = JS_ARGV(cx, vp);
RootedString str(cx);
for (unsigned i = 0; i < argc; i++) {
str = JS_ValueToString(cx, argv[i]);
if (!str)
return false;
str = ResolvePath(cx, str, true);
JSString *str = JS_ValueToString(cx, argv[i]);
if (!str)
return false;
argv[i] = STRING_TO_JSVAL(str);
JSAutoByteString filename(cx, str);
if (!filename)
return false;
@ -1418,6 +1356,14 @@ SetDebug(JSContext *cx, unsigned argc, jsval *vp)
return ok;
}
static RawScript
GetTopScript(JSContext *cx)
{
RootedScript script(cx);
JS_DescribeScriptedCaller(cx, script.address(), NULL);
return script;
}
static JSBool
GetScriptAndPCArgs(JSContext *cx, unsigned argc, jsval *argv, MutableHandleScript scriptp,
int32_t *ip)
@ -3033,6 +2979,57 @@ Parent(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
#ifdef XP_UNIX
#include <fcntl.h>
#include <sys/stat.h>
/*
* Returns a JS_malloc'd string (that the caller needs to JS_free)
* containing the directory (non-leaf) part of |from| prepended to |leaf|.
* If |from| is empty or a leaf, MakeAbsolutePathname returns a copy of leaf.
* Returns NULL to indicate an error.
*/
static char *
MakeAbsolutePathname(JSContext *cx, const char *from, const char *leaf)
{
size_t dirlen;
char *dir;
const char *slash = NULL, *cp;
if (*leaf == '/') {
/* We were given an absolute pathname. */
return JS_strdup(cx, leaf);
}
cp = from;
while (*cp) {
if (*cp == '/') {
slash = cp;
}
++cp;
}
if (!slash) {
/* We were given a leaf or |from| was empty. */
return JS_strdup(cx, leaf);
}
/* Else, we were given a real pathname, return that + the leaf. */
dirlen = slash - from + 1;
dir = (char*) JS_malloc(cx, dirlen + strlen(leaf) + 1);
if (!dir)
return NULL;
strncpy(dir, from, dirlen);
strcpy(dir + dirlen, leaf); /* Note: we can't use strcat here. */
return dir;
}
#endif // XP_UNIX
static JSBool
Compile(JSContext *cx, unsigned argc, jsval *vp)
{
@ -3169,30 +3166,36 @@ struct FreeOnReturn
};
static JSBool
ReadFile(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
Snarf(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JSString *str;
if (args.length() < 1 || args.length() > 2) {
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL,
args.length() < 1 ? JSSMSG_NOT_ENOUGH_ARGS : JSSMSG_TOO_MANY_ARGS,
"snarf");
if (!argc)
return false;
}
if (!args[0].isString() || (args.length() == 2 && !args[1].isString())) {
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_INVALID_ARGS, "snarf");
str = JS_ValueToString(cx, JS_ARGV(cx, vp)[0]);
if (!str)
return false;
}
RootedString givenPath(cx, args[0].toString());
RootedString str(cx, ResolvePath(cx, givenPath, scriptRelative));
JSAutoByteString filename(cx, str);
if (!filename)
return false;
if (args.length() > 1) {
JSString *opt = JS_ValueToString(cx, args[1]);
/* Get the currently executing script's name. */
RootedScript script(cx, GetTopScript(cx));
JS_ASSERT(script->filename);
const char *pathname = filename.ptr();
#ifdef XP_UNIX
FreeOnReturn pnGuard(cx);
if (pathname[0] != '/') {
pathname = MakeAbsolutePathname(cx, script->filename, pathname);
if (!pathname)
return false;
pnGuard.init(pathname);
}
#endif
if (argc > 1) {
JSString *opt = JS_ValueToString(cx, JS_ARGV(cx, vp)[1]);
if (!opt)
return false;
JSBool match;
@ -3200,31 +3203,19 @@ ReadFile(JSContext *cx, unsigned argc, jsval *vp, bool scriptRelative)
return false;
if (match) {
JSObject *obj;
if (!(obj = FileAsTypedArray(cx, filename.ptr())))
if (!(obj = FileAsTypedArray(cx, pathname)))
return false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
return true;
}
}
if (!(str = FileAsString(cx, filename.ptr())))
if (!(str = FileAsString(cx, pathname)))
return false;
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
return true;
}
static JSBool
Snarf(JSContext *cx, unsigned argc, jsval *vp)
{
return ReadFile(cx, argc, vp, false);
}
static JSBool
ReadRelativeToScript(JSContext *cx, unsigned argc, jsval *vp)
{
return ReadFile(cx, argc, vp, true);
}
static JSBool
System(JSContext *cx, unsigned argc, jsval *vp)
{
@ -3536,8 +3527,7 @@ 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()."),
" Load files named by string arguments."),
JS_FN_HELP("evaluate", Evaluate, 2, 0,
"evaluate(code[, options])",
@ -3738,19 +3728,13 @@ static JSFunctionSpecWithHelp shell_functions[] = {
#endif
JS_FN_HELP("snarf", Snarf, 1, 0,
"snarf(filename, [\"binary\"])",
" Read filename into returned string. Filename is relative to the current\n"
" working directory."),
"snarf(filename)",
" Read filename into returned string."),
JS_FN_HELP("read", Snarf, 1, 0,
"read(filename, [\"binary\"])",
"read(filename)",
" Synonym for snarf."),
JS_FN_HELP("readRelativeToScript", ReadRelativeToScript, 1, 0,
"readRelativeToScript(filename, [\"binary\"])",
" Read filename into returned string. Filename is relative to the directory\n"
" containing the current script."),
JS_FN_HELP("system", System, 1, 0,
"system(command)",
" Execute command on the current host, returning result code."),

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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 *

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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 *

View File

@ -12,7 +12,7 @@ var summary =
print(BUGNUMBER + ": " + summary);
load("defineProperty-setup.js");
load("ecma_5/Object/defineProperty-setup.js");
/**************
* BEGIN TEST *

View File

@ -12,7 +12,7 @@ var summary =
print(BUGNUMBER + ": " + summary);
load("defineProperty-setup.js");
load("ecma_5/Object/defineProperty-setup.js");
/**************
* BEGIN TEST *

View File

@ -12,7 +12,7 @@ var summary =
print(BUGNUMBER + ": " + summary);
load("defineProperty-setup.js");
load("ecma_5/Object/defineProperty-setup.js");
/**************
* BEGIN TEST *

View File

@ -12,7 +12,7 @@ var summary =
print(BUGNUMBER + ": " + summary);
load("defineProperty-setup.js");
load("ecma_5/Object/defineProperty-setup.js");
/**************
* BEGIN TEST *

View File

@ -299,6 +299,9 @@ function matches(aA, aB)
//---------------------------------------------------------------------------
// XXX: note that read() looks for files relative to the path of the script,
// not the path the script was invoked from. Bug 835552 is open to fix this.
let kUsageMsg =
"Usage:\n\
\n\