Not to call Context.getContext() in TokenStrea/IRFactory, an explicit Context instance is passed to TokenStream constructor

This commit is contained in:
igor%mir2.org 2003-10-30 16:40:39 +00:00
Родитель e0c6b113b2
Коммит c0c59dd572
3 изменённых файлов: 8 добавлений и 25 удалений

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

@ -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();

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

@ -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

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

@ -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;
}