Bug 467747 - JS version/option unsyncing results in JS modules not being loaded with the very latest JS version, resulting in syntax errors when loading modules that use new JS syntax. r=brendan

This commit is contained in:
Jeff Walden 2009-02-07 23:23:01 -08:00
Родитель 2d89d1039f
Коммит 0da0a96ffa
3 изменённых файлов: 45 добавлений и 15 удалений

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

@ -1191,24 +1191,12 @@ 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; \
if ((cx)->options & JSOPTION_ANONFUNFIX) \
(cx)->version |= JSVERSION_ANONFUNFIX; \
else \
(cx)->version &= ~JSVERSION_ANONFUNFIX; \
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);
js_SyncOptionsToVersion(cx);
return oldopts;
}
@ -1217,7 +1205,7 @@ JS_ToggleOptions(JSContext *cx, uint32 options)
{
uint32 oldopts = cx->options;
cx->options ^= options;
SYNC_OPTIONS_TO_VERSION(cx);
js_SyncOptionsToVersion(cx);
return oldopts;
}

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

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=80:
*
* ***** BEGIN LICENSE BLOCK *****
@ -61,6 +61,7 @@
#include "jsnum.h"
#include "jsobj.h"
#include "jsopcode.h"
#include "jspubtd.h"
#include "jsscan.h"
#include "jsscope.h"
#include "jsscript.h"
@ -207,6 +208,38 @@ js_InitContextThread(JSContext *cx, JSThread *thread)
#endif /* JS_THREADSAFE */
/*
* 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)
{
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)
{
@ -221,6 +254,7 @@ void
js_SetVersion(JSContext *cx, JSVersion version)
{
cx->version = version;
js_SyncVersionToOptions(cx);
js_OnVersionChange(cx);
}

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

@ -1157,6 +1157,14 @@ js_InitThreadPrivateIndex(void (*ptr)(void *));
extern JSBool
js_CleanupThreadPrivateData();
/*
* 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
js_SyncOptionsToVersion(JSContext *cx);
/*
* Common subroutine of JS_SetVersion and js_SetVersion, to update per-context
* data that depends on version.