зеркало из https://github.com/mozilla/gecko-dev.git
Renaming getIdDefaultAttributes to getIdAttributes in IdScriptable and its descendants to better reflect method semantic change in the previous IdScriptable commit plus layout cosmetics.
This commit is contained in:
Родитель
04a61296fb
Коммит
054eccf9b5
|
@ -152,17 +152,19 @@ class Arguments extends IdScriptable {
|
|||
super.delete(index);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee:
|
||||
case Id_caller:
|
||||
case Id_length:
|
||||
return DONTENUM;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected boolean hasIdValue(int id) {
|
||||
protected boolean hasIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee: return calleeObj != NOT_FOUND;
|
||||
case Id_length: return lengthObj != NOT_FOUND;
|
||||
|
@ -171,7 +173,8 @@ class Arguments extends IdScriptable {
|
|||
return super.hasIdValue(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee: return calleeObj;
|
||||
case Id_length: return lengthObj;
|
||||
|
@ -192,7 +195,8 @@ class Arguments extends IdScriptable {
|
|||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee: calleeObj = value; return;
|
||||
case Id_length: lengthObj = value; return;
|
||||
|
@ -203,7 +207,8 @@ class Arguments extends IdScriptable {
|
|||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
protected void deleteIdValue(int id) {
|
||||
protected void deleteIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee: calleeObj = NOT_FOUND; return;
|
||||
case Id_length: lengthObj = NOT_FOUND; return;
|
||||
|
@ -212,7 +217,8 @@ class Arguments extends IdScriptable {
|
|||
super.deleteIdValue(id);
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_callee: return "callee";
|
||||
case Id_length: return "length";
|
||||
|
@ -232,7 +238,8 @@ class Arguments extends IdScriptable {
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2002-04-09 20:46:33 CEST
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -80,7 +80,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
* value's prototype chain
|
||||
*
|
||||
*/
|
||||
public boolean hasInstance(Scriptable instance) {
|
||||
public boolean hasInstance(Scriptable instance)
|
||||
{
|
||||
Object protoProp = ScriptableObject.getProperty(this, "prototype");
|
||||
if (protoProp instanceof Scriptable && protoProp != Undefined.instance)
|
||||
{
|
||||
|
@ -90,7 +91,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
("msg.instanceof.bad.prototype", functionName, instance);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_length:
|
||||
case Id_arity:
|
||||
|
@ -103,10 +105,11 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
case Id_arguments:
|
||||
return EMPTY;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected boolean hasIdValue(int id) {
|
||||
protected boolean hasIdValue(int id)
|
||||
{
|
||||
if (id == Id_prototype) {
|
||||
return prototypeProperty != NOT_FOUND;
|
||||
}
|
||||
|
@ -122,7 +125,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
return super.hasIdValue(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_length: return wrap_int(getLength());
|
||||
case Id_arity: return wrap_int(getArity());
|
||||
|
@ -133,7 +137,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
if (id == Id_prototype) {
|
||||
prototypeProperty = (value != null) ? value : UniqueTag.NULL_VALUE;
|
||||
return;
|
||||
|
@ -141,7 +146,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
protected void deleteIdValue(int id) {
|
||||
protected void deleteIdValue(int id)
|
||||
{
|
||||
if (id == Id_prototype) {
|
||||
prototypeProperty = NOT_FOUND;
|
||||
return;
|
||||
|
@ -149,7 +155,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
super.deleteIdValue(id);
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
if (prototypeFlag) {
|
||||
switch (methodId) {
|
||||
case Id_constructor: return 1;
|
||||
|
@ -224,7 +231,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
return newInstance;
|
||||
}
|
||||
|
||||
public Scriptable createObject(Context cx, Scriptable scope) {
|
||||
public Scriptable createObject(Context cx, Scriptable scope)
|
||||
{
|
||||
Scriptable newInstance = new NativeObject();
|
||||
newInstance.setPrototype(getClassPrototype());
|
||||
newInstance.setParentScope(getParentScope());
|
||||
|
@ -297,7 +305,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void setupDefaultPrototype() {
|
||||
private void setupDefaultPrototype()
|
||||
{
|
||||
NativeObject obj = new NativeObject();
|
||||
final int attr = ScriptableObject.DONTENUM |
|
||||
ScriptableObject.READONLY |
|
||||
|
@ -314,7 +323,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
}
|
||||
}
|
||||
|
||||
private Object getArguments() {
|
||||
private Object getArguments()
|
||||
{
|
||||
// <Function name>.arguments is deprecated, so we use a slow
|
||||
// way of getting it that doesn't add to the invocation cost.
|
||||
// TODO: add warning, error based on version
|
||||
|
@ -324,7 +334,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
: activation.get("arguments", activation);
|
||||
}
|
||||
|
||||
NativeCall getActivation(Context cx) {
|
||||
NativeCall getActivation(Context cx)
|
||||
{
|
||||
NativeCall activation = cx.currentActivation;
|
||||
while (activation != null) {
|
||||
if (activation.getFunctionObject() == this)
|
||||
|
@ -447,7 +458,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
return ScriptRuntime.call(cx, function, callThis, callArgs, scope);
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_length: return "length";
|
||||
case Id_arity: return "arity";
|
||||
|
@ -480,7 +492,8 @@ public class BaseFunction extends IdScriptable implements Function {
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-05-20 00:12:12 GMT+02:00
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -47,7 +47,7 @@ Any descendant should implement at least the following methods:
|
|||
To define non-function properties, the descendant should override
|
||||
getIdValue
|
||||
setIdValue
|
||||
getIdDefaultAttributes
|
||||
getIdAttributes
|
||||
to get/set property value and provide its default attributes.
|
||||
|
||||
During initialization descendant should call setMaxId directly or via calling addAsPrototype.
|
||||
|
@ -59,7 +59,8 @@ may override scopeInit or fillConstructorProperties methods.
|
|||
public abstract class IdScriptable extends ScriptableObject
|
||||
implements IdFunctionMaster
|
||||
{
|
||||
public boolean has(String name, Scriptable start) {
|
||||
public boolean has(String name, Scriptable start)
|
||||
{
|
||||
if (maxId != 0) {
|
||||
int id = mapNameToId_writeCached(name);
|
||||
if (id != 0) {
|
||||
|
@ -69,7 +70,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
return super.has(name, start);
|
||||
}
|
||||
|
||||
public Object get(String name, Scriptable start) {
|
||||
public Object get(String name, Scriptable start)
|
||||
{
|
||||
if (maxId != 0) {
|
||||
int id = mapNameToId_writeCached(name);
|
||||
if (id != 0) {
|
||||
|
@ -92,11 +94,12 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
return super.get(name, start);
|
||||
}
|
||||
|
||||
public void put(String name, Scriptable start, Object value) {
|
||||
public void put(String name, Scriptable start, Object value)
|
||||
{
|
||||
if (maxId != 0) {
|
||||
int id = mapNameToId_cached(name);
|
||||
if (id != 0) {
|
||||
int attr = getIdDefaultAttributes(id);
|
||||
int attr = getIdAttributes(id);
|
||||
if ((attr & READONLY) == 0 && !isSealed()) {
|
||||
if (start == this) {
|
||||
setIdValue(id, value);
|
||||
|
@ -111,13 +114,14 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
super.put(name, start, value);
|
||||
}
|
||||
|
||||
public void delete(String name) {
|
||||
public void delete(String name)
|
||||
{
|
||||
if (maxId != 0) {
|
||||
int id = mapNameToId(name);
|
||||
if (id != 0) {
|
||||
// Let the super class to throw exceptions for sealed objects
|
||||
if (!isSealed()) {
|
||||
int attr = getIdDefaultAttributes(id);
|
||||
int attr = getIdAttributes(id);
|
||||
if ((attr & PERMANENT) == 0) {
|
||||
deleteIdValue(id);
|
||||
}
|
||||
|
@ -135,7 +139,7 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
int id = mapNameToId(name);
|
||||
if (id != 0) {
|
||||
if (hasValue(id)) {
|
||||
return getIdDefaultAttributes(id);
|
||||
return getIdAttributes(id);
|
||||
}
|
||||
// For ids with deleted values super will throw exceptions
|
||||
}
|
||||
|
@ -165,8 +169,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
/**
|
||||
* Redefine ScriptableObject.defineProperty to allow changing
|
||||
* values/attributes of id-based properties unless
|
||||
* getIdDefaultAttributes contains the READONLY attribute.
|
||||
* @see #getIdDefaultAttributes
|
||||
* getIdAttributes contains the READONLY attribute.
|
||||
* @see #getIdAttributes
|
||||
* @see org.mozilla.javascript.ScriptableObject#defineProperty
|
||||
*/
|
||||
public void defineProperty(String propertyName, Object value,
|
||||
|
@ -175,7 +179,7 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
if (maxId != 0) {
|
||||
int id = mapNameToId(propertyName);
|
||||
if (id != 0) {
|
||||
int current_attributes = getIdDefaultAttributes(id);
|
||||
int current_attributes = getIdAttributes(id);
|
||||
if ((current_attributes & READONLY) != 0) {
|
||||
// It is a bug to redefine id with readonly attributes
|
||||
throw new RuntimeException
|
||||
|
@ -189,7 +193,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
super.defineProperty(propertyName, value, attributes);
|
||||
}
|
||||
|
||||
Object[] getIds(boolean getAll) {
|
||||
Object[] getIds(boolean getAll)
|
||||
{
|
||||
Object[] result = super.getIds(getAll);
|
||||
|
||||
if (maxId != 0) {
|
||||
|
@ -198,7 +203,7 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
|
||||
for (int id = maxId; id != 0; --id) {
|
||||
if (hasValue(id)) {
|
||||
if (getAll || (getIdDefaultAttributes(id) & DONTENUM) == 0) {
|
||||
if (getAll || (getIdAttributes(id) & DONTENUM) == 0) {
|
||||
if (count == 0) {
|
||||
// Need extra room for nor more then [1..id] names
|
||||
ids = new Object[id];
|
||||
|
@ -223,7 +228,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
}
|
||||
|
||||
// Try to avoid calls to mapNameToId by quering name cache
|
||||
private int mapNameToId_cached(String name) {
|
||||
private int mapNameToId_cached(String name)
|
||||
{
|
||||
if (CACHE_NAMES) {
|
||||
Object[] data = idMapData;
|
||||
if (data != null) {
|
||||
|
@ -272,7 +278,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
** this for non-function attributes like length to return
|
||||
** DONTENUM | READONLY | PERMANENT or DONTENUM | PERMANENT
|
||||
*/
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
return DONTENUM;
|
||||
}
|
||||
|
||||
|
@ -281,11 +288,11 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
* Descendants should override the default implementation if they want to
|
||||
* allow to change id attributes since the default implementation throw an
|
||||
* exception unless new attributes eqaul the result of
|
||||
* <tt>getIdDefaultAttributes(id)</tt>.
|
||||
* <tt>getIdAttributes(id)</tt>.
|
||||
*/
|
||||
protected void setIdAttributes(int id, int attributes)
|
||||
{
|
||||
int current = getIdDefaultAttributes(id);
|
||||
int current = getIdAttributes(id);
|
||||
if (attributes != current) {
|
||||
throw new RuntimeException(
|
||||
"Change of attributes for this id is not supported");
|
||||
|
@ -294,7 +301,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
|
||||
/** Check if id value exists.
|
||||
** Default implementation always returns true */
|
||||
protected boolean hasIdValue(int id) {
|
||||
protected boolean hasIdValue(int id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -304,7 +312,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
** Default implementation creates IdFunction instance for given id
|
||||
** and cache its value
|
||||
*/
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
IdFunction f = newIdFunction(id);
|
||||
f.setParentScope(getParentScope());
|
||||
return cacheIdValue(id, f);
|
||||
|
@ -313,11 +322,12 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
/**
|
||||
* Set id value.
|
||||
* IdScriptable never calls this method if result of
|
||||
* <code>getIdDefaultAttributes(id)</code> contains READONLY attribute.
|
||||
* <code>getIdAttributes(id)</code> contains READONLY attribute.
|
||||
* Descendants can overwrite this method to provide custom handler for
|
||||
* property assignments.
|
||||
*/
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
synchronized (this) {
|
||||
Object[] data = ensureIdData();
|
||||
data[id - 1] = (value != null) ? value : UniqueTag.NULL_VALUE;
|
||||
|
@ -329,7 +339,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
* After this call IdScriptable never calls hasIdValue and getIdValue
|
||||
* for the given id.
|
||||
*/
|
||||
protected Object cacheIdValue(int id, Object value) {
|
||||
protected Object cacheIdValue(int id, Object value)
|
||||
{
|
||||
synchronized (this) {
|
||||
Object[] data = ensureIdData();
|
||||
Object curValue = data[id - 1];
|
||||
|
@ -346,11 +357,12 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
/**
|
||||
* Delete value represented by id so hasIdValue return false.
|
||||
* IdScriptable never calls this method if result of
|
||||
* <code>getIdDefaultAttributes(id)</code> contains PERMANENT attribute.
|
||||
* <code>getIdAttributes(id)</code> contains PERMANENT attribute.
|
||||
* Descendants can overwrite this method to provide custom handler for
|
||||
* property delete.
|
||||
*/
|
||||
protected void deleteIdValue(int id) {
|
||||
protected void deleteIdValue(int id)
|
||||
{
|
||||
synchronized (this) {
|
||||
ensureIdData()[id - 1] = NOT_FOUND;
|
||||
}
|
||||
|
@ -369,17 +381,20 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
/** Get arity or defined argument count for method with given id.
|
||||
** Should return -1 if methodId is not known or can not be used
|
||||
** with execMethod call. */
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Get maximum id mapNameToId can generate */
|
||||
protected final int getMaxId() {
|
||||
protected final int getMaxId()
|
||||
{
|
||||
return maxId;
|
||||
}
|
||||
|
||||
/** Set maximum id mapNameToId can generate */
|
||||
protected final void setMaxId(int maxId) {
|
||||
protected final void setMaxId(int maxId)
|
||||
{
|
||||
// maxId can only go up
|
||||
if (maxId < this.maxId) Context.codeBug();
|
||||
this.maxId = maxId;
|
||||
|
@ -462,37 +477,44 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
f.getFunctionName(), f);
|
||||
}
|
||||
|
||||
protected IdFunction newIdFunction(int id) {
|
||||
protected IdFunction newIdFunction(int id)
|
||||
{
|
||||
return newIdFunction(getIdName(id), id);
|
||||
}
|
||||
|
||||
protected IdFunction newIdFunction(String name, int id) {
|
||||
protected IdFunction newIdFunction(String name, int id)
|
||||
{
|
||||
IdFunction f = new IdFunction(this, name, id);
|
||||
if (isSealed()) { f.sealObject(); }
|
||||
return f;
|
||||
}
|
||||
|
||||
protected final Object wrap_double(double x) {
|
||||
protected final Object wrap_double(double x)
|
||||
{
|
||||
return (x == x) ? new Double(x) : ScriptRuntime.NaNobj;
|
||||
}
|
||||
|
||||
protected final Object wrap_int(int x) {
|
||||
protected final Object wrap_int(int x)
|
||||
{
|
||||
byte b = (byte)x;
|
||||
if (b == x) { return new Byte(b); }
|
||||
return new Integer(x);
|
||||
}
|
||||
|
||||
protected final Object wrap_long(long x) {
|
||||
protected final Object wrap_long(long x)
|
||||
{
|
||||
int i = (int)x;
|
||||
if (i == x) { return wrap_int(i); }
|
||||
return new Long(x);
|
||||
}
|
||||
|
||||
protected final Object wrap_boolean(boolean x) {
|
||||
protected final Object wrap_boolean(boolean x)
|
||||
{
|
||||
return x ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
private boolean hasValue(int id) {
|
||||
private boolean hasValue(int id)
|
||||
{
|
||||
Object value;
|
||||
Object[] data = idMapData;
|
||||
if (data == null || (value = data[id - 1]) == null) {
|
||||
|
@ -504,7 +526,8 @@ public abstract class IdScriptable extends ScriptableObject
|
|||
}
|
||||
|
||||
// Must be called only from synchronized (this)
|
||||
private Object[] ensureIdData() {
|
||||
private Object[] ensureIdData()
|
||||
{
|
||||
Object[] data = idMapData;
|
||||
if (data == null) {
|
||||
idMapData = data = new Object[CACHE_NAMES ? maxId * 2 : maxId];
|
||||
|
|
|
@ -61,7 +61,8 @@ public class NativeArray extends IdScriptable {
|
|||
* always gets at least an object back, even when Array == null.
|
||||
*/
|
||||
|
||||
static void init(Context cx, Scriptable scope, boolean sealed) {
|
||||
static void init(Context cx, Scriptable scope, boolean sealed)
|
||||
{
|
||||
NativeArray obj = new NativeArray();
|
||||
obj.prototypeFlag = true;
|
||||
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
|
||||
|
@ -70,12 +71,14 @@ public class NativeArray extends IdScriptable {
|
|||
/**
|
||||
* Zero-parameter constructor: just used to create Array.prototype
|
||||
*/
|
||||
private NativeArray() {
|
||||
private NativeArray()
|
||||
{
|
||||
dense = null;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
public NativeArray(long length) {
|
||||
public NativeArray(long length)
|
||||
{
|
||||
int intLength = (int) length;
|
||||
if (intLength == length && intLength > 0) {
|
||||
if (intLength > maximumDenseLength)
|
||||
|
@ -87,37 +90,43 @@ public class NativeArray extends IdScriptable {
|
|||
this.length = length;
|
||||
}
|
||||
|
||||
public NativeArray(Object[] array) {
|
||||
public NativeArray(Object[] array)
|
||||
{
|
||||
dense = array;
|
||||
this.length = array.length;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
public String getClassName()
|
||||
{
|
||||
return "Array";
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
if (id == Id_length) {
|
||||
return DONTENUM | PERMANENT;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
if (id == Id_length) {
|
||||
return wrap_double(length);
|
||||
}
|
||||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
if (id == Id_length) {
|
||||
setLength(value); return;
|
||||
}
|
||||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
if (prototypeFlag) {
|
||||
switch (methodId) {
|
||||
case Id_constructor: return 1;
|
||||
|
@ -188,13 +197,15 @@ public class NativeArray extends IdScriptable {
|
|||
return super.execMethod(methodId, f, cx, scope, thisObj, args);
|
||||
}
|
||||
|
||||
public Object get(int index, Scriptable start) {
|
||||
public Object get(int index, Scriptable start)
|
||||
{
|
||||
if (dense != null && 0 <= index && index < dense.length)
|
||||
return dense[index];
|
||||
return super.get(index, start);
|
||||
}
|
||||
|
||||
public boolean has(int index, Scriptable start) {
|
||||
public boolean has(int index, Scriptable start)
|
||||
{
|
||||
if (dense != null && 0 <= index && index < dense.length)
|
||||
return dense[index] != NOT_FOUND;
|
||||
return super.has(index, start);
|
||||
|
@ -202,7 +213,8 @@ public class NativeArray extends IdScriptable {
|
|||
|
||||
// if id is an array index (ECMA 15.4.0), return the number,
|
||||
// otherwise return -1L
|
||||
private static long toArrayIndex(String id) {
|
||||
private static long toArrayIndex(String id)
|
||||
{
|
||||
double d = ScriptRuntime.toNumber(id);
|
||||
if (d == d) {
|
||||
long index = ScriptRuntime.toUint32(d);
|
||||
|
@ -217,7 +229,8 @@ public class NativeArray extends IdScriptable {
|
|||
return -1;
|
||||
}
|
||||
|
||||
public void put(String id, Scriptable start, Object value) {
|
||||
public void put(String id, Scriptable start, Object value)
|
||||
{
|
||||
if (start == this) {
|
||||
long index = toArrayIndex(id);
|
||||
if (index >= length) {
|
||||
|
@ -227,7 +240,8 @@ public class NativeArray extends IdScriptable {
|
|||
super.put(id, start, value);
|
||||
}
|
||||
|
||||
public void put(int index, Scriptable start, Object value) {
|
||||
public void put(int index, Scriptable start, Object value)
|
||||
{
|
||||
if (start == this) {
|
||||
// only set the array length if given an array index (ECMA 15.4.0)
|
||||
if (this.length <= index) {
|
||||
|
@ -243,7 +257,8 @@ public class NativeArray extends IdScriptable {
|
|||
super.put(index, start, value);
|
||||
}
|
||||
|
||||
public void delete(int index) {
|
||||
public void delete(int index)
|
||||
{
|
||||
if (!isSealed()) {
|
||||
if (dense != null && 0 <= index && index < dense.length) {
|
||||
dense[index] = NOT_FOUND;
|
||||
|
@ -253,7 +268,8 @@ public class NativeArray extends IdScriptable {
|
|||
super.delete(index);
|
||||
}
|
||||
|
||||
public Object[] getIds() {
|
||||
public Object[] getIds()
|
||||
{
|
||||
Object[] superIds = super.getIds();
|
||||
if (dense == null) { return superIds; }
|
||||
int N = dense.length;
|
||||
|
@ -285,7 +301,8 @@ public class NativeArray extends IdScriptable {
|
|||
return ids;
|
||||
}
|
||||
|
||||
public Object getDefaultValue(Class hint) {
|
||||
public Object getDefaultValue(Class hint)
|
||||
{
|
||||
if (hint == ScriptRuntime.NumberClass) {
|
||||
Context cx = Context.getContext();
|
||||
if (cx.getLanguageVersion() == Context.VERSION_1_2)
|
||||
|
@ -1078,7 +1095,8 @@ public class NativeArray extends IdScriptable {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
if (id == Id_length) { return "length"; }
|
||||
|
||||
if (prototypeFlag) {
|
||||
|
@ -1107,7 +1125,8 @@ public class NativeArray extends IdScriptable {
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
if (s.equals("length")) { return Id_length; }
|
||||
else if (prototypeFlag) {
|
||||
return toPrototypeId(s);
|
||||
|
@ -1117,7 +1136,8 @@ public class NativeArray extends IdScriptable {
|
|||
|
||||
// #string_id_map#
|
||||
|
||||
private static int toPrototypeId(String s) {
|
||||
private static int toPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-04-23 11:46:01 GMT+02:00
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -43,9 +43,11 @@ package org.mozilla.javascript;
|
|||
*
|
||||
* ECMA 15.11
|
||||
*/
|
||||
final class NativeError extends IdScriptable {
|
||||
final class NativeError extends IdScriptable
|
||||
{
|
||||
|
||||
static void init(Context cx, Scriptable scope, boolean sealed) {
|
||||
static void init(Context cx, Scriptable scope, boolean sealed)
|
||||
{
|
||||
NativeError obj = new NativeError();
|
||||
obj.prototypeFlag = true;
|
||||
obj.messageValue = "";
|
||||
|
@ -53,36 +55,42 @@ final class NativeError extends IdScriptable {
|
|||
obj.addAsPrototype(MAX_PROTOTYPE_ID, cx, scope, sealed);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
if (id == Id_message || id == Id_name) { return EMPTY; }
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected boolean hasIdValue(int id) {
|
||||
protected boolean hasIdValue(int id)
|
||||
{
|
||||
if (id == Id_message) { return messageValue != NOT_FOUND; }
|
||||
if (id == Id_name) { return nameValue != NOT_FOUND; }
|
||||
return super.hasIdValue(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
if (id == Id_message) { return messageValue; }
|
||||
if (id == Id_name) { return nameValue; }
|
||||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
if (id == Id_message) { messageValue = value; return; }
|
||||
if (id == Id_name) { nameValue = value; return; }
|
||||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
protected void deleteIdValue(int id) {
|
||||
protected void deleteIdValue(int id)
|
||||
{
|
||||
if (id == Id_message) { messageValue = NOT_FOUND; return; }
|
||||
if (id == Id_name) { nameValue = NOT_FOUND; return; }
|
||||
super.deleteIdValue(id);
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
if (prototypeFlag) {
|
||||
if (methodId == Id_constructor) return 1;
|
||||
if (methodId == Id_toString) return 0;
|
||||
|
@ -116,34 +124,40 @@ final class NativeError extends IdScriptable {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static String js_toString(Scriptable thisObj) {
|
||||
private static String js_toString(Scriptable thisObj)
|
||||
{
|
||||
Object name = ScriptRuntime.getStrIdElem(thisObj, "name");
|
||||
Object message = ScriptRuntime.getStrIdElem(thisObj, "message");
|
||||
return ScriptRuntime.toString(name)
|
||||
+": "+ScriptRuntime.toString(message);
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
public String getClassName()
|
||||
{
|
||||
return "Error";
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
public String toString()
|
||||
{
|
||||
return js_toString(this);
|
||||
}
|
||||
|
||||
String getName() {
|
||||
String getName()
|
||||
{
|
||||
Object val = nameValue;
|
||||
return ScriptRuntime.toString(val != NOT_FOUND ? val
|
||||
: Undefined.instance);
|
||||
}
|
||||
|
||||
String getMessage() {
|
||||
String getMessage()
|
||||
{
|
||||
Object val = messageValue;
|
||||
return ScriptRuntime.toString(val != NOT_FOUND ? val
|
||||
: Undefined.instance);
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
if (id == Id_message) { return "message"; }
|
||||
if (id == Id_name) { return "name"; }
|
||||
if (prototypeFlag) {
|
||||
|
@ -163,7 +177,8 @@ final class NativeError extends IdScriptable {
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-05-19 21:55:23 CEST
|
||||
L0: { id = 0; String X = null;
|
||||
|
|
|
@ -44,7 +44,8 @@ package org.mozilla.javascript;
|
|||
|
||||
final class NativeMath extends IdScriptable
|
||||
{
|
||||
static void init(Context cx, Scriptable scope, boolean sealed) {
|
||||
static void init(Context cx, Scriptable scope, boolean sealed)
|
||||
{
|
||||
NativeMath obj = new NativeMath();
|
||||
obj.setPrototype(getObjectPrototype(scope));
|
||||
obj.setParentScope(scope);
|
||||
|
@ -55,21 +56,24 @@ final class NativeMath extends IdScriptable
|
|||
|
||||
public String getClassName() { return "Math"; }
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
if (id > LAST_METHOD_ID) {
|
||||
return DONTENUM | READONLY | PERMANENT;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
if (id > LAST_METHOD_ID) {
|
||||
return cacheIdValue(id, wrap_double(getField(id)));
|
||||
}
|
||||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
private double getField(int fieldId) {
|
||||
private double getField(int fieldId)
|
||||
{
|
||||
switch (fieldId) {
|
||||
case Id_E: return E;
|
||||
case Id_PI: return PI;
|
||||
|
@ -83,7 +87,8 @@ final class NativeMath extends IdScriptable
|
|||
return 0; // Unreachable
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
switch (methodId) {
|
||||
case Id_abs: return 1;
|
||||
case Id_acos: return 1;
|
||||
|
@ -318,7 +323,8 @@ final class NativeMath extends IdScriptable
|
|||
|
||||
private double js_tan(double x) { return Math.tan(x); }
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_abs: return "abs";
|
||||
case Id_acos: return "acos";
|
||||
|
@ -353,7 +359,8 @@ final class NativeMath extends IdScriptable
|
|||
|
||||
// #string_id_map#
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-03-23 13:50:14 GMT+01:00
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -72,21 +72,24 @@ final class NativeString extends IdScriptable {
|
|||
super.fillConstructorProperties(cx, ctor, sealed);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
if (id == Id_length) {
|
||||
return DONTENUM | READONLY | PERMANENT;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
if (id == Id_length) {
|
||||
return wrap_int(string.length());
|
||||
}
|
||||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
if (prototypeFlag) {
|
||||
switch (methodId) {
|
||||
case ConstructorId_fromCharCode: return 1;
|
||||
|
@ -254,7 +257,8 @@ final class NativeString extends IdScriptable {
|
|||
return (NativeString)thisObj;
|
||||
}
|
||||
|
||||
private static RegExpProxy checkReProxy(Context cx) {
|
||||
private static RegExpProxy checkReProxy(Context cx)
|
||||
{
|
||||
RegExpProxy result = cx.getRegExpProxy();
|
||||
if (result == null) {
|
||||
throw cx.reportRuntimeError0("msg.no.regexp");
|
||||
|
@ -763,17 +767,18 @@ final class NativeString extends IdScriptable {
|
|||
return target;
|
||||
}
|
||||
|
||||
private static boolean js_equals(String target, String strOther) {
|
||||
private static boolean js_equals(String target, String strOther)
|
||||
{
|
||||
return target.equals(strOther);
|
||||
}
|
||||
|
||||
|
||||
private static boolean js_equalsIgnoreCase(String target, String strOther)
|
||||
{
|
||||
return target.equalsIgnoreCase(strOther);
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
if (id == Id_length) { return "length"; }
|
||||
|
||||
if (prototypeFlag) {
|
||||
|
@ -824,7 +829,8 @@ final class NativeString extends IdScriptable {
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
if (s.equals("length")) { return Id_length; }
|
||||
else if (prototypeFlag) {
|
||||
return toPrototypeId(s);
|
||||
|
@ -834,7 +840,8 @@ final class NativeString extends IdScriptable {
|
|||
|
||||
// #string_id_map#
|
||||
|
||||
private static int toPrototypeId(String s) {
|
||||
private static int toPrototypeId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-04-23 12:50:07 GMT+02:00
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -2628,11 +2628,13 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
return result;
|
||||
}
|
||||
|
||||
public byte getFlags() {
|
||||
public byte getFlags()
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void reportError(String msg, String arg, CompilerState state) {
|
||||
private void reportError(String msg, String arg, CompilerState state)
|
||||
{
|
||||
Object[] args = { arg };
|
||||
throw NativeGlobal.constructError(
|
||||
state.cx, "SyntaxError",
|
||||
|
@ -2640,7 +2642,8 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
state.scope);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_lastIndex:
|
||||
return ScriptableObject.PERMANENT | ScriptableObject.DONTENUM;
|
||||
|
@ -2651,21 +2654,28 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
return ScriptableObject.PERMANENT | ScriptableObject.READONLY
|
||||
| ScriptableObject.DONTENUM;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_lastIndex: return wrap_double(lastIndex);
|
||||
case Id_source: return new String(source);
|
||||
case Id_global: return wrap_boolean((flags & JSREG_GLOB) != 0);
|
||||
case Id_ignoreCase: return wrap_boolean((flags & JSREG_FOLD) != 0);
|
||||
case Id_multiline: return wrap_boolean((flags & JSREG_MULTILINE) != 0);
|
||||
case Id_lastIndex:
|
||||
return wrap_double(lastIndex);
|
||||
case Id_source:
|
||||
return new String(source);
|
||||
case Id_global:
|
||||
return wrap_boolean((flags & JSREG_GLOB) != 0);
|
||||
case Id_ignoreCase:
|
||||
return wrap_boolean((flags & JSREG_FOLD) != 0);
|
||||
case Id_multiline:
|
||||
return wrap_boolean((flags & JSREG_MULTILINE) != 0);
|
||||
}
|
||||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
if (id == Id_lastIndex) {
|
||||
setLastIndex(ScriptRuntime.toNumber(value));
|
||||
return;
|
||||
|
@ -2673,11 +2683,13 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
void setLastIndex(double value) {
|
||||
void setLastIndex(double value)
|
||||
{
|
||||
lastIndex = value;
|
||||
}
|
||||
|
||||
public int methodArity(int methodId) {
|
||||
public int methodArity(int methodId)
|
||||
{
|
||||
if (prototypeFlag) {
|
||||
switch (methodId) {
|
||||
case Id_compile: return 1;
|
||||
|
@ -2723,7 +2735,8 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
return (NativeRegExp)thisObj;
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case Id_lastIndex: return "lastIndex";
|
||||
case Id_source: return "source";
|
||||
|
@ -2757,7 +2770,8 @@ System.out.println("Testing at " + x.cp + ", op = " + op);
|
|||
|
||||
{ setMaxId(MAX_INSTANCE_ID); }
|
||||
|
||||
protected int mapNameToId(String s) {
|
||||
protected int mapNameToId(String s)
|
||||
{
|
||||
int id;
|
||||
// #generated# Last update: 2001-05-24 12:01:22 GMT+02:00
|
||||
L0: { id = 0; String X = null; int c;
|
||||
|
|
|
@ -71,7 +71,8 @@ public class NativeRegExpCtor extends NativeFunction {
|
|||
return construct(cx, parent, args);
|
||||
}
|
||||
|
||||
public Scriptable construct(Context cx, Scriptable scope, Object[] args) {
|
||||
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
|
||||
{
|
||||
NativeRegExp re = new NativeRegExp();
|
||||
re.compile(cx, scope, args);
|
||||
re.setPrototype(getClassPrototype(scope, "RegExp"));
|
||||
|
@ -79,12 +80,14 @@ public class NativeRegExpCtor extends NativeFunction {
|
|||
return re;
|
||||
}
|
||||
|
||||
static RegExpImpl getImpl() {
|
||||
static RegExpImpl getImpl()
|
||||
{
|
||||
Context cx = Context.getCurrentContext();
|
||||
return (RegExpImpl) ScriptRuntime.getRegExpProxy(cx);
|
||||
}
|
||||
|
||||
protected int getIdDefaultAttributes(int id) {
|
||||
protected int getIdAttributes(int id)
|
||||
{
|
||||
int shifted = id - idBase;
|
||||
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
|
||||
switch (shifted) {
|
||||
|
@ -96,14 +99,16 @@ public class NativeRegExpCtor extends NativeFunction {
|
|||
}
|
||||
return PERMANENT | READONLY;
|
||||
}
|
||||
return super.getIdDefaultAttributes(id);
|
||||
return super.getIdAttributes(id);
|
||||
}
|
||||
|
||||
private static String stringResult(Object obj) {
|
||||
private static String stringResult(Object obj)
|
||||
{
|
||||
return (obj == null) ? "" : obj.toString();
|
||||
}
|
||||
|
||||
protected Object getIdValue(int id) {
|
||||
protected Object getIdValue(int id)
|
||||
{
|
||||
int shifted = id - idBase;
|
||||
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
|
||||
RegExpImpl impl = getImpl();
|
||||
|
@ -139,7 +144,8 @@ public class NativeRegExpCtor extends NativeFunction {
|
|||
return super.getIdValue(id);
|
||||
}
|
||||
|
||||
protected void setIdValue(int id, Object value) {
|
||||
protected void setIdValue(int id, Object value)
|
||||
{
|
||||
switch (id - idBase) {
|
||||
case Id_multiline:
|
||||
case Id_STAR:
|
||||
|
@ -154,7 +160,8 @@ public class NativeRegExpCtor extends NativeFunction {
|
|||
super.setIdValue(id, value);
|
||||
}
|
||||
|
||||
protected String getIdName(int id) {
|
||||
protected String getIdName(int id)
|
||||
{
|
||||
int shifted = id - idBase;
|
||||
if (1 <= shifted && shifted <= MAX_INSTANCE_ID) {
|
||||
switch (shifted) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче