Back out due to mochiserver breakage. (no_r=me)

This commit is contained in:
Chris Leary 2010-09-09 16:52:31 -07:00
Родитель 09eb112ae9
Коммит 813d1e57f3
23 изменённых файлов: 226 добавлений и 240 удалений

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

@ -468,7 +468,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// We re-use our knowledge of the implementation to reuse
// JSVERSION_HAS_XML as a safe version flag.
// If version has JSVERSION_UNKNOWN (-1), then this is still OK.
version |= js::VersionFlags::HAS_XML;
version |= JSVERSION_HAS_XML;
}
}
} else {

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

@ -1058,7 +1058,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
// our implementation knowledge to reuse JSVERSION_HAS_XML as a
// safe version flag. This is still OK if version is
// JSVERSION_UNKNOWN (-1),
version |= js::VersionFlags::HAS_XML;
version |= JSVERSION_HAS_XML;
nsAutoString value;
rv = parser.GetParameter("e4x", value);
@ -1067,7 +1067,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
return rv;
} else {
if (value.Length() == 1 && value[0] == '0')
version &= ~js::VersionFlags::HAS_XML;
version &= ~JSVERSION_HAS_XML;
}
}
}
@ -1081,7 +1081,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
// Even when JS version < 1.6 is specified, E4X is
// turned on in XUL.
version |= js::VersionFlags::HAS_XML;
version |= JSVERSION_HAS_XML;
}
}
aAttributes += 2;

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

@ -326,10 +326,10 @@ private:
nsJSVersionSetter::nsJSVersionSetter(JSContext *aContext, PRUint32 aVersion)
: mContext(aContext)
{
// HAS_XML may be set in our version mask - however, we can't
// JSVERSION_HAS_XML may be set in our version mask - however, we can't
// simply pass this directly to JS_SetOptions as it masks out that bit -
// the only way to make this happen is via JS_SetOptions.
JSBool hasxml = (aVersion & js::VersionFlags::HAS_XML) != 0;
JSBool hasxml = (aVersion & JSVERSION_HAS_XML) != 0;
mOldOptions = ::JS_GetOptions(mContext);
mOptionsChanged = ((hasxml) ^ !!(mOldOptions & JSOPTION_XML));
@ -342,7 +342,7 @@ nsJSVersionSetter::nsJSVersionSetter(JSContext *aContext, PRUint32 aVersion)
// Change the version - this is cheap when the versions match, so no need
// to optimize here...
JSVersion newVer = (JSVersion)(aVersion & js::VersionFlags::MASK);
JSVersion newVer = (JSVersion)(aVersion & JSVERSION_MASK);
mOldVersion = ::JS_SetVersion(mContext, newVer);
}

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

@ -982,25 +982,27 @@ JS_ContextIterator(JSRuntime *rt, JSContext **iterp)
JS_PUBLIC_API(JSVersion)
JS_GetVersion(JSContext *cx)
{
return VersionNumber(cx->findVersion());
return JSVERSION_NUMBER(cx);
}
JS_PUBLIC_API(JSVersion)
JS_SetVersion(JSContext *cx, JSVersion newVersion)
JS_SetVersion(JSContext *cx, JSVersion version)
{
JS_ASSERT(VersionIsKnown(newVersion));
JS_ASSERT(!VersionHasFlags(newVersion));
JSVersion oldVersion;
JSVersion oldVersion = VersionNumber(cx->findVersion());
if (oldVersion == newVersion)
return oldVersion; /* No override actually occurs! */
JS_ASSERT(version != JSVERSION_UNKNOWN);
JS_ASSERT((version & ~JSVERSION_MASK) == 0);
/* We no longer support 1.4 or below. */
if (newVersion != JSVERSION_DEFAULT && newVersion <= JSVERSION_1_4)
oldVersion = JSVERSION_NUMBER(cx);
if (version == oldVersion)
return oldVersion;
VersionCloneFlags(oldVersion, &newVersion);
cx->maybeOverrideVersion(newVersion);
/* We no longer support 1.4 or below. */
if (version != JSVERSION_DEFAULT && version <= JSVERSION_1_4)
return oldVersion;
cx->version = (cx->version & ~JSVERSION_MASK) | version;
js_OnVersionChange(cx);
return oldVersion;
}
@ -1057,8 +1059,7 @@ JS_SetOptions(JSContext *cx, uint32 options)
AutoLockGC lock(cx->runtime);
uint32 oldopts = cx->options;
cx->options = options;
SyncOptionsToVersion(cx);
JS_ASSERT_IF(options & JSOPTION_XML, VersionHasXML(cx->findVersion()));
js_SyncOptionsToVersion(cx);
cx->updateJITEnabled();
return oldopts;
}
@ -1069,7 +1070,7 @@ JS_ToggleOptions(JSContext *cx, uint32 options)
AutoLockGC lock(cx->runtime);
uint32 oldopts = cx->options;
cx->options ^= options;
SyncOptionsToVersion(cx);
js_SyncOptionsToVersion(cx);
cx->updateJITEnabled();
return oldopts;
}

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

@ -683,19 +683,54 @@ js_PurgeThreads(JSContext *cx)
#endif
}
/*
* JSOPTION_XML and JSOPTION_ANONFUNFIX must be part of the JS version
* associated with scripts, so in addition to storing them in cx->options we
* duplicate them in cx->version (script->version, etc.) and ensure each bit
* remains synchronized between the two through these two functions.
*/
void
js::SyncOptionsToVersion(JSContext* cx)
js_SyncOptionsToVersion(JSContext* cx)
{
JSVersion version = cx->findVersion();
bool shouldHaveXML = !!(cx->options & JSOPTION_XML);
bool shouldHaveAnonFunFix = !!(cx->options & JSOPTION_ANONFUNFIX);
if (shouldHaveXML == VersionHasXML(version) &&
shouldHaveAnonFunFix == VersionHasAnonFunFix(version))
return; /* No need to override. */
VersionSetXML(&version, shouldHaveXML);
VersionSetAnonFunFix(&version, shouldHaveAnonFunFix);
cx->maybeOverrideVersion(version);
JS_ASSERT_IF(shouldHaveXML, VersionHasXML(cx->findVersion()));
if (cx->options & JSOPTION_XML)
cx->version |= JSVERSION_HAS_XML;
else
cx->version &= ~JSVERSION_HAS_XML;
if (cx->options & JSOPTION_ANONFUNFIX)
cx->version |= JSVERSION_ANONFUNFIX;
else
cx->version &= ~JSVERSION_ANONFUNFIX;
}
inline void
js_SyncVersionToOptions(JSContext* cx)
{
if (cx->version & JSVERSION_HAS_XML)
cx->options |= JSOPTION_XML;
else
cx->options &= ~JSOPTION_XML;
if (cx->version & JSVERSION_ANONFUNFIX)
cx->options |= JSOPTION_ANONFUNFIX;
else
cx->options &= ~JSOPTION_ANONFUNFIX;
}
void
js_OnVersionChange(JSContext *cx)
{
#ifdef DEBUG
JSVersion version = JSVERSION_NUMBER(cx);
JS_ASSERT(version == JSVERSION_DEFAULT || version >= JSVERSION_ECMA_3);
#endif
}
void
js_SetVersion(JSContext *cx, JSVersion version)
{
cx->version = version;
js_SyncVersionToOptions(cx);
js_OnVersionChange(cx);
}
JSContext *
@ -721,7 +756,7 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
#endif
cx->scriptStackQuota = JS_DEFAULT_SCRIPT_STACK_QUOTA;
JS_STATIC_ASSERT(JSVERSION_DEFAULT == 0);
JS_ASSERT(cx->findVersion() == JSVERSION_DEFAULT);
JS_ASSERT(cx->version == JSVERSION_DEFAULT);
VOUCH_DOES_NOT_REQUIRE_STACK();
JS_InitArenaPool(&cx->tempPool, "temp", TEMP_POOL_CHUNK_SIZE, sizeof(jsdouble),

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

@ -1979,78 +1979,6 @@ class RegExpStatics
void getRightContext(JSSubString *out) const;
};
#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)
namespace VersionFlags {
static const uint32 MASK = 0x0FFF; /* see JSVersion in jspubtd.h */
static const uint32 HAS_XML = 0x1000; /* flag induced by XML option */
static const uint32 ANONFUNFIX = 0x2000; /* see jsapi.h comment on JSOPTION_ANONFUNFIX */
}
static inline bool
VersionHasXML(JSVersion version)
{
return !!(version & VersionFlags::HAS_XML);
}
static inline bool
VersionHasAnonFunFix(JSVersion version)
{
return !!(version & VersionFlags::ANONFUNFIX);
}
static inline void
VersionSetXML(JSVersion *version, bool enable)
{
if (enable)
*version = JSVersion(uint32(*version) | VersionFlags::HAS_XML);
else
*version = JSVersion(uint32(*version) & ~VersionFlags::HAS_XML);
}
static inline void
VersionSetAnonFunFix(JSVersion *version, bool enable)
{
if (enable)
*version = JSVersion(uint32(*version) | VersionFlags::ANONFUNFIX);
else
*version = JSVersion(uint32(*version) & ~VersionFlags::ANONFUNFIX);
}
static inline JSVersion
VersionExtractFlags(JSVersion version)
{
return JSVersion(uint32(version) & ~VersionFlags::MASK);
}
static inline bool
VersionHasFlags(JSVersion version)
{
return !!VersionExtractFlags(version);
}
static inline JSVersion
VersionNumber(JSVersion version)
{
return JSVersion(uint32(version) & VersionFlags::MASK);
}
static inline bool
VersionIsKnown(JSVersion version)
{
return VersionNumber(version) != JSVERSION_UNKNOWN;
}
static inline void
VersionCloneFlags(JSVersion src, JSVersion *dst)
{
*dst = JSVersion(uint32(VersionNumber(*dst)) | uint32(VersionExtractFlags(src)));
}
} /* namespace js */
struct JSContext
@ -2060,13 +1988,9 @@ struct JSContext
/* JSRuntime contextList linkage. */
JSCList link;
private:
/* See JSContext::findVersion. */
JSVersion defaultVersion; /* script compilation version */
JSVersion versionOverride; /* supercedes defaultVersion when valid */
bool hasVersionOverride;
/* Runtime version control identifier. */
uint16 version;
public:
/* Per-context options. */
uint32 options; /* see jsapi.h for JSOPTION_* */
@ -2225,9 +2149,11 @@ struct JSContext
*/
js::StackSegment *containingSegment(const JSStackFrame *target);
/* Search the call stack for the nearest frame with static level targetLevel. */
JSStackFrame *findFrameAtLevel(uintN targetLevel) const {
JSStackFrame *fp = regs->fp;
/*
* Search the call stack for the nearest frame with static level targetLevel.
*/
JSStackFrame *findFrameAtLevel(uintN targetLevel) {
JSStackFrame *fp = this->regs->fp;
while (true) {
JS_ASSERT(fp && fp->hasScript());
if (fp->getScript()->staticLevel == targetLevel)
@ -2237,58 +2163,6 @@ struct JSContext
return fp;
}
void clearVersionOverride() { hasVersionOverride = false; }
private:
/* Set the default script compilation version. */
void setDefaultVersion(JSVersion version) { defaultVersion = version; }
/*
* The default script compilation version can be set iff there is no code running.
* This typically occurs via the JSAPI right after a context is constructed.
*/
bool canSetDefaultVersion() const { return !regs && !hasVersionOverride; }
/* Force a version for future script compilation. */
void overrideVersion(JSVersion newVersion) {
JS_ASSERT(!canSetDefaultVersion());
versionOverride = newVersion;
hasVersionOverride = true;
}
public:
/* Set the default version if possible; otherwise, force the version. */
void maybeOverrideVersion(JSVersion newVersion) {
if (canSetDefaultVersion())
setDefaultVersion(newVersion);
else
overrideVersion(newVersion);
}
/*
* Return:
* - The override version, if there is an override version.
* - The newest scripted frame's version, if there is such a frame.
* - The default verion.
*
* @note If this ever shows up in a profile, just add caching!
*/
JSVersion findVersion() const {
if (hasVersionOverride)
return versionOverride;
if (regs) {
/* There may be a scripted function somewhere on the stack! */
JSStackFrame *fp = regs->fp;
while (fp && !fp->hasScript())
fp = fp->down;
if (fp)
return fp->getScript()->getVersion();
}
return defaultVersion;
}
#ifdef JS_THREADSAFE
JSThread *thread;
unsigned outstandingRequests;/* number of JS_BeginRequest calls
@ -3057,6 +2931,49 @@ class JSAutoResolveFlags
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/*
* 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_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 JSVERSION_ANONFUNFIX 0x2000 /* see jsapi.h, the comments
for JSOPTION_ANONFUNFIX */
#define JSVERSION_NUMBER(cx) ((JSVersion)((cx)->version & \
JSVERSION_MASK))
#define JS_HAS_XML_OPTION(cx) ((cx)->version & JSVERSION_HAS_XML || \
JSVERSION_NUMBER(cx) >= JSVERSION_1_6)
extern JSThreadData *
js_CurrentThreadData(JSRuntime *rt);
@ -3110,14 +3027,29 @@ class ThreadDataIter
#endif /* !JS_THREADSAFE */
} /* namespace js */
/*
* If necessary, push the option flags that affect script compilation to the current version.
* Note this may cause a version override -- see JSContext::overrideVersion.
* Ensures the JSOPTION_XML and JSOPTION_ANONFUNFIX bits of cx->options are
* reflected in cx->version, since each bit must travel with a script that has
* it set.
*/
extern void
SyncOptionsToVersion(JSContext *cx);
js_SyncOptionsToVersion(JSContext *cx);
} /* namespace js */
/*
* 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

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

@ -1303,7 +1303,7 @@ JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
JS_PUBLIC_API(JSVersion)
JS_GetScriptVersion(JSContext *cx, JSScript *script)
{
return VersionNumber(script->getVersion());
return (JSVersion) (script->version & JSVERSION_MASK);
}
/***************************************************************************/
@ -1786,12 +1786,6 @@ JS_MakeSystemObject(JSContext *cx, JSObject *obj)
/************************************************************************/
JS_FRIEND_API(void)
js_RevertVersion(JSContext *cx)
{
cx->clearVersionOverride();
}
JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt)
{

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

@ -492,9 +492,6 @@ JS_MakeSystemObject(JSContext *cx, JSObject *obj);
/************************************************************************/
extern JS_FRIEND_API(void)
js_RevertVersion(JSContext *cx);
extern JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt);

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

@ -460,7 +460,7 @@ WrapEscapingClosure(JSContext *cx, JSStackFrame *fp, JSFunction *fun)
wscript->savedCallerFun = script->savedCallerFun;
wscript->hasSharps = script->hasSharps;
wscript->strictModeCode = script->strictModeCode;
wscript->setVersion(script->getVersion());
wscript->version = script->version;
wscript->nfixed = script->nfixed;
wscript->filename = script->filename;
wscript->lineno = script->lineno;
@ -2734,7 +2734,7 @@ Function(JSContext *cx, uintN argc, Value *vp)
/* Initialize a tokenstream that reads from the given string. */
TokenStream ts(cx);
if (!ts.init(cx->findVersion(), collected_args, args_length, NULL, filename, lineno)) {
if (!ts.init(collected_args, args_length, NULL, filename, lineno)) {
JS_ARENA_RELEASE(&cx->tempPool, mark);
return JS_FALSE;
}

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

@ -2167,6 +2167,7 @@ Interpret(JSContext *cx, JSStackFrame *entryFrame, uintN inlineCallCount, uintN
fp = cx->fp(); \
script = fp->getScript(); \
atoms = FrameAtomBase(cx, fp); \
currentVersion = (JSVersion) script->version; \
JS_ASSERT(cx->regs == &regs); \
if (cx->throwing) \
goto error; \
@ -2254,6 +2255,19 @@ Interpret(JSContext *cx, JSStackFrame *entryFrame, uintN inlineCallCount, uintN
++cx->interpLevel;
/*
* Optimized Get and SetVersion for proper script language versioning.
*
* If any native method or a Class or ObjectOps 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
* at run-time.
*/
JSVersion currentVersion = (JSVersion) script->version;
JSVersion originalVersion = (JSVersion) cx->version;
if (currentVersion != originalVersion)
js_SetVersion(cx, currentVersion);
#define CHECK_INTERRUPT_HANDLER() \
JS_BEGIN_MACRO \
if (cx->debugHooks->interruptHook) \
@ -2590,6 +2604,13 @@ BEGIN_CASE(JSOP_STOP)
Probes::exitJSFun(cx, fp->maybeFunction());
/* Restore context version only if callee hasn't set version. */
if (JS_LIKELY(cx->version == currentVersion)) {
currentVersion = fp->getCallerVersion();
if (currentVersion != cx->version)
js_SetVersion(cx, currentVersion);
}
/*
* If inline-constructing, replace primitive rval with the new object
* passed in via |this|, and instrument this constructor invocation.
@ -4525,6 +4546,14 @@ BEGIN_CASE(JSOP_APPLY)
Value *newsp = newfp->base();
SetValueRangeToUndefined(newfp->slots(), newsp);
/* Switch version if currentVersion wasn't overridden. */
newfp->setCallerVersion((JSVersion) cx->version);
if (JS_LIKELY(cx->version == currentVersion)) {
currentVersion = (JSVersion) newscript->version;
if (JS_UNLIKELY(currentVersion != cx->version))
js_SetVersion(cx, currentVersion);
}
/* Push the frame. */
stack.pushInlineFrame(cx, fp, regs.pc, newfp);
@ -6850,6 +6879,8 @@ END_CASE(JSOP_ARRAYPUSH)
JS_ASSERT_IF(!fp->isGenerator(), !js_IsActiveWithOrBlock(cx, fp->getScopeChain(), 0));
/* Undo the remaining effects committed on entry to Interpret. */
if (cx->version == currentVersion && currentVersion != originalVersion)
js_SetVersion(cx, originalVersion);
--cx->interpLevel;
return interpReturnOK;

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

@ -146,6 +146,7 @@ struct JSStackFrame
private:
/* Members only needed for inline calls. */
void *hookData; /* debugger call hook data */
JSVersion callerVersion; /* dynamic version of calling script */
public:
/* Get the frame's current bytecode, assuming |this| is in |cx|. */
@ -374,6 +375,20 @@ struct JSStackFrame
return offsetof(JSStackFrame, hookData);
}
/* Version accessors */
JSVersion getCallerVersion() const {
return callerVersion;
}
void setCallerVersion(JSVersion version) {
callerVersion = version;
}
static size_t offsetCallerVersion() {
return offsetof(JSStackFrame, callerVersion);
}
/* Script accessors */
bool hasScript() const {

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

@ -1167,11 +1167,10 @@ obj_eval(JSContext *cx, uintN argc, Value *vp)
JSScript **scriptp = bucket;
EVAL_CACHE_METER(probe);
JSVersion version = cx->findVersion();
while ((script = *scriptp) != NULL) {
if (script->savedCallerFun &&
script->staticLevel == staticLevel &&
script->getVersion() == version &&
script->version == cx->version &&
(script->principals == principals ||
(principals->subsume(principals, script->principals) &&
script->principals->subsume(script->principals, principals)))) {

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

@ -173,10 +173,9 @@ Parser::init(const jschar *base, size_t length,
FILE *fp, const char *filename, uintN lineno)
{
JSContext *cx = context;
version = cx->findVersion();
tempPoolMark = JS_ARENA_MARK(&cx->tempPool);
if (!tokenStream.init(version, base, length, fp, filename, lineno)) {
if (!tokenStream.init(base, length, fp, filename, lineno)) {
JS_ARENA_RELEASE(&cx->tempPool, tempPoolMark);
return false;
}
@ -4902,7 +4901,7 @@ Parser::statement()
PopStatement(tc);
pn->pn_pos.end = pn2->pn_pos.end;
pn->pn_right = pn2;
if (VersionNumber(version) != JSVERSION_ECMA_3) {
if (JSVERSION_NUMBER(context) != JSVERSION_ECMA_3) {
/*
* All legacy and extended versions must do automatic semicolon
* insertion after do-while. See the testcase and discussion in
@ -5005,7 +5004,7 @@ Parser::statement()
if (TokenKindIsDecl(tt)
? (pn1->pn_count > 1 || pn1->pn_op == JSOP_DEFCONST
#if JS_HAS_DESTRUCTURING
|| (VersionNumber(version) == JSVERSION_1_7 &&
|| (JSVERSION_NUMBER(context) == JSVERSION_1_7 &&
pn->pn_op == JSOP_ITER &&
!(pn->pn_iflags & JSITER_FOREACH) &&
(pn1->pn_head->pn_type == TOK_RC ||
@ -5019,7 +5018,7 @@ Parser::statement()
: (pn1->pn_type != TOK_NAME &&
pn1->pn_type != TOK_DOT &&
#if JS_HAS_DESTRUCTURING
((VersionNumber(version) == JSVERSION_1_7 &&
((JSVERSION_NUMBER(context) == JSVERSION_1_7 &&
pn->pn_op == JSOP_ITER &&
!(pn->pn_iflags & JSITER_FOREACH))
? (pn1->pn_type != TOK_RB || pn1->pn_count != 2)
@ -5156,7 +5155,7 @@ Parser::statement()
if (pn1 == pn2 && !CheckDestructuring(context, NULL, pn2, NULL, tc))
return NULL;
if (VersionNumber(version) == JSVERSION_1_7) {
if (JSVERSION_NUMBER(context) == JSVERSION_1_7) {
/*
* Destructuring for-in requires [key, value] enumeration
* in JS1.7.
@ -6859,7 +6858,7 @@ Parser::comprehensionTail(JSParseNode *kid, uintN blockid,
if (!CheckDestructuring(context, &data, pn3, NULL, tc))
return NULL;
if (VersionNumber(version) == JSVERSION_1_7) {
if (JSVERSION_NUMBER(context) == JSVERSION_1_7) {
/* Destructuring requires [key, value] enumeration in JS1.7. */
if (pn3->pn_type != TOK_RB || pn3->pn_count != 2) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_FOR_LEFTSIDE);
@ -7877,16 +7876,8 @@ Parser::xmlElementOrListRoot(JSBool allowList)
* that don't recognize <script>).
*/
oldopts = JS_SetOptions(context, context->options | JSOPTION_XML);
version = context->findVersion();
tokenStream.setVersion(version);
JS_ASSERT(VersionHasXML(version));
pn = xmlElementOrList(allowList);
JS_SetOptions(context, oldopts);
version = context->findVersion();
tokenStream.setVersion(version);
JS_ASSERT(!!(oldopts & JSOPTION_XML) == VersionHasXML(version));
return pn;
}

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

@ -994,7 +994,6 @@ struct Parser : private js::AutoGCRooter
uint32 functionCount; /* number of functions in current unit */
JSObjectBox *traceListHead; /* list of parsed object for GC tracing */
JSTreeContext *tc; /* innermost tree context (stack-allocated) */
JSVersion version; /* cached version to avoid repeated lookups */
/* Root atoms and objects allocated for the parsed tree. */
js::AutoKeepAtoms keepAtoms;

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

@ -185,16 +185,15 @@ TokenStream::TokenStream(JSContext *cx)
#endif
bool
TokenStream::init(JSVersion version, const jschar *base, size_t length, FILE *fp,
const char *fn, uintN ln)
TokenStream::init(const jschar *base, size_t length, FILE *fp, const char *fn, uintN ln)
{
this->version = version;
jschar *buf;
JS_ASSERT_IF(fp, !base);
JS_ASSERT_IF(!base, length == 0);
size_t nb = fp
? (UNGET_LIMIT + 2 * LINE_LIMIT) * sizeof(jschar) /* see below */
: (UNGET_LIMIT + 1 * LINE_LIMIT) * sizeof(jschar);
jschar *buf;
JS_ARENA_ALLOCATE_CAST(buf, jschar *, &cx->tempPool, nb);
if (!buf) {
js_ReportOutOfScriptQuota(cx);
@ -1103,7 +1102,7 @@ TokenStream::getTokenInternal()
JSMSG_RESERVED_ID, kw->chars)) {
goto error;
}
} else if (kw->version <= VersionNumber(version)) {
} else if (kw->version <= JSVERSION_NUMBER(cx)) {
tt = kw->tokentype;
tp->t_op = (JSOp) kw->op;
goto out;
@ -1439,7 +1438,7 @@ TokenStream::getTokenInternal()
* The check for this is in jsparse.cpp, Compiler::compileScript.
*/
if ((flags & TSF_OPERAND) &&
(VersionHasXML(version) || peekChar() != '!')) {
(JS_HAS_XML_OPTION(cx) || peekChar() != '!')) {
/* Check for XML comment or CDATA section. */
if (matchChar('!')) {
tokenbuf.clear();

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

@ -320,8 +320,7 @@ class TokenStream
* Create a new token stream, either from an input buffer or from a file.
* Return false on file-open or memory-allocation failure.
*/
bool init(JSVersion version, const jschar *base, size_t length, FILE *fp,
const char *filename, uintN lineno);
bool init(const jschar *base, size_t length, FILE *fp, const char *filename, uintN lineno);
void close();
~TokenStream() {}
@ -442,8 +441,6 @@ class TokenStream
return JS_FALSE;
}
void setVersion(JSVersion newVersion) { version = newVersion; }
private:
typedef struct TokenBuf {
jschar *base; /* base of line or stream buffer */
@ -514,7 +511,6 @@ class TokenStream
JSCharBuffer tokenbuf; /* current token string buffer */
bool maybeEOL[256]; /* probabilistic EOL lookup table */
bool maybeStrSpecial[256];/* speeds up string scanning */
JSVersion version; /* cached version number for scan */
};
} /* namespace js */

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

@ -162,7 +162,7 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, bool needMutableScript,
if (!script)
return JS_FALSE;
script->setVersion(JSVERSION_DEFAULT);
script->version = JSVERSION_DEFAULT;
script->noScriptRval = true;
script->code[0] = JSOP_STOP;
script->code[1] = SRC_NULL;
@ -176,8 +176,8 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, bool needMutableScript,
if (xdr->mode == JSXDR_ENCODE) {
prologLength = script->main - script->code;
JS_ASSERT(script->getVersion() != JSVERSION_UNKNOWN);
version = (uint32)script->getVersion() | (script->nfixed << 16);
JS_ASSERT((int16)script->version != JSVERSION_UNKNOWN);
version = (uint32)script->version | (script->nfixed << 16);
lineno = (uint32)script->lineno;
nslots = (uint32)script->nslots;
nslots = (uint32)((script->staticLevel << 16) | script->nslots);
@ -235,7 +235,7 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, bool needMutableScript,
return JS_FALSE;
script->main += prologLength;
script->setVersion(JSVersion(version & 0xffff));
script->version = JSVersion(version & 0xffff);
script->nfixed = uint16(version >> 16);
/* If we know nsrcnotes, we allocated space for notes in script. */
@ -880,7 +880,7 @@ js_NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
PodZero(script);
script->length = length;
script->setVersion(cx->findVersion());
script->version = cx->version;
cursor = (uint8 *)script + sizeof(JSScript);
if (nobjects != 0) {

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

@ -326,15 +326,6 @@ struct JSScript {
return getAtom(arr->vector[index].atomIndex);
}
JSVersion getVersion() const {
return JSVersion(version);
}
void setVersion(JSVersion newVersion) {
JS_ASSERT((newVersion & JS_BITMASK(16)) == uint32(newVersion));
version = newVersion;
}
inline JSFunction *getFunction(size_t index);
inline JSObject *getRegExp(size_t index);

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

@ -5706,6 +5706,12 @@ SynthesizeFrame(JSContext* cx, const FrameInfo& fi, JSObject* callee)
newfp->setThisValue(NullValue()); // will be updated in FlushNativeStackFrame
JS_ASSERT(!newfp->hasIMacroPC());
/*
* Note that fp->script is still the caller's script; set the callee
* inline frame's idea of caller version from its version.
*/
newfp->setCallerVersion((JSVersion) fp->getScript()->version);
/* Push inline frame. (Copied from js_Interpret.) */
stack.pushInlineFrame(cx, fp, fi.pc, newfp);

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

@ -273,6 +273,10 @@ mjit::Compiler::generatePrologue()
Address(JSFrameReg, offsetof(JSStackFrame, savedPC)));
#endif
/* :TODO: This is entirely wrong. */
masm.store32(Imm32(cx->version),
Address(JSFrameReg, JSStackFrame::offsetCallerVersion()));
/* Set cx->fp */
masm.loadPtr(FrameAddress(offsetof(VMFrame, cx)), Registers::ReturnReg);

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

@ -212,6 +212,8 @@ InlineReturn(VMFrame &f, JSBool ok)
fp->putActivationObjects(cx);
/* :TODO: version stuff */
if (fp->flags & JSFRAME_CONSTRUCTING && fp->getReturnValue().isPrimitive())
fp->setReturnValue(fp->getThisValue());
@ -387,6 +389,7 @@ stubs::CompileFunction(VMFrame &f)
fp->setBlockChain(NULL);
fp->setHookData(NULL);
fp->setAnnotation(NULL);
fp->setCallerVersion(fp->down->getCallerVersion());
fp->setScript(script);
fp->clearReturnValue();
#ifdef DEBUG
@ -479,6 +482,9 @@ CreateFrame(VMFrame &f, uint32 flags, uint32 argc)
if (fun->isHeavyweight() && !js_GetCallObject(cx, newfp))
return false;
/* :TODO: Switch version if currentVersion wasn't overridden. */
newfp->setCallerVersion((JSVersion)cx->version);
// Marker for debug support.
if (JSInterpreterHook hook = cx->debugHooks->callHook) {
newfp->setHookData(hook(cx, fp, JS_TRUE, 0,

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

@ -874,14 +874,6 @@ Version(JSContext *cx, uintN argc, jsval *vp)
return JS_TRUE;
}
static JSBool
RevertVersion(JSContext *cx, uintN argc, jsval *vp)
{
js_RevertVersion(cx);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
static JSBool
Options(JSContext *cx, uintN argc, jsval *vp)
{
@ -4089,7 +4081,6 @@ Wrap(JSContext *cx, uintN argc, jsval *vp)
/* We use a mix of JS_FS and JS_FN to test both kinds of natives. */
static JSFunctionSpec shell_functions[] = {
JS_FN("version", Version, 0,0),
JS_FN("revertVersion", RevertVersion, 0,0),
JS_FN("options", Options, 0,0),
JS_FN("load", Load, 1,0),
JS_FN("readline", ReadLine, 0,0),
@ -4189,8 +4180,7 @@ static const char shell_help_header[] =
"======= ===========\n";
static const char *const shell_help_messages[] = {
"version([number]) Get or force a script compilation version number",
"revertVersion() Revert previously set version number",
"version([number]) Get or set JavaScript version number",
"options([option ...]) Get or toggle JavaScript options",
"load(['foo.js' ...]) Load files named by string arguments",
"readline() Read a single line from stdin",

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

@ -209,11 +209,11 @@ function test()
{
var v = version(150);
f = new Function("return version(arguments[0])");
revertVersion();
version(v);
expect(150, f());
expect(150, eval("f()"));
//expect(150, eval("f()"));
expect(0, eval("f(0); f()"));
revertVersion();
version(v);
}
print("End of Tests");