Propagate a flag induced by JSOPTION_XML into script and context version fields, for proper run- and compile-time consistency (275742, r=shaver).

This commit is contained in:
brendan%mozilla.org 2004-12-24 00:03:59 +00:00
Родитель c50e280c7b
Коммит 931f64581c
15 изменённых файлов: 166 добавлений и 78 удалений

Просмотреть файл

@ -981,7 +981,7 @@ JS_ContextIterator(JSRuntime *rt, JSContext **iterp)
JS_PUBLIC_API(JSVersion)
JS_GetVersion(JSContext *cx)
{
return cx->version;
return cx->version & JSVERSION_MASK;
}
JS_PUBLIC_API(JSVersion)
@ -989,22 +989,15 @@ JS_SetVersion(JSContext *cx, JSVersion version)
{
JSVersion oldVersion;
oldVersion = cx->version;
JS_ASSERT(version != JSVERSION_UNKNOWN);
JS_ASSERT((version & ~JSVERSION_MASK) == 0);
oldVersion = cx->version & JSVERSION_MASK;
if (version == oldVersion)
return oldVersion;
cx->version = version;
#if !JS_BUG_FALLIBLE_EQOPS
if (cx->version == JSVERSION_1_2) {
cx->jsop_eq = JSOP_NEW_EQ;
cx->jsop_ne = JSOP_NEW_NE;
} else {
cx->jsop_eq = JSOP_EQ;
cx->jsop_ne = JSOP_NE;
}
#endif /* !JS_BUG_FALLIBLE_EQOPS */
cx->version = (cx->version & ~JSVERSION_MASK) | version;
js_OnVersionChange(cx);
return oldVersion;
}
@ -1051,11 +1044,20 @@ JS_GetOptions(JSContext *cx)
return cx->options;
}
#define SYNC_OPTIONS_TO_VERSION(cx) \
JS_BEGIN_MACRO \
if ((cx)->options & JSOPTION_XML) \
(cx)->version |= JSVERSION_HAS_XML; \
else \
(cx)->version &= ~JSVERSION_HAS_XML; \
JS_END_MACRO
JS_PUBLIC_API(uint32)
JS_SetOptions(JSContext *cx, uint32 options)
{
uint32 oldopts = cx->options;
cx->options = options;
SYNC_OPTIONS_TO_VERSION(cx);
return oldopts;
}
@ -1064,6 +1066,7 @@ JS_ToggleOptions(JSContext *cx, uint32 options)
{
uint32 oldopts = cx->options;
cx->options ^= options;
SYNC_OPTIONS_TO_VERSION(cx);
return oldopts;
}

Просмотреть файл

@ -296,7 +296,7 @@ array_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
{
jsuint length;
if (cx->version == JSVERSION_1_2) {
if (JS_VERSION_IS_1_2(cx)) {
if (!js_GetLengthProperty(cx, obj, &length))
return JS_FALSE;
switch (type) {
@ -412,7 +412,7 @@ array_join_sub(JSContext *cx, JSObject *obj, JSString *sep, JSBool literalize,
if (!ok)
goto done;
if ((!literalize || cx->version == JSVERSION_1_2) &&
if ((!literalize || JS_VERSION_IS_1_2(cx)) &&
(JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v))) {
str = cx->runtime->emptyString;
} else {
@ -519,7 +519,7 @@ array_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
* JS1.2 arrays convert to array literals, with a comma followed by a space
* between each element.
*/
literalize = (cx->version == JSVERSION_1_2);
literalize = JS_VERSION_IS_1_2(cx);
return array_join_sub(cx, obj, literalize ? &comma_space : &comma,
literalize, rval, JS_FALSE);
}
@ -959,7 +959,7 @@ array_push(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
* return the new array length.
*/
length += argc;
if (cx->version == JSVERSION_1_2) {
if (JS_VERSION_IS_1_2(cx)) {
*rval = argc ? argv[argc-1] : JSVAL_VOID;
} else {
if (!IndexToValue(cx, length, rval))
@ -1138,7 +1138,7 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
argv++;
}
if (count == 1 && cx->version == JSVERSION_1_2) {
if (count == 1 && JS_VERSION_IS_1_2(cx)) {
/*
* JS lacks "list context", whereby in Perl one turns the single
* scalar that's spliced out into an array just by assigning it to
@ -1155,7 +1155,7 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (!OBJ_GET_PROPERTY(cx, obj, id, rval))
return JS_FALSE;
} else {
if (cx->version != JSVERSION_1_2 || count > 0) {
if (!JS_VERSION_IS_1_2(cx) || count > 0) {
/*
* Create a new array value to return. Our ECMA v2 proposal specs
* that splice always returns an array value, even when given no
@ -1398,7 +1398,7 @@ Array(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (argc == 0) {
length = 0;
vector = NULL;
} else if (cx->version == JSVERSION_1_2) {
} else if (JS_VERSION_IS_1_2(cx)) {
length = (jsuint) argc;
vector = argv;
} else if (argc > 1) {

Просмотреть файл

@ -194,7 +194,7 @@ js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
b = JS_FALSE;
} else if (JSVAL_IS_OBJECT(v)) {
if (!JSVERSION_IS_ECMA(cx->version)) {
if (!JS_VERSION_IS_ECMA(cx)) {
if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
return JS_FALSE;
if (!JSVAL_IS_BOOLEAN(v))

Просмотреть файл

@ -63,6 +63,27 @@
#include "jsscript.h"
#include "jsstr.h"
void
js_OnVersionChange(JSContext *cx)
{
#if !JS_BUG_FALLIBLE_EQOPS
if (JS_VERSION_IS_1_2(cx)) {
cx->jsop_eq = JSOP_NEW_EQ;
cx->jsop_ne = JSOP_NEW_NE;
} else {
cx->jsop_eq = JSOP_EQ;
cx->jsop_ne = JSOP_NE;
}
#endif /* !JS_BUG_FALLIBLE_EQOPS */
}
void
js_SetVersion(JSContext *cx, JSVersion version)
{
cx->version = version;
js_OnVersionChange(cx);
}
JSContext *
js_NewContext(JSRuntime *rt, size_t stackChunkSize)
{

Просмотреть файл

@ -344,7 +344,7 @@ struct JSContext {
jsuword stackLimit;
/* Runtime version control identifier and equality operators. */
JSVersion version;
uint16 version;
jsbytecode jsop_eq;
jsbytecode jsop_ne;
@ -459,17 +459,72 @@ struct JSContext {
};
/*
* Slightly more readable macros, also to hide bitset implementation detail.
* XXX beware non-boolean truth values, which belie the bitset hiding claim!
* Slightly more readable macros for testing per-context option settings (also
* to hide bitset implementation detail).
*
* JSOPTION_XML must be handled specially in order to propagate from compile-
* to run-time (from cx->options to script->version/cx->version). To do that,
* we copy JSOPTION_XML from cx->options into cx->version as JSVERSION_HAS_XML
* whenever options are set, and preserve this XML flag across version number
* changes done via the JS_SetVersion API.
*
* But when executing a script or scripted function, the interpreter changes
* cx->version, including the XML flag, to script->version. Thus JSOPTION_XML
* is a compile-time option that causes a run-time version change during each
* activation of the compiled script. That version change has the effect of
* changing JS_HAS_XML_OPTION, so that any compiling done via eval enables XML
* support. If an XML-enabled script or function calls a non-XML function,
* the flag bit will be cleared during the callee's activation.
*
* Note that JS_SetVersion API calls never pass JSVERSION_HAS_XML or'd into
* that API's version parameter.
*
* Note also that script->version must contain this XML option flag in order
* for XDR'ed scripts to serialize and deserialize with that option preserved
* for detection at run-time. We can't copy other compile-time options into
* script->version because that would break backward compatibility (certain
* other options, e.g. JSOPTION_VAROBJFIX, are analogous to JSOPTION_XML).
*/
#define JS_HAS_STRICT_OPTION(cx) ((cx)->options & JSOPTION_STRICT)
#define JS_HAS_WERROR_OPTION(cx) ((cx)->options & JSOPTION_WERROR)
#define JS_HAS_COMPILE_N_GO_OPTION(cx) ((cx)->options & JSOPTION_COMPILE_N_GO)
#define JS_HAS_ATLINE_OPTION(cx) ((cx)->options & JSOPTION_ATLINE)
#define JS_HAS_XML_OPTION(cx) ((cx)->options & JSOPTION_XML)
#define JS_HAS_NATIVE_BRANCH_CALLBACK_OPTION(cx) \
((cx)->options & JSOPTION_NATIVE_BRANCH_CALLBACK)
#define JS_HAS_OPTION(cx,option) (((cx)->options & (option)) != 0)
#define JS_HAS_STRICT_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_STRICT)
#define JS_HAS_WERROR_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_WERROR)
#define JS_HAS_COMPILE_N_GO_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_COMPILE_N_GO)
#define JS_HAS_ATLINE_OPTION(cx) JS_HAS_OPTION(cx, JSOPTION_ATLINE)
#define JSVERSION_MASK 0x0FFF /* see JSVersion in jspubtd.h */
#define JSVERSION_HAS_XML 0x1000 /* flag induced by XML option */
#define JS_HAS_XML_OPTION(cx) ((cx)->version & JSVERSION_HAS_XML)
#define JS_HAS_NATIVE_BRANCH_CALLBACK_OPTION(cx) \
JS_HAS_OPTION(cx, JSOPTION_NATIVE_BRANCH_CALLBACK)
/*
* Wrappers for the JSVERSION_IS_* macros from jspubtd.h taking JSContext *cx
* and masking off the XML flag and any other high order bits.
*/
#define JS_VERSION_IS_ECMA(cx) \
JSVERSION_IS_ECMA((cx)->version & JSVERSION_MASK)
#define JS_VERSION_IS_1_2(cx) \
(((cx)->version & JSVERSION_MASK) == JSVERSION_1_2)
/*
* Common subroutine of JS_SetVersion and js_SetVersion, to update per-context
* data that depends on version.
*/
extern void
js_OnVersionChange(JSContext *cx);
/*
* Unlike the JS_SetVersion API, this function stores JSVERSION_HAS_XML and
* any future non-version-number flags induced by compiler options.
*/
extern void
js_SetVersion(JSContext *cx, JSVersion version);
/*
* Create and destroy functions for JSContext, which is manually allocated
* and exclusively owned.
*/
extern JSContext *
js_NewContext(JSRuntime *rt, size_t stackChunkSize);

Просмотреть файл

@ -796,12 +796,15 @@ date_getTime(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool
date_getYear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble *date;
jsdouble result;
jsdouble *date = date_getProlog(cx, obj, argv);
JSVersion version;
date = date_getProlog(cx, obj, argv);
if (!date)
return JS_FALSE;
result = *date;
result = *date;
if (!JSDOUBLE_IS_FINITE(result))
return js_NewNumberValue(cx, result, rval);
@ -816,9 +819,10 @@ date_getYear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
* the getFullYear method. But we try to protect existing scripts that
* have specified a version...
*/
if (cx->version == JSVERSION_1_0 ||
cx->version == JSVERSION_1_1 ||
cx->version == JSVERSION_1_2)
version = cx->version & JSVERSION_MASK;
if (version == JSVERSION_1_0 ||
version == JSVERSION_1_1 ||
version == JSVERSION_1_2)
{
if (result >= 1900 && result < 2000)
result -= 1900;

Просмотреть файл

@ -839,7 +839,7 @@ JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
JS_PUBLIC_API(JSVersion)
JS_GetScriptVersion(JSContext *cx, JSScript *script)
{
return script->version;
return script->version & JSVERSION_MASK;
}
/***************************************************************************/

Просмотреть файл

@ -409,7 +409,7 @@ args_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
if (!js_DefineProperty(cx, obj, INT_JSVAL_TO_JSID(id),
fp->argv[slot],
args_getProperty, args_setProperty,
JSVERSION_IS_ECMA(cx->version)
JS_VERSION_IS_ECMA(cx)
? 0
: JSPROP_ENUMERATE,
NULL)) {
@ -915,7 +915,7 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
#endif /* !JS_HAS_ARGS_OBJECT */
case ARGS_LENGTH:
if (!JSVERSION_IS_ECMA(cx->version))
if (!JS_VERSION_IS_ECMA(cx))
*vp = INT_TO_JSVAL((jsint)(fp && fp->fun ? fp->argc : fun->nargs));
else
case FUN_ARITY:
@ -1633,7 +1633,7 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
#endif
fun = js_NewFunction(cx, obj, NULL, 0, JSFUN_LAMBDA, parent,
JSVERSION_IS_ECMA(cx->version)
JS_VERSION_IS_ECMA(cx)
? cx->runtime->atomState.anonymousAtom
: NULL);

Просмотреть файл

@ -1127,7 +1127,7 @@ js_Invoke(JSContext *cx, uintN argc, uintN flags)
* We attempt the conversion under all circumstances for 1.2, but
* only if there is a call op defined otherwise.
*/
if (cx->version == JSVERSION_1_2 ||
if (JS_VERSION_IS_1_2(cx) ||
((ops == &js_ObjectOps) ? clasp->call : ops->call)) {
ok = clasp->convert(cx, funobj, JSTYPE_FUNCTION, &v);
if (!ok)
@ -1836,7 +1836,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
/*
* Optimized Get and SetVersion for proper script language versioning.
*
* If any native method or JSClass/JSObjectOps hook calls JS_SetVersion
* If any native method or JSClass/JSObjectOps hook calls js_SetVersion
* and changes cx->version, the effect will "stick" and we will stop
* maintaining currentVersion. This is relied upon by testsuites, for
* the most part -- web browsers select version before compiling and not
@ -1845,7 +1845,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
currentVersion = script->version;
originalVersion = cx->version;
if (currentVersion != originalVersion)
JS_SetVersion(cx, currentVersion);
js_SetVersion(cx, currentVersion);
/*
* Prepare to call a user-supplied branch handler, and abort the script
@ -2041,7 +2041,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
if (cx->version == currentVersion) {
currentVersion = ifp->callerVersion;
if (currentVersion != cx->version)
JS_SetVersion(cx, currentVersion);
js_SetVersion(cx, currentVersion);
}
/* Store the return value in the caller's operand frame. */
@ -2453,7 +2453,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
rval = STRING_TO_JSVAL(str);
}
#endif
else if (cx->version != JSVERSION_1_2) {
else if (!JS_VERSION_IS_1_2(cx)) {
str = js_NumberToString(cx, (jsdouble) JSID_TO_INT(fid));
if (!str) {
ok = JS_FALSE;
@ -3132,7 +3132,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
/* Check the return value and update obj from it. */
rval = *vp;
if (JSVAL_IS_PRIMITIVE(rval)) {
if (fun || !JSVERSION_IS_ECMA(cx->version)) {
if (fun || !JS_VERSION_IS_ECMA(cx)) {
*vp = OBJECT_TO_JSVAL(obj);
break;
}
@ -3536,7 +3536,7 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
if (cx->version == currentVersion) {
currentVersion = script->version;
if (currentVersion != cx->version)
JS_SetVersion(cx, currentVersion);
js_SetVersion(cx, currentVersion);
}
/* Push the frame and set interpreter registers. */
@ -3829,8 +3829,8 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
* the default case if the discriminant isn't already an int jsval.
* (This opcode is emitted only for dense jsint-domain switches.)
*/
if (cx->version == JSVERSION_DEFAULT ||
cx->version >= JSVERSION_1_4) {
if ((cx->version & JSVERSION_MASK) == JSVERSION_DEFAULT ||
(cx->version & JSVERSION_MASK) >= JSVERSION_1_4) {
rval = POP_OPND();
if (!JSVAL_IS_INT(rval))
break;
@ -3912,8 +3912,8 @@ js_Interpret(JSContext *cx, jsbytecode *pc, jsval *result)
* the default case if the discriminant isn't already an int jsval.
* (This opcode is emitted only for dense jsint-domain switches.)
*/
if (cx->version == JSVERSION_DEFAULT ||
cx->version >= JSVERSION_1_4) {
if ((cx->version & JSVERSION_MASK) == JSVERSION_DEFAULT ||
(cx->version & JSVERSION_MASK) >= JSVERSION_1_4) {
rval = POP_OPND();
if (!JSVAL_IS_INT(rval))
break;
@ -5335,7 +5335,7 @@ out2:
fp->spbase = NULL;
js_FreeRawStack(cx, mark);
if (cx->version == currentVersion && currentVersion != originalVersion)
JS_SetVersion(cx, originalVersion);
js_SetVersion(cx, originalVersion);
cx->interpLevel--;
return ok;

Просмотреть файл

@ -636,7 +636,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
* obj_toString for 1.2 calls toSource, and doesn't want the extra parens
* on the outside.
*/
outermost = (cx->version != JSVERSION_1_2 && cx->sharpObjectMap.depth == 0);
outermost = !JS_VERSION_IS_1_2(cx) && cx->sharpObjectMap.depth == 0;
he = js_EnterSharpObject(cx, obj, &ida, &chars);
if (!he)
return JS_FALSE;
@ -960,7 +960,7 @@ js_obj_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
JSString *str;
#if JS_HAS_INITIALIZERS
if (cx->version == JSVERSION_1_2)
if (JS_VERSION_IS_1_2(cx))
return js_obj_toSource(cx, obj, argc, argv, rval);
#endif
@ -1016,7 +1016,7 @@ obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
caller = JS_GetScriptedCaller(cx, fp);
indirectCall = (caller && caller->pc && *caller->pc != JSOP_EVAL);
if (JSVERSION_IS_ECMA(cx->version) &&
if (JS_VERSION_IS_ECMA(cx) &&
indirectCall &&
!JS_ReportErrorFlagsAndNumber(cx,
JSREPORT_WARNING | JSREPORT_STRICT,
@ -2774,7 +2774,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
if ((attrs & JSPROP_READONLY) ||
(SCOPE_IS_SEALED(scope) && pobj == obj)) {
JS_UNLOCK_SCOPE(cx, scope);
if ((attrs & JSPROP_READONLY) && JSVERSION_IS_ECMA(cx->version))
if ((attrs & JSPROP_READONLY) && JS_VERSION_IS_ECMA(cx))
return JS_TRUE;
goto read_only_error;
}
@ -2972,7 +2972,7 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
JSScope *scope;
JSBool ok;
*rval = JSVERSION_IS_ECMA(cx->version) ? JSVAL_TRUE : JSVAL_VOID;
*rval = JS_VERSION_IS_ECMA(cx) ? JSVAL_TRUE : JSVAL_VOID;
/*
* Handle old bug that took empty string as zero index. Also convert
@ -3012,7 +3012,7 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
sprop = (JSScopeProperty *)prop;
if (sprop->attrs & JSPROP_PERMANENT) {
OBJ_DROP_PROPERTY(cx, obj, prop);
if (JSVERSION_IS_ECMA(cx->version)) {
if (JS_VERSION_IS_ECMA(cx)) {
*rval = JSVAL_FALSE;
return JS_TRUE;
}
@ -3078,7 +3078,7 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
* object to a string. ECMA requires an error if both toString
* and valueOf fail to produce a primitive value.
*/
if (!JSVAL_IS_PRIMITIVE(v) && cx->version == JSVERSION_1_2) {
if (!JSVAL_IS_PRIMITIVE(v) && JS_VERSION_IS_1_2(cx)) {
char *bytes = JS_smprintf("[object %s]",
OBJ_GET_CLASS(cx, obj)->name);
if (!bytes)
@ -3104,7 +3104,7 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
goto out;
}
/* Don't convert to string (source object literal) for JS1.2. */
if (cx->version == JSVERSION_1_2 && hint == JSTYPE_BOOLEAN)
if (JS_VERSION_IS_1_2(cx) && hint == JSTYPE_BOOLEAN)
goto out;
if (!js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0,
NULL, &v))

Просмотреть файл

@ -2191,7 +2191,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
lval,
(op == JSOP_NEW_EQ) ? '=' : '!',
#if JS_HAS_TRIPLE_EQOPS
JSVERSION_IS_ECMA(cx->version) ? "==" :
JS_VERSION_IS_ECMA(cx) ? "==" :
#endif
"=",
rval);

Просмотреть файл

@ -1082,7 +1082,7 @@ Condition(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
pn->pn_op == JSOP_NOP &&
pn->pn_right->pn_type > TOK_EQOP)
{
JSBool rewrite = !JSVERSION_IS_ECMA(cx->version);
JSBool rewrite = !JS_VERSION_IS_ECMA(cx);
if (!js_ReportCompileErrorNumber(cx, ts,
JSREPORT_TS |
JSREPORT_WARNING |
@ -1457,7 +1457,7 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc)
js_PopStatement(tc);
pn->pn_pos.end = pn2->pn_pos.end;
pn->pn_right = pn2;
if (cx->version != JSVERSION_ECMA_3) {
if ((cx->version & JSVERSION_MASK) != JSVERSION_ECMA_3) {
/*
* All legacy and extended versions must do automatic semicolon
* insertion after do-while. See the testcase and discussion in

Просмотреть файл

@ -3096,7 +3096,7 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
res->lastMatch.chars = cp;
res->lastMatch.length = matchlen;
if (cx->version == JSVERSION_1_2) {
if (JS_VERSION_IS_1_2(cx)) {
/*
* JS1.2 emulated Perl4.0.1.8 (patch level 36) for global regexps used
* in scalar contexts, and unintentionally for the string.match "list"

Просмотреть файл

@ -1267,7 +1267,8 @@ retry:
if (!hadUnicodeEscape && ATOM_KEYWORD(atom)) {
struct keyword *kw = ATOM_KEYWORD(atom);
if (JSVERSION_IS_ECMA(cx->version) || kw->version <= cx->version) {
if (JS_VERSION_IS_ECMA(cx) ||
kw->version <= (cx->version & JSVERSION_MASK)) {
tt = kw->tokentype;
tp->t_op = (JSOp) kw->op;
goto out;
@ -1433,7 +1434,7 @@ retry:
c = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]);
SkipChars(ts, 2);
}
} else if (c == '\n' && JSVERSION_IS_ECMA(cx->version)) {
} else if (c == '\n' && JS_VERSION_IS_ECMA(cx)) {
/* ECMA follows C by removing escaped newlines. */
continue;
}

Просмотреть файл

@ -530,7 +530,7 @@ str_enumerate(JSContext *cx, JSObject *obj)
size_t i, length;
/* Avoid infinite recursion via js_obj_toSource (see bug 271477). */
if (cx->version == JSVERSION_1_2)
if (JS_VERSION_IS_1_2(cx))
return JS_TRUE;
str = js_ValueToString(cx, OBJECT_TO_JSVAL(obj));
@ -707,7 +707,7 @@ str_substring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
else if (end > length)
end = length;
if (end < begin) {
if (cx->version != JSVERSION_1_2) {
if (!JS_VERSION_IS_1_2(cx)) {
/* XXX emulate old JDK1.0 java.lang.String.substring. */
jsdouble tmp = begin;
begin = end;
@ -1277,6 +1277,7 @@ typedef struct ReplaceData {
static JSSubString *
interpret_dollar(JSContext *cx, jschar *dp, ReplaceData *rdata, size_t *skip)
{
JSVersion version;
JSRegExpStatics *res;
jschar dc, *cp;
uintN num, tmp;
@ -1288,7 +1289,8 @@ interpret_dollar(JSContext *cx, jschar *dp, ReplaceData *rdata, size_t *skip)
* Allow a real backslash (literal "\\" before "$1") to escape "$1", e.g.
* Do this only for versions strictly less than ECMAv3.
*/
if (cx->version != JSVERSION_DEFAULT && cx->version <= JSVERSION_1_4) {
version = cx->version & JSVERSION_MASK;
if (version != JSVERSION_DEFAULT && version <= JSVERSION_1_4) {
if (dp > JSSTRING_CHARS(rdata->repstr) && dp[-1] == '\\')
return NULL;
}
@ -1297,7 +1299,7 @@ interpret_dollar(JSContext *cx, jschar *dp, ReplaceData *rdata, size_t *skip)
res = &cx->regExpStatics;
dc = dp[1];
if (JS7_ISDEC(dc)) {
if (cx->version != JSVERSION_DEFAULT && cx->version <= JSVERSION_1_4) {
if (version != JSVERSION_DEFAULT && version <= JSVERSION_1_4) {
if (dc == '0')
return NULL;
@ -1343,7 +1345,7 @@ interpret_dollar(JSContext *cx, jschar *dp, ReplaceData *rdata, size_t *skip)
case '+':
return &res->lastParen;
case '`':
if (cx->version == JSVERSION_1_2) {
if (version == JSVERSION_1_2) {
/*
* JS1.2 imitated the Perl4 bug where left context at each step
* in an iterative use of a global regexp started from last match,
@ -1560,6 +1562,7 @@ str_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSObject *lambda;
JSString *repstr, *str;
ReplaceData rdata;
JSVersion version;
JSBool ok;
jschar *chars;
size_t leftlen, rightlen, length;
@ -1583,7 +1586,8 @@ str_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
* special meanings) UNLESS the first arg is a RegExp object.
*/
rdata.base.flags = MODE_REPLACE | KEEP_REGEXP;
if (cx->version == JSVERSION_DEFAULT || cx->version > JSVERSION_1_4)
version = cx->version & JSVERSION_MASK;
if (version == JSVERSION_DEFAULT || version > JSVERSION_1_4)
rdata.base.flags |= FORCE_FLAT;
rdata.base.optarg = 2;
@ -1698,7 +1702,7 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
*/
chars = JSSTRING_CHARS(str);
length = JSSTRING_LENGTH(str);
if (cx->version == JSVERSION_1_2 &&
if (JS_VERSION_IS_1_2(cx) &&
!re && *sep->chars == ' ' && sep->chars[1] == 0) {
/* Skip leading whitespace if at front of str. */
@ -1761,7 +1765,7 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
* sep->length to our return value.
*/
if ((size_t)i == length) {
if (cx->version == JSVERSION_1_2) {
if (JS_VERSION_IS_1_2(cx)) {
sep->length = 1;
return i;
}
@ -1781,7 +1785,7 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
* string into a non-empty array (an array of length 1 that contains the
* empty string).
*/
if (!JSVERSION_IS_ECMA(cx->version) && length == 0)
if (!JS_VERSION_IS_ECMA(cx) && length == 0)
return -1;
/*
@ -1794,7 +1798,7 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
* to include an additional null string at the end of the substring list.
*/
if (sep->length == 0) {
if (cx->version == JSVERSION_1_2) {
if (JS_VERSION_IS_1_2(cx)) {
if ((size_t)i == length) {
sep->length = 1;
return i;
@ -1926,7 +1930,7 @@ str_split(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
}
#endif
i = j + sep->length;
if (!JSVERSION_IS_ECMA(cx->version)) {
if (!JS_VERSION_IS_ECMA(cx)) {
/*
* Deviate from ECMA to imitate Perl, which omits a final
* split unless a limit argument is given and big enough.