Yet another change in IdFunction: now its constructor takes arity argument

which removes the need to have separated methodArity in IdFunctionMaster
intertface. The method, however, has to be preseved in IdScriptable since it
is used to find which arity should be used during IdFunction construction.
This commit is contained in:
igor%mir2.org 2004-06-08 22:25:57 +00:00
Родитель 9c20990405
Коммит e565588063
19 изменённых файлов: 279 добавлений и 365 удалений

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

@ -155,20 +155,6 @@ public class BaseFunction extends IdScriptable implements Function {
super.deleteIdValue(id);
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_toSource: return 1;
case Id_apply: return 2;
case Id_call: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -530,6 +516,20 @@ public class BaseFunction extends IdScriptable implements Function {
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_toSource: return 1;
case Id_apply: return 2;
case Id_call: return 1;
}
}
return super.methodArity(methodId);
}
// #string_id_map#
private static final int

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

@ -39,20 +39,14 @@ package org.mozilla.javascript;
public class IdFunction extends BaseFunction
{
public IdFunction(IdFunctionMaster master, String name, int id)
public IdFunction(IdFunctionMaster master, Object tag, int id,
String name, int arity)
{
this.functionName = name;
this.tag = null;
this.master = master;
this.methodId = id;
}
public IdFunction(Object tag, IdFunctionMaster master, String name, int id)
{
this.tag = tag;
this.functionName = name;
this.master = master;
this.methodId = id;
this.arity = arity;
}
public final boolean hasTag(Object tag)
@ -138,7 +132,7 @@ public class IdFunction extends BaseFunction
public int getArity()
{
return master.methodArity(this);
return arity;
}
public int getLength() { return getArity(); }
@ -161,8 +155,9 @@ public class IdFunction extends BaseFunction
return new RuntimeException("BAD FUNCTION ID="+methodId+" MASTER="+master);
}
private final Object tag;
private final IdFunctionMaster master;
private final Object tag;
public final int methodId;
private int arity;
private boolean useCallAsConstructor;
}

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

@ -1,57 +0,0 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1997-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Igor Bukanov
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
package org.mozilla.javascript;
/**
* Master for id-based functions that knows their properties and how to
* execute them.
*/
public interface IdFunctionMaster
{
/**
* 'thisObj' will be null if invoked as constructor, in which case
* instance of Scriptable should be returned
*/
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args);
/**
* Get arity or defined argument count for the given {@link IdFunction}
* instance.
*/
public int methodArity(IdFunction f);
}

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

@ -378,14 +378,13 @@ public abstract class IdScriptable extends ScriptableObject
}
/**
* Get arity or defined argument count for the given {@link IdFunction}
* instance.
* Get arity or defined argument count for the given function id.
* If subclass overrides ths method, it should always calls
* <tt>super.methodArity(f)</tt> for unknown functions.
* <tt>super.methodArity(id)</tt> for unknown functions.
*/
public int methodArity(IdFunction f)
protected int methodArity(int methodId)
{
throw f.unknown();
throw new IllegalArgumentException(String.valueOf(methodId));
}
/** Get maximum id mapNameToId can generate */
@ -489,7 +488,7 @@ public abstract class IdScriptable extends ScriptableObject
protected IdFunction newIdFunction(String name, int id)
{
IdFunction f = new IdFunction(this, name, id);
IdFunction f = new IdFunction(this, null, id, name, methodArity(id));
if (isSealed()) { f.sealObject(); }
return f;
}

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

@ -168,7 +168,8 @@ public final class JavaAdapter implements IdFunctionMaster
public static void init(Context cx, Scriptable scope, boolean sealed)
{
JavaAdapter obj = new JavaAdapter();
IdFunction f = new IdFunction(FTAG, obj, "JavaAdapter", Id_JavaAdapter);
IdFunction f = new IdFunction(obj, FTAG, Id_JavaAdapter,
"JavaAdapter", 1);
f.enableConstructorUsage();
f.defineAsScopeProperty(scope, sealed);
}
@ -184,16 +185,6 @@ public final class JavaAdapter implements IdFunctionMaster
throw f.unknown();
}
public int methodArity(IdFunction f)
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_JavaAdapter) {
return 1;
}
}
throw f.unknown();
}
public static Object convertResult(Object result, Class c)
{
if (result == Undefined.instance &&

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

@ -125,29 +125,6 @@ public class NativeArray extends IdScriptable {
super.setIdValue(id, value);
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toLocaleString: return 1;
case Id_toSource: return 0;
case Id_join: return 1;
case Id_reverse: return 0;
case Id_sort: return 1;
case Id_push: return 1;
case Id_pop: return 1;
case Id_shift: return 1;
case Id_unshift: return 1;
case Id_splice: return 1;
case Id_concat: return 1;
case Id_slice: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -1136,6 +1113,29 @@ public class NativeArray extends IdScriptable {
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toLocaleString: return 1;
case Id_toSource: return 0;
case Id_join: return 1;
case Id_reverse: return 0;
case Id_sort: return 1;
case Id_push: return 1;
case Id_pop: return 1;
case Id_shift: return 1;
case Id_unshift: return 1;
case Id_splice: return 1;
case Id_concat: return 1;
case Id_slice: return 1;
}
}
return super.methodArity(methodId);
}
private static final int
Id_length = 1,
MAX_INSTANCE_ID = 1;

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

@ -66,19 +66,6 @@ final class NativeBoolean extends IdScriptable {
return super.getDefaultValue(typeHint);
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
case Id_valueOf: return 0;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -130,6 +117,19 @@ final class NativeBoolean extends IdScriptable {
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
case Id_valueOf: return 0;
}
}
return super.methodArity(methodId);
}
// #string_id_map#
protected int mapNameToId(String s) {

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

@ -147,12 +147,6 @@ final class NativeCallPrototype extends IdScriptable
return "Call";
}
public int methodArity(IdFunction f)
{
if (f.methodId == Id_constructor) return 1;
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -174,6 +168,12 @@ final class NativeCallPrototype extends IdScriptable
return null;
}
protected int methodArity(int methodId)
{
if (methodId == Id_constructor) return 1;
return super.methodArity(methodId);
}
protected int mapNameToId(String s)
{
return s.equals("constructor") ? Id_constructor : 0;

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

@ -97,63 +97,6 @@ final class NativeDate extends IdScriptable
super.fillConstructorProperties(cx, ctor, sealed);
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case ConstructorId_now: return 0;
case ConstructorId_parse: return 1;
case ConstructorId_UTC: return 1;
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toTimeString: return 0;
case Id_toDateString: return 0;
case Id_toLocaleString: return 0;
case Id_toLocaleTimeString: return 0;
case Id_toLocaleDateString: return 0;
case Id_toUTCString: return 0;
case Id_toSource: return 0;
case Id_valueOf: return 0;
case Id_getTime: return 0;
case Id_getYear: return 0;
case Id_getFullYear: return 0;
case Id_getUTCFullYear: return 0;
case Id_getMonth: return 0;
case Id_getUTCMonth: return 0;
case Id_getDate: return 0;
case Id_getUTCDate: return 0;
case Id_getDay: return 0;
case Id_getUTCDay: return 0;
case Id_getHours: return 0;
case Id_getUTCHours: return 0;
case Id_getMinutes: return 0;
case Id_getUTCMinutes: return 0;
case Id_getSeconds: return 0;
case Id_getUTCSeconds: return 0;
case Id_getMilliseconds: return 0;
case Id_getUTCMilliseconds: return 0;
case Id_getTimezoneOffset: return 0;
case Id_setTime: return 1;
case Id_setMilliseconds: return 1;
case Id_setUTCMilliseconds: return 1;
case Id_setSeconds: return 2;
case Id_setUTCSeconds: return 2;
case Id_setMinutes: return 3;
case Id_setUTCMinutes: return 3;
case Id_setHours: return 4;
case Id_setUTCHours: return 4;
case Id_setDate: return 1;
case Id_setUTCDate: return 1;
case Id_setMonth: return 2;
case Id_setUTCMonth: return 2;
case Id_setFullYear: return 3;
case Id_setUTCFullYear: return 3;
case Id_setYear: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -1533,6 +1476,63 @@ final class NativeDate extends IdScriptable
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case ConstructorId_now: return 0;
case ConstructorId_parse: return 1;
case ConstructorId_UTC: return 1;
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toTimeString: return 0;
case Id_toDateString: return 0;
case Id_toLocaleString: return 0;
case Id_toLocaleTimeString: return 0;
case Id_toLocaleDateString: return 0;
case Id_toUTCString: return 0;
case Id_toSource: return 0;
case Id_valueOf: return 0;
case Id_getTime: return 0;
case Id_getYear: return 0;
case Id_getFullYear: return 0;
case Id_getUTCFullYear: return 0;
case Id_getMonth: return 0;
case Id_getUTCMonth: return 0;
case Id_getDate: return 0;
case Id_getUTCDate: return 0;
case Id_getDay: return 0;
case Id_getUTCDay: return 0;
case Id_getHours: return 0;
case Id_getUTCHours: return 0;
case Id_getMinutes: return 0;
case Id_getUTCMinutes: return 0;
case Id_getSeconds: return 0;
case Id_getUTCSeconds: return 0;
case Id_getMilliseconds: return 0;
case Id_getUTCMilliseconds: return 0;
case Id_getTimezoneOffset: return 0;
case Id_setTime: return 1;
case Id_setMilliseconds: return 1;
case Id_setUTCMilliseconds: return 1;
case Id_setSeconds: return 2;
case Id_setUTCSeconds: return 2;
case Id_setMinutes: return 3;
case Id_setUTCMinutes: return 3;
case Id_setHours: return 4;
case Id_setUTCHours: return 4;
case Id_setDate: return 1;
case Id_setUTCDate: return 1;
case Id_setMonth: return 2;
case Id_setUTCMonth: return 2;
case Id_setFullYear: return 3;
case Id_setUTCFullYear: return 3;
case Id_setYear: return 1;
}
}
return super.methodArity(methodId);
}
// #string_id_map#
protected int mapNameToId(String s)

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

@ -81,18 +81,6 @@ final class NativeError extends IdScriptable
return obj;
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -180,13 +168,27 @@ final class NativeError extends IdScriptable
protected String getIdName(int id)
{
if (prototypeFlag) {
if (id == Id_constructor) return "constructor";
if (id == Id_toString) return "toString";
if (id == Id_toSource) return "toSource";
switch (id) {
case Id_constructor: return "constructor";
case Id_toString: return "toString";
case Id_toSource: return "toSource";
}
}
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
}
}
return super.methodArity(methodId);
}
protected int mapNameToId(String s)
{
int id;

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

@ -57,23 +57,49 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
for (int id = 1; id <= LAST_SCOPE_FUNCTION_ID; ++id) {
String name;
int arity = 1;
switch (id) {
case Id_decodeURI: name = "decodeURI"; break;
case Id_decodeURIComponent: name = "decodeURIComponent"; break;
case Id_encodeURI: name = "encodeURI"; break;
case Id_encodeURIComponent: name = "encodeURIComponent"; break;
case Id_escape: name = "escape"; break;
case Id_eval: name = "eval"; break;
case Id_isFinite: name = "isFinite"; break;
case Id_isNaN: name = "isNaN"; break;
case Id_parseFloat: name = "parseFloat"; break;
case Id_parseInt: name = "parseInt"; break;
case Id_unescape: name = "unescape"; break;
case Id_uneval: name = "uneval"; break;
default:
Kit.codeBug(); name = null;
case Id_decodeURI:
name = "decodeURI";
break;
case Id_decodeURIComponent:
name = "decodeURIComponent";
break;
case Id_encodeURI:
name = "encodeURI";
break;
case Id_encodeURIComponent:
name = "encodeURIComponent";
break;
case Id_escape:
name = "escape";
break;
case Id_eval:
name = "eval";
break;
case Id_isFinite:
name = "isFinite";
break;
case Id_isNaN:
name = "isNaN";
break;
case Id_parseFloat:
name = "parseFloat";
break;
case Id_parseInt:
name = "parseInt";
arity = 2;
break;
case Id_unescape:
name = "unescape";
break;
case Id_uneval:
name = "uneval";
break;
default:
throw Kit.codeBug();
}
IdFunction f = new IdFunction(FTAG, obj, name, id);
IdFunction f = new IdFunction(obj, FTAG, id, name, arity);
f.defineAsScopeProperty(scope, sealed);
}
@ -109,8 +135,8 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
newObject(cx, scope, "Error",
ScriptRuntime.emptyArgs);
errorProto.put("name", errorProto, name);
IdFunction ctor = new IdFunction(FTAG, obj, name,
Id_new_CommonError);
IdFunction ctor = new IdFunction(obj, FTAG, Id_new_CommonError,
name, 1);
ctor.initAsConstructor(scope, errorProto);
if (sealed) {
ctor.sealObject();
@ -189,29 +215,6 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
throw f.unknown();
}
public int methodArity(IdFunction f)
{
if (f.hasTag(FTAG)) {
switch (f.methodId) {
case Id_decodeURI: return 1;
case Id_decodeURIComponent: return 1;
case Id_encodeURI: return 1;
case Id_encodeURIComponent: return 1;
case Id_escape: return 1;
case Id_eval: return 1;
case Id_isFinite: return 1;
case Id_isNaN: return 1;
case Id_parseFloat: return 1;
case Id_parseInt: return 2;
case Id_unescape: return 1;
case Id_uneval: return 1;
case Id_new_CommonError: return 1;
}
}
throw f.unknown();
}
/**
* The global method parseInt, as per ECMA-262 15.1.2.2.
*/

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

@ -117,8 +117,8 @@ public class NativeJavaTopPackage
}
// getClass implementation
IdFunction
getClass = new IdFunction(FTAG, top, "getClass", Id_getClass);
IdFunction getClass = new IdFunction(top, FTAG, Id_getClass,
"getClass", 1);
// We want to get a real alias, and not a distinct JavaPackage
// with the same packageName, so that we share classes and top
@ -145,16 +145,6 @@ public class NativeJavaTopPackage
throw f.unknown();
}
public int methodArity(IdFunction f)
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_getClass) {
return 1;
}
}
throw f.unknown();
}
private Scriptable js_getClass(Context cx, Scriptable scope, Object[] args)
{
if (args.length > 0 && args[0] instanceof Wrapper) {

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

@ -84,32 +84,6 @@ final class NativeMath extends IdScriptable
return super.getIdValue(id);
}
public int methodArity(IdFunction f)
{
switch (f.methodId) {
case Id_toSource: return 0;
case Id_abs: return 1;
case Id_acos: return 1;
case Id_asin: return 1;
case Id_atan: return 1;
case Id_atan2: return 2;
case Id_ceil: return 1;
case Id_cos: return 1;
case Id_exp: return 1;
case Id_floor: return 1;
case Id_log: return 1;
case Id_max: return 2;
case Id_min: return 2;
case Id_pow: return 2;
case Id_random: return 0;
case Id_round: return 1;
case Id_sin: return 1;
case Id_sqrt: return 1;
case Id_tan: return 1;
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -335,6 +309,32 @@ final class NativeMath extends IdScriptable
return null;
}
protected int methodArity(int methodId)
{
switch (methodId) {
case Id_toSource: return 0;
case Id_abs: return 1;
case Id_acos: return 1;
case Id_asin: return 1;
case Id_atan: return 1;
case Id_atan2: return 2;
case Id_ceil: return 1;
case Id_cos: return 1;
case Id_exp: return 1;
case Id_floor: return 1;
case Id_log: return 1;
case Id_max: return 2;
case Id_min: return 2;
case Id_pow: return 2;
case Id_random: return 0;
case Id_round: return 1;
case Id_sin: return 1;
case Id_sqrt: return 1;
case Id_tan: return 1;
}
return super.methodArity(methodId);
}
// #string_id_map#
protected int mapNameToId(String s)

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

@ -86,22 +86,6 @@ final class NativeNumber extends IdScriptable {
super.fillConstructorProperties(cx, ctor, sealed);
}
public int methodArity(IdFunction f) {
if (prototypeFlag) {
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_toLocaleString: return 1;
case Id_toSource: return 0;
case Id_valueOf: return 0;
case Id_toFixed: return 1;
case Id_toExponential: return 1;
case Id_toPrecision: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -207,6 +191,22 @@ final class NativeNumber extends IdScriptable {
return null;
}
protected int methodArity(int methodId) {
if (prototypeFlag) {
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 1;
case Id_toLocaleString: return 1;
case Id_toSource: return 0;
case Id_valueOf: return 0;
case Id_toFixed: return 1;
case Id_toExponential: return 1;
case Id_toPrecision: return 1;
}
}
return super.methodArity(methodId);
}
// #string_id_map#
protected int mapNameToId(String s) {

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

@ -72,21 +72,6 @@ final class NativeObjectPrototype extends NativeObject
addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
}
public int methodArity(IdFunction f)
{
switch (f.methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toLocaleString: return 0;
case Id_valueOf: return 0;
case Id_hasOwnProperty: return 1;
case Id_propertyIsEnumerable: return 1;
case Id_isPrototypeOf: return 1;
case Id_toSource: return 0;
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -244,6 +229,21 @@ final class NativeObjectPrototype extends NativeObject
return null;
}
protected int methodArity(int methodId)
{
switch (methodId) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_toLocaleString: return 0;
case Id_valueOf: return 0;
case Id_hasOwnProperty: return 1;
case Id_propertyIsEnumerable: return 1;
case Id_isPrototypeOf: return 1;
case Id_toSource: return 0;
}
return super.methodArity(methodId);
}
// #string_id_map#
protected int mapNameToId(String s)

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

@ -126,19 +126,6 @@ class NativeScript extends NativeFunction implements Script
return script == null ? Undefined.instance : script.exec(cx, scope);
}
public int methodArity(IdFunction f)
{
if (0 <= prototypeIdShift) {
switch (f.methodId - prototypeIdShift) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_exec: return 0;
case Id_compile: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -208,6 +195,19 @@ class NativeScript extends NativeFunction implements Script
return super.getIdName(id);
}
protected int methodArity(int methodId)
{
if (0 <= prototypeIdShift) {
switch (methodId - prototypeIdShift) {
case Id_constructor: return 1;
case Id_toString: return 0;
case Id_exec: return 0;
case Id_compile: return 1;
}
}
return super.methodArity(methodId);
}
protected int mapNameToId(String s)
{
if (0 <= prototypeIdShift) {

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

@ -88,10 +88,10 @@ final class NativeString extends IdScriptable {
return super.getIdValue(id);
}
public int methodArity(IdFunction f)
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (f.methodId) {
switch (methodId) {
case ConstructorId_fromCharCode: return 1;
case Id_constructor: return 1;
@ -129,7 +129,7 @@ final class NativeString extends IdScriptable {
case Id_replace: return 1;
}
}
return super.methodArity(f);
return super.methodArity(methodId);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,

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

@ -49,8 +49,8 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
NativeWith obj = new NativeWith();
obj.prototypeFlag = true;
IdFunction ctor = new IdFunction(FTAG, obj, "constructor",
Id_constructor);
IdFunction ctor = new IdFunction(obj, FTAG, Id_constructor,
"constructor", 0);
ctor.initAsConstructor(scope, obj);
if (sealed) { ctor.sealObject(); }
@ -150,21 +150,12 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_constructor) {
throw Context.reportRuntimeError1
("msg.cant.call.indirect", "With");
throw Context.reportRuntimeError1("msg.cant.call.indirect", "With");
}
}
throw f.unknown();
}
public int methodArity(IdFunction f)
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_constructor) { return 0; }
}
throw f.unknown();
}
static boolean isWithFunction(Object functionObj)
{
if (functionObj instanceof IdFunction) {

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

@ -2621,21 +2621,6 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
lastIndex = value;
}
public int methodArity(IdFunction f)
{
if (prototypeFlag) {
switch (f.methodId) {
case Id_compile: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
case Id_exec: return 1;
case Id_test: return 1;
case Id_prefix: return 1;
}
}
return super.methodArity(f);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
@ -2693,6 +2678,21 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
return null;
}
protected int methodArity(int methodId)
{
if (prototypeFlag) {
switch (methodId) {
case Id_compile: return 1;
case Id_toString: return 0;
case Id_toSource: return 0;
case Id_exec: return 1;
case Id_test: return 1;
case Id_prefix: return 1;
}
}
return super.methodArity(methodId);
}
// #string_id_map#
private static final int