Added ScriptRuntime.checkRegExpProxy which is used in Interpreter and NativeString to check for regexp package presence instead of own duplicating code.

RegExpProxy.find_split is changed to include Context argument to follow the rest of RegExpProxy functions.
This commit is contained in:
igor%mir2.org 2003-09-06 15:41:03 +00:00
Родитель 5a252e7afe
Коммит 5f745d1f6e
5 изменённых файлов: 44 добавлений и 42 удалений

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

@ -265,15 +265,12 @@ public class Interpreter
int N = scriptOrFn.getRegexpCount();
if (N == 0) return;
RegExpProxy rep = cx.getRegExpProxy();
if (rep == null) {
throw cx.reportRuntimeError0("msg.no.regexp");
}
RegExpProxy rep = ScriptRuntime.checkRegExpProxy(cx);
Object[] array = new Object[N];
for (int i = 0; i != N; i++) {
String string = scriptOrFn.getRegexpString(i);
String flags = scriptOrFn.getRegexpFlags(i);
array[i] = rep.newRegExp(cx, scope, string, flags, false);
array[i] = rep.newRegExp(cx, scope, string, flags);
}
itsData.itsRegExpLiterals = array;
}

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

@ -238,13 +238,16 @@ final class NativeString extends IdScriptable {
ScriptRuntime.toString(args, 0)));
case Id_match:
return checkReProxy(cx).match(cx, scope, thisObj, args);
return ScriptRuntime.checkRegExpProxy(cx).
match(cx, scope, thisObj, args);
case Id_search:
return checkReProxy(cx).search(cx, scope, thisObj, args);
return ScriptRuntime.checkRegExpProxy(cx).
search(cx, scope, thisObj, args);
case Id_replace:
return checkReProxy(cx).replace(cx, scope, thisObj, args);
return ScriptRuntime.checkRegExpProxy(cx).
replace(cx, scope, thisObj, args);
}
}
return super.execMethod(methodId, f, cx, scope, thisObj, args);
@ -257,15 +260,6 @@ final class NativeString extends IdScriptable {
return (NativeString)thisObj;
}
private static RegExpProxy checkReProxy(Context cx)
{
RegExpProxy result = cx.getRegExpProxy();
if (result == null) {
throw cx.reportRuntimeError0("msg.no.regexp");
}
return result;
}
/*
* HTML composition aids.
*/
@ -416,15 +410,14 @@ final class NativeString extends IdScriptable {
* separator occurrence if found, or the string length if no
* separator is found.
*/
private static int find_split(Scriptable scope, String target,
String separator, Object re,
private static int find_split(Context cx, Scriptable scope, String target,
String separator, int version,
RegExpProxy reProxy, Object re,
int[] ip, int[] matchlen, boolean[] matched,
String[][] parensp)
{
int i = ip[0];
int length = target.length();
Context cx = Context.getContext();
int version = cx.getLanguageVersion();
/*
* Perl4 special case for str.split(' '), only if the user has selected
@ -479,10 +472,8 @@ final class NativeString extends IdScriptable {
* trying for a match, so we don't get stuck in a loop.
*/
if (re != null) {
return cx.getRegExpProxy().find_split(scope, target,
separator, re,
ip, matchlen, matched,
parensp);
return reProxy.find_split(cx, scope, target, separator, re,
ip, matchlen, matched, parensp);
}
/*
@ -559,7 +550,7 @@ final class NativeString extends IdScriptable {
String separator = null;
int[] matchlen = { 0 };
Object re = null;
RegExpProxy reProxy = cx.getRegExpProxy();
RegExpProxy reProxy = ScriptRuntime.getRegExpProxy(cx);
if (reProxy != null && reProxy.isRegExp(args[0])) {
re = args[0];
} else {
@ -573,8 +564,10 @@ final class NativeString extends IdScriptable {
int len = 0;
boolean[] matched = { false };
String[][] parens = { null };
while ((match = find_split(scope, target, separator, re, ip,
matchlen, matched, parens)) >= 0)
int version = cx.getLanguageVersion();
while ((match = find_split(cx, scope, target, separator, version,
reProxy, re, ip, matchlen, matched, parens))
>= 0)
{
if ((limited && len >= limit) || (match > target.length()))
break;
@ -604,8 +597,8 @@ final class NativeString extends IdScriptable {
}
ip[0] = match + matchlen[0];
if (cx.getLanguageVersion() < Context.VERSION_1_3
&& cx.getLanguageVersion() != Context.VERSION_DEFAULT)
if (version < Context.VERSION_1_3
&& version != Context.VERSION_DEFAULT)
{
/*
* Deviate from ECMA to imitate Perl, which omits a final

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

@ -43,12 +43,13 @@ package org.mozilla.javascript;
*
* @author Norris Boyd
*/
public interface RegExpProxy {
public interface RegExpProxy
{
public boolean isRegExp(Object obj);
public Object newRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat);
public Object newRegExp(Context cx, Scriptable scope,
String source, String global);
public Object match(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
@ -62,7 +63,8 @@ public interface RegExpProxy {
Scriptable thisObj, Object[] args)
throws JavaScriptException;
public int find_split(Scriptable scope, String target, String separator,
Object re, int[] ip, int[] matchlen,
public int find_split(Context cx, Scriptable scope, String target,
String separator, Object re,
int[] ip, int[] matchlen,
boolean[] matched, String[][] parensp);
}

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

@ -1959,10 +1959,20 @@ public class ScriptRuntime {
return Context.getMessage(messageId, arguments);
}
public static RegExpProxy getRegExpProxy(Context cx) {
public static RegExpProxy getRegExpProxy(Context cx)
{
return cx.getRegExpProxy();
}
public static RegExpProxy checkRegExpProxy(Context cx)
{
RegExpProxy result = getRegExpProxy(cx);
if (result == null) {
throw cx.reportRuntimeError0("msg.no.regexp");
}
return result;
}
public static NativeCall getCurrentActivation(Context cx) {
return cx.currentActivation;
}

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

@ -49,10 +49,10 @@ public class RegExpImpl implements RegExpProxy {
return obj instanceof NativeRegExp;
}
public Object newRegExp(Context cx, Scriptable scope, String source,
String global, boolean flat)
public Object newRegExp(Context cx, Scriptable scope,
String source, String global)
{
return new NativeRegExp(cx, scope, source, global, flat);
return new NativeRegExp(cx, scope, source, global, false);
}
public Object match(Context cx, Scriptable scope,
@ -202,14 +202,14 @@ public class RegExpImpl implements RegExpProxy {
public int find_split(Scriptable scope, String target, String separator,
Object reObj, int[] ip, int[] matchlen,
public int find_split(Context cx, Scriptable scope, String target,
String separator, Object reObj,
int[] ip, int[] matchlen,
boolean[] matched, String[][] parensp)
{
int i = ip[0];
int length = target.length();
int result;
Context cx = Context.getCurrentContext();
int version = cx.getLanguageVersion();
NativeRegExp re = (NativeRegExp) reObj;