зеркало из https://github.com/mozilla/gecko-dev.git
Fixing bug 254915: proper name lookup etc.
This commit is contained in:
Родитель
2628259213
Коммит
ca75e5c0c8
|
@ -2459,7 +2459,7 @@ switch (op) {
|
||||||
if (rhs == DBL_MRK) rhs = doubleWrap(sDbl[stackTop]);
|
if (rhs == DBL_MRK) rhs = doubleWrap(sDbl[stackTop]);
|
||||||
--stackTop;
|
--stackTop;
|
||||||
Scriptable lhs = (Scriptable)stack[stackTop];
|
Scriptable lhs = (Scriptable)stack[stackTop];
|
||||||
stack[stackTop] = ScriptRuntime.setName(lhs, rhs, cx, stringReg);
|
stack[stackTop] = ScriptRuntime.setName(lhs, rhs, cx, scope, stringReg);
|
||||||
continue Loop;
|
continue Loop;
|
||||||
}
|
}
|
||||||
case Token.DELPROP : {
|
case Token.DELPROP : {
|
||||||
|
|
|
@ -1640,42 +1640,68 @@ public class ScriptRuntime {
|
||||||
* Looks up a name in the scope chain and returns its value.
|
* Looks up a name in the scope chain and returns its value.
|
||||||
*/
|
*/
|
||||||
public static Object name(Context cx, Scriptable scopeChain, String id)
|
public static Object name(Context cx, Scriptable scopeChain, String id)
|
||||||
|
{
|
||||||
|
return name(cx, scopeChain, id, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object name(Context cx, Scriptable scopeChain, String id,
|
||||||
|
boolean asFunctionCall)
|
||||||
{
|
{
|
||||||
Scriptable scope = scopeChain;
|
Scriptable scope = scopeChain;
|
||||||
XMLObject firstXMLObject = null;
|
XMLObject firstXMLObject = null;
|
||||||
do {
|
Object result;
|
||||||
|
for (;;) {
|
||||||
if (scope instanceof NativeWith) {
|
if (scope instanceof NativeWith) {
|
||||||
Scriptable withObj = scope.getPrototype();
|
Scriptable withObj = scope.getPrototype();
|
||||||
if (withObj instanceof XMLObject) {
|
if (withObj instanceof XMLObject) {
|
||||||
XMLObject xmlObj = (XMLObject)withObj;
|
XMLObject xmlObj = (XMLObject)withObj;
|
||||||
if (xmlObj.ecmaHas(cx, id)) {
|
if (xmlObj.ecmaHas(cx, id)) {
|
||||||
return xmlObj.ecmaGet(cx, id);
|
result = xmlObj.ecmaGet(cx, id);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (firstXMLObject == null) {
|
if (firstXMLObject == null) {
|
||||||
firstXMLObject = xmlObj;
|
firstXMLObject = xmlObj;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Object result = ScriptableObject.getProperty(withObj, id);
|
result = ScriptableObject.getProperty(withObj, id);
|
||||||
if (result != Scriptable.NOT_FOUND) {
|
if (result != Scriptable.NOT_FOUND) {
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Object result = ScriptableObject.getProperty(scope, id);
|
result = ScriptableObject.getProperty(scope, id);
|
||||||
if (result != Scriptable.NOT_FOUND) {
|
if (result != Scriptable.NOT_FOUND) {
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope = scope.getParentScope();
|
scope = scope.getParentScope();
|
||||||
} while (scope != null);
|
if (scope == null) {
|
||||||
|
if (firstXMLObject != null) {
|
||||||
if (firstXMLObject != null) {
|
// The name was not found, but we did find an XML object in
|
||||||
// The name was not found, but we did find an XML object in the
|
//the scope chain. The result should be an empty XMLList
|
||||||
// scope chain. The result should be an empty XMLList
|
result = firstXMLObject.ecmaGet(cx, id);
|
||||||
return firstXMLObject.ecmaGet(cx, id);
|
break;
|
||||||
|
}
|
||||||
|
throw notFoundError(scopeChain, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (asFunctionCall) {
|
||||||
throw notFoundError(scopeChain, id);
|
if (!(result instanceof Function)) {
|
||||||
|
throw notFunctionError(result, id);
|
||||||
|
}
|
||||||
|
Scriptable thisObj = scope;
|
||||||
|
if (thisObj.getParentScope() != null) {
|
||||||
|
// Check for with and activation:
|
||||||
|
while (thisObj instanceof NativeWith) {
|
||||||
|
thisObj = thisObj.getPrototype();
|
||||||
|
}
|
||||||
|
if (thisObj instanceof NativeCall) {
|
||||||
|
thisObj = ScriptableObject.getTopLevelScope(thisObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storeScriptable(cx, thisObj);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1693,11 +1719,10 @@ public class ScriptRuntime {
|
||||||
*/
|
*/
|
||||||
public static Scriptable bind(Context cx, Scriptable scope, String id)
|
public static Scriptable bind(Context cx, Scriptable scope, String id)
|
||||||
{
|
{
|
||||||
Scriptable obj = scope;
|
|
||||||
Scriptable firstXMLObject = null;
|
Scriptable firstXMLObject = null;
|
||||||
for (;;) {
|
do {
|
||||||
if (obj instanceof NativeWith) {
|
if (scope instanceof NativeWith) {
|
||||||
Scriptable withObj = obj.getPrototype();
|
Scriptable withObj = scope.getPrototype();
|
||||||
if (withObj instanceof XMLObject) {
|
if (withObj instanceof XMLObject) {
|
||||||
XMLObject xmlObject = (XMLObject)withObj;
|
XMLObject xmlObject = (XMLObject)withObj;
|
||||||
if (xmlObject.ecmaHas(cx, id)) {
|
if (xmlObject.ecmaHas(cx, id)) {
|
||||||
|
@ -1712,25 +1737,19 @@ public class ScriptRuntime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ScriptableObject.hasProperty(obj, id)) {
|
if (ScriptableObject.hasProperty(scope, id)) {
|
||||||
return obj;
|
return scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj = obj.getParentScope();
|
scope = scope.getParentScope();
|
||||||
if (obj == null) {
|
} while (scope != null);
|
||||||
// XML objects always bind so return it if it was found
|
|
||||||
return firstXMLObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Scriptable getBase(Context cx, Scriptable scope, String id)
|
// Nothing was found
|
||||||
{
|
if (firstXMLObject != null) {
|
||||||
Scriptable base = bind(cx, scope, id);
|
// XML objects always bind so return it if it was found
|
||||||
if (base != null) {
|
return firstXMLObject;
|
||||||
return base;
|
|
||||||
}
|
}
|
||||||
throw notFoundError(scope, id);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scriptable getThis(Scriptable base) {
|
public static Scriptable getThis(Scriptable base) {
|
||||||
|
@ -1742,7 +1761,7 @@ public class ScriptRuntime {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object setName(Scriptable bound, Object value,
|
public static Object setName(Scriptable bound, Object value,
|
||||||
Context cx, String id)
|
Context cx, Scriptable scope, String id)
|
||||||
{
|
{
|
||||||
if (bound != null) {
|
if (bound != null) {
|
||||||
if (bound instanceof XMLObject) {
|
if (bound instanceof XMLObject) {
|
||||||
|
@ -1756,7 +1775,7 @@ public class ScriptRuntime {
|
||||||
// been defined, creates a new property in the
|
// been defined, creates a new property in the
|
||||||
// global object. Find the global object by
|
// global object. Find the global object by
|
||||||
// walking up the scope chain.
|
// walking up the scope chain.
|
||||||
bound = cx.topCallScope;
|
bound = ScriptableObject.getTopLevelScope(scope);
|
||||||
bound.put(id, bound, value);
|
bound.put(id, bound, value);
|
||||||
/*
|
/*
|
||||||
This code is causing immense performance problems in
|
This code is causing immense performance problems in
|
||||||
|
@ -1769,7 +1788,6 @@ public class ScriptRuntime {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the enumeration needed by the for..in statement.
|
* This is the enumeration needed by the for..in statement.
|
||||||
*
|
*
|
||||||
|
@ -1904,24 +1922,8 @@ public class ScriptRuntime {
|
||||||
Context cx,
|
Context cx,
|
||||||
Scriptable scope)
|
Scriptable scope)
|
||||||
{
|
{
|
||||||
Object value = name(cx, scope, name);
|
// name will call storeScriptable(cx, thisObj);
|
||||||
if (!(value instanceof Function)) {
|
return (Function)name(cx, scope, name, true);
|
||||||
throw notFunctionError(value, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scriptable thisObj = scope;
|
|
||||||
if (scope.getParentScope() != null) {
|
|
||||||
// Check for with and activation:
|
|
||||||
while (thisObj instanceof NativeWith) {
|
|
||||||
thisObj = thisObj.getPrototype();
|
|
||||||
}
|
|
||||||
if (thisObj instanceof NativeCall) {
|
|
||||||
thisObj = ScriptableObject.getTopLevelScope(thisObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
storeScriptable(cx, thisObj);
|
|
||||||
return (Function)value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3473,12 +3473,14 @@ Else pass the JS object in the aReg and 0.0 in the dReg.
|
||||||
child = child.getNext();
|
child = child.getNext();
|
||||||
}
|
}
|
||||||
cfw.addALoad(contextLocal);
|
cfw.addALoad(contextLocal);
|
||||||
|
cfw.addALoad(variableObjectLocal);
|
||||||
cfw.addPush(name);
|
cfw.addPush(name);
|
||||||
addScriptRuntimeInvoke(
|
addScriptRuntimeInvoke(
|
||||||
"setName",
|
"setName",
|
||||||
"(Lorg/mozilla/javascript/Scriptable;"
|
"(Lorg/mozilla/javascript/Scriptable;"
|
||||||
+"Ljava/lang/Object;"
|
+"Ljava/lang/Object;"
|
||||||
+"Lorg/mozilla/javascript/Context;"
|
+"Lorg/mozilla/javascript/Context;"
|
||||||
|
+"Lorg/mozilla/javascript/Scriptable;"
|
||||||
+"Ljava/lang/String;"
|
+"Ljava/lang/String;"
|
||||||
+")Ljava/lang/Object;");
|
+")Ljava/lang/Object;");
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче