To construct regexp objects the generated code now calls omj.RegExpProxy instead of explicit calls to NativeRegExp constructor. It removes dependence of compiled Script instances on details of RegExp implementation.

This commit is contained in:
igor%mir2.org 2003-09-06 15:44:41 +00:00
parent f8c669f1dd
commit 31b2256d97

View File

@ -784,18 +784,19 @@ public class Codegen extends Interpreter {
if (regexpCount == 0) badTree();
cfw.addPush(regexpCount);
cfw.add(ByteCode.ANEWARRAY,
"org/mozilla/javascript/regexp/NativeRegExp");
cfw.add(ByteCode.ANEWARRAY, "java/lang/Object");
cfw.addALoad(contextArg);
cfw.addInvoke(ByteCode.INVOKESTATIC,
"org/mozilla/javascript/ScriptRuntime",
"checkRegExpProxy",
"(Lorg/mozilla/javascript/Context;"
+")Lorg/mozilla/javascript/RegExpProxy;");
// Loop invariant: it keeps new-array-ref on stack top
for (int i = 0; i != regexpCount; ++i) {
cfw.add(ByteCode.DUP);
cfw.addPush(i);
cfw.add(ByteCode.NEW,
"org/mozilla/javascript/regexp/NativeRegExp");
cfw.add(ByteCode.DUP);
cfw.add(ByteCode.DUP2);
// Stack structure: proxy, array, proxy, array
cfw.addALoad(contextArg);
cfw.addALoad(scopeArg);
cfw.addPush(n.getRegexpString(i));
@ -805,18 +806,23 @@ public class Codegen extends Interpreter {
} else {
cfw.addPush(regexpFlags);
}
cfw.addPush(0);
cfw.addInvoke(ByteCode.INVOKESPECIAL,
"org/mozilla/javascript/regexp/NativeRegExp",
"<init>",
cfw.addInvoke(ByteCode.INVOKEINTERFACE,
"org/mozilla/javascript/RegExpProxy",
"newRegExp",
"(Lorg/mozilla/javascript/Context;"
+"Lorg/mozilla/javascript/Scriptable;"
+"Ljava/lang/String;Ljava/lang/String;"
+"Z"
+")V");
+")Ljava/lang/Object;");
// Stack structure: result of newRegExp, array, proxy, array
cfw.addPush(i);
cfw.add(ByteCode.SWAP);
cfw.add(ByteCode.AASTORE);
// Stack structure: proxy, array
}
// remove proxy
cfw.add(ByteCode.POP);
}
void pushNumberAsObject(ClassFileWriter cfw, double num)
@ -969,8 +975,7 @@ public class Codegen extends Interpreter {
private static final String ID_FIELD_NAME = "_id";
static final String REGEXP_ARRAY_FIELD_NAME = "_re";
static final String REGEXP_ARRAY_FIELD_TYPE
= "[Lorg/mozilla/javascript/regexp/NativeRegExp;";
static final String REGEXP_ARRAY_FIELD_TYPE = "[Ljava/lang/Object;";
static final String FUNCTION_INIT_SIGNATURE
= "(Lorg/mozilla/javascript/Context;"