Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Add back in evalFile with deprecation warning. Revert to using getCur…
Browse files Browse the repository at this point in the history
…rentContext to get the Rhino Context.
  • Loading branch information
Tom Robinson committed Mar 2, 2010
1 parent 05ddc04 commit 3fc08ff
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions engines/rhino/lib/interpreter.js
Expand Up @@ -9,14 +9,20 @@
var Context = exports.Context = function() { var Context = exports.Context = function() {
var self = this; var self = this;


var context = new Packages.org.mozilla.javascript.Context(); // TODO: verify this is the correct way to obtain a Context.
self.global = context.initStandardObjects(); // var context = new Packages.org.mozilla.javascript.Context();
function getContext() {
// return context;
return Packages.org.mozilla.javascript.Context.getCurrentContext();
}

self.global = getContext().initStandardObjects();


self.eval = function(source) { self.eval = function(source) {
source = source || ""; source = source || "";
var sourceURL = findSourceURL(source) || "<eval>"; var sourceURL = findSourceURL(source) || "<eval>";


return context.evaluateString( return getContext().evaluateString(
self.global, self.global,
source, source,
sourceURL, sourceURL,
Expand All @@ -25,8 +31,13 @@ var Context = exports.Context = function() {
); );
}; };


self.evalFile = function(sourceURL) {
require("narwhal").deprecated("Context's evalFile() is deprecated in favor of importScript().");
return self.importScript.apply(self, arguments);
};

self.importScript = function (sourceURL) { self.importScript = function (sourceURL) {
return context.evaluateReader( return getContext().evaluateReader(
self.global, self.global,
new Packages.java.io.FileReader(sourceURL), new Packages.java.io.FileReader(sourceURL),
sourceURL, sourceURL,
Expand All @@ -47,7 +58,7 @@ var Context = exports.Context = function() {
for (var name in inject) for (var name in inject)
if (Object.prototype.hasOwnProperty.call(inject, name)) if (Object.prototype.hasOwnProperty.call(inject, name))
names.push(name); names.push(name);
return context.compileFunction( return getContext().compileFunction(
self.global, self.global,
"function(" + names.join(",") + "){" + text + "\n}", "function(" + names.join(",") + "){" + text + "\n}",
String(fileName), String(fileName),
Expand All @@ -64,16 +75,16 @@ var Context = exports.Context = function() {
var body = args.pop() || ""; var body = args.pop() || "";
var source = "function("+args.join(",")+"){"+body+"/**/\n}"; var source = "function("+args.join(",")+"){"+body+"/**/\n}";
var sourceURL = findSourceURL(body) || "<function>"; var sourceURL = findSourceURL(body) || "<function>";

return context.compileFunction( return getContext().compileFunction(
self.global, self.global,
source, source,
sourceURL, sourceURL,
1, 1,
null null
); );
}; };

return self; return self;
}; };


Expand Down

0 comments on commit 3fc08ff

Please sign in to comment.