Bug 596580: fix versioning on mozJSSubScriptLoader. (r=sayrer,brendan)

--HG--
extra : rebase_source : fb2fe804a3f94bc9d6947605ce0e0c19a29b2227
This commit is contained in:
Chris Leary 2010-09-23 14:48:58 -07:00
parent f0f46d8ec8
commit 379f9466a6
5 changed files with 49 additions and 2 deletions

View File

@ -4807,6 +4807,16 @@ JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj, JSPrincipals *princ
return ok;
}
JS_PUBLIC_API(JSBool)
JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj, JSPrincipals *principals,
const char *bytes, uintN nbytes,
const char *filename, uintN lineno, jsval *rval, JSVersion version)
{
AutoVersionAPI avi(cx, version);
return JS_EvaluateScriptForPrincipals(cx, obj, principals, bytes, nbytes, filename, lineno,
rval);
}
JS_PUBLIC_API(JSBool)
JS_EvaluateScript(JSContext *cx, JSObject *obj, const char *bytes, uintN nbytes,
const char *filename, uintN lineno, jsval *rval)

View File

@ -2582,6 +2582,13 @@ JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
const char *filename, uintN lineno,
jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
JSPrincipals *principals,
const char *bytes, uintN length,
const char *filename, uintN lineno,
jsval *rval, JSVersion version);
extern JS_PUBLIC_API(JSBool)
JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
const jschar *chars, uintN length,

View File

@ -60,6 +60,8 @@
#include "jsapi.h"
#include "jsdbgapi.h"
#include "jsobj.h"
#include "jsscript.h"
#include "jscntxt.h"
#include "mozilla/FunctionTimer.h"
@ -233,6 +235,7 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
JSStackFrame* frame = nsnull;
JSScript* script = nsnull;
JSVersion version;
// Figure out who's calling us
do
@ -348,8 +351,12 @@ mozJSSubScriptLoader::LoadSubScript (const PRUnichar * aURL
* exceptions, including the source/line number */
er = JS_SetErrorReporter (cx, mozJSLoaderErrorReporter);
ok = JS_EvaluateScriptForPrincipals (cx, target_obj, jsPrincipals,
buf, len, uriStr.get(), 1, rval);
version = script->getVersion();
version = JSVersion((version & js::VersionFlags::MASK)
| (version & js::VersionFlags::HAS_XML));
ok = JS_EvaluateScriptForPrincipalsVersion(cx, target_obj, jsPrincipals,
buf, len, uriStr.get(), 1,
rval, version);
/* repent for our evil deeds */
JS_SetErrorReporter (cx, er);

View File

@ -0,0 +1,4 @@
/* Some constructs that require a high default version number. */
let x = 12;
function simpleGen() { yield 12; }
var e4xy = <html><title>Huzzah!</title></html>

View File

@ -0,0 +1,19 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
function run_test() {
var file = do_get_file("bug596580_versioned.js");
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var uri = ios.newFileURI(file);
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
scriptLoader.loadSubScript(uri.spec);
version(150)
try {
scriptLoader.loadSubScript(uri.spec);
throw new Exception("Subscript should fail to load.");
} catch (e if e instanceof SyntaxError) {
// Okay.
}
}