From c0c59dd572012008b42d15c74f62b290960614a0 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Thu, 30 Oct 2003 16:40:39 +0000 Subject: [PATCH] Not to call Context.getContext() in TokenStrea/IRFactory, an explicit Context instance is passed to TokenStream constructor --- .../src/org/mozilla/javascript/Context.java | 25 +++---------------- .../src/org/mozilla/javascript/IRFactory.java | 2 +- .../org/mozilla/javascript/TokenStream.java | 6 +++-- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/Context.java b/js/rhino/src/org/mozilla/javascript/Context.java index 0c337aee469..d5bc20c2901 100644 --- a/js/rhino/src/org/mozilla/javascript/Context.java +++ b/js/rhino/src/org/mozilla/javascript/Context.java @@ -49,7 +49,6 @@ package org.mozilla.javascript; import java.beans.*; import java.io.*; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Locale; import java.util.ResourceBundle; @@ -930,7 +929,7 @@ public class Context { { // no source name or source text manager, because we're just // going to throw away the result. - TokenStream ts = new TokenStream(null, source, false, null, 1, + TokenStream ts = new TokenStream(this, null, source, false, null, 1, new DefaultErrorReporter()); boolean errorseen = false; @@ -1895,24 +1894,6 @@ public class Context { return formatter.format(arguments); } - private static String readReader(Reader r) - throws IOException - { - char[] buffer = new char[512]; - int cursor = 0; - for (;;) { - int n = r.read(buffer, cursor, buffer.length - cursor); - if (n < 0) { break; } - cursor += n; - if (cursor == buffer.length) { - char[] tmp = new char[buffer.length * 2]; - System.arraycopy(buffer, 0, tmp, 0, cursor); - buffer = tmp; - } - } - return new String(buffer, 0, cursor); - } - /** * Compile a script. * @@ -1955,12 +1936,12 @@ public class Context { if (debugger != null) { if (sourceReader != null) { - sourceString = readReader(sourceReader); + sourceString = Kit.readReader(sourceReader); sourceReader = null; } } boolean fromEval = (scope != null); - TokenStream ts = new TokenStream(sourceReader, sourceString, + TokenStream ts = new TokenStream(this, sourceReader, sourceString, fromEval, sourceName, lineno, getErrorReporter()); Parser p = createParser(); diff --git a/js/rhino/src/org/mozilla/javascript/IRFactory.java b/js/rhino/src/org/mozilla/javascript/IRFactory.java index 9ac03823f8f..5e83bbf6480 100644 --- a/js/rhino/src/org/mozilla/javascript/IRFactory.java +++ b/js/rhino/src/org/mozilla/javascript/IRFactory.java @@ -588,7 +588,7 @@ public class IRFactory { * (Which will make Array optimizations involving allocating a * Java array to back the javascript array work better.) */ - if (Context.getContext().getLanguageVersion() == Context.VERSION_1_2) { + if (ts.cx.getLanguageVersion() == Context.VERSION_1_2) { /* When last array element is empty, we need to set the * length explicitly, because we can't depend on SETELEM * to do it for us - because empty [,,] array elements diff --git a/js/rhino/src/org/mozilla/javascript/TokenStream.java b/js/rhino/src/org/mozilla/javascript/TokenStream.java index 6acf8f0cb74..7da5215a225 100644 --- a/js/rhino/src/org/mozilla/javascript/TokenStream.java +++ b/js/rhino/src/org/mozilla/javascript/TokenStream.java @@ -269,10 +269,11 @@ public class TokenStream { return id & 0xff; } - public TokenStream(Reader sourceReader, String sourceString, + public TokenStream(Context cx, Reader sourceReader, String sourceString, boolean fromEval, String sourceName, int lineno, ErrorReporter errorReporter) { + this.cx = cx; this.fromEval = fromEval; this.pushbackToken = Token.EOF; this.sourceName = sourceName; @@ -499,7 +500,7 @@ public class TokenStream { if (result != Token.RESERVED) { return result; } - else if (!Context.getContext().hasFeature( + else if (!cx.hasFeature( Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER)) { return result; @@ -1232,4 +1233,5 @@ public class TokenStream { private ErrorReporter errorReporter; int errorCount; + Context cx; }