use of org.mozilla.javascript.xml.XMLObject in project hackpad by dropbox.
the class ScriptRuntime method getElemFunctionAndThis.
/**
* Prepare for calling obj[id](...): return function corresponding to
* obj[id] and make obj properly converted to Scriptable available
* as ScriptRuntime.lastStoredScriptable() for consumption as thisObj.
* The caller must call ScriptRuntime.lastStoredScriptable() immediately
* after calling this method.
*/
public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx) {
String s = toStringIdOrIndex(cx, elem);
if (s != null) {
return getPropFunctionAndThis(obj, s, cx);
}
int index = lastIndexResult(cx);
Scriptable thisObj = toObjectOrNull(cx, obj);
if (thisObj == null) {
throw undefCallError(obj, String.valueOf(index));
}
Object value;
for (; ; ) {
// Ignore XML lookup as required by ECMA 357, 11.2.2.1
value = ScriptableObject.getProperty(thisObj, index);
if (value != Scriptable.NOT_FOUND) {
break;
}
if (!(thisObj instanceof XMLObject)) {
break;
}
XMLObject xmlObject = (XMLObject) thisObj;
Scriptable extra = xmlObject.getExtraMethodSource(cx);
if (extra == null) {
break;
}
thisObj = extra;
}
if (!(value instanceof Callable)) {
throw notFunctionError(value, elem);
}
storeScriptable(cx, thisObj);
return (Callable) value;
}
use of org.mozilla.javascript.xml.XMLObject in project hackpad by dropbox.
the class ScriptRuntime method getPropFunctionAndThisHelper.
private static Callable getPropFunctionAndThisHelper(Object obj, String property, Context cx, Scriptable thisObj) {
if (thisObj == null) {
throw undefCallError(obj, property);
}
Object value;
for (; ; ) {
// Ignore XML lookup as required by ECMA 357, 11.2.2.1
value = ScriptableObject.getProperty(thisObj, property);
if (value != Scriptable.NOT_FOUND) {
break;
}
if (!(thisObj instanceof XMLObject)) {
break;
}
XMLObject xmlObject = (XMLObject) thisObj;
Scriptable extra = xmlObject.getExtraMethodSource(cx);
if (extra == null) {
break;
}
thisObj = extra;
}
if (!(value instanceof Callable)) {
Object noSuchMethod = ScriptableObject.getProperty(thisObj, "__noSuchMethod__");
if (noSuchMethod instanceof Callable)
value = new NoSuchMethodShim((Callable) noSuchMethod, property);
else
throw notFunctionError(thisObj, value, property);
}
storeScriptable(cx, thisObj);
return (Callable) value;
}
use of org.mozilla.javascript.xml.XMLObject in project hackpad by dropbox.
the class ScriptRuntime method deleteObjectElem.
public static boolean deleteObjectElem(Scriptable target, Object elem, Context cx) {
boolean result;
if (target instanceof XMLObject) {
XMLObject xmlObject = (XMLObject) target;
result = xmlObject.ecmaDelete(cx, elem);
} else {
String s = toStringIdOrIndex(cx, elem);
if (s == null) {
int index = lastIndexResult(cx);
target.delete(index);
return !target.has(index, target);
} else {
target.delete(s);
return !target.has(s, target);
}
}
return result;
}
use of org.mozilla.javascript.xml.XMLObject in project hackpad by dropbox.
the class ScriptRuntime method nameOrFunction.
private static Object nameOrFunction(Context cx, Scriptable scope, Scriptable parentScope, String name, boolean asFunctionCall) {
Object result;
// It is used only if asFunctionCall==true.
Scriptable thisObj = scope;
XMLObject firstXMLObject = null;
for (; ; ) {
if (scope instanceof NativeWith) {
Scriptable withObj = scope.getPrototype();
if (withObj instanceof XMLObject) {
XMLObject xmlObj = (XMLObject) withObj;
if (xmlObj.ecmaHas(cx, name)) {
// function this should be the target object of with
thisObj = xmlObj;
result = xmlObj.ecmaGet(cx, name);
break;
}
if (firstXMLObject == null) {
firstXMLObject = xmlObj;
}
} else {
result = ScriptableObject.getProperty(withObj, name);
if (result != Scriptable.NOT_FOUND) {
// function this should be the target object of with
thisObj = withObj;
break;
}
}
} else if (scope instanceof NativeCall) {
// NativeCall does not prototype chain and Scriptable.get
// can be called directly.
result = scope.get(name, scope);
if (result != Scriptable.NOT_FOUND) {
if (asFunctionCall) {
// ECMA 262 requires that this for nested funtions
// should be top scope
thisObj = ScriptableObject.getTopLevelScope(parentScope);
}
break;
}
} else {
// Can happen if Rhino embedding decided that nested
// scopes are useful for what ever reasons.
result = ScriptableObject.getProperty(scope, name);
if (result != Scriptable.NOT_FOUND) {
thisObj = scope;
break;
}
}
scope = parentScope;
parentScope = parentScope.getParentScope();
if (parentScope == null) {
result = topScopeName(cx, scope, name);
if (result == Scriptable.NOT_FOUND) {
if (firstXMLObject == null || asFunctionCall) {
throw notFoundError(scope, name);
}
// The name was not found, but we did find an XML
// object in the scope chain and we are looking for name,
// not function. The result should be an empty XMLList
// in name context.
result = firstXMLObject.ecmaGet(cx, name);
}
// For top scope thisObj for functions is always scope itself.
thisObj = scope;
break;
}
}
if (asFunctionCall) {
if (!(result instanceof Callable)) {
throw notFunctionError(result, name);
}
storeScriptable(cx, thisObj);
}
return result;
}
use of org.mozilla.javascript.xml.XMLObject in project jaggery by wso2.
the class XSLTHostObject method jsConstructor.
/**
* XSLT(xslt)
* XSLT(xslt, paramMap)
* XSLT(xslt, uriResolver)
* XSLT(xslt, paramMap, uriResolver)
*/
public static Scriptable jsConstructor(final Context cx, Object[] args, final Function ctorObj, boolean inNewExpr) throws ScriptException {
int argsCount = args.length;
if (argsCount < 1 || argsCount > 3) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, hostObjectName, argsCount, true);
}
Function uriResolver = null;
NativeObject paramMap = null;
XSLTHostObject xho = new XSLTHostObject();
if (args[0] instanceof String) {
xho.xslt = new StringReader((String) args[0]);
} else if (args[0] instanceof XMLObject) {
xho.xslt = new StringReader(args[0].toString());
} else {
HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "1", "string | xml", args[0], true);
}
if (argsCount == 2) {
if (args[1] instanceof NativeObject) {
paramMap = (NativeObject) args[1];
} else if (args[1] instanceof Function) {
uriResolver = (Function) args[1];
} else {
HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "2", "string", args[1], true);
}
} else if (argsCount == 3) {
if (args[1] instanceof NativeObject) {
paramMap = (NativeObject) args[1];
} else {
HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "2", "string", args[1], true);
}
if (args[2] instanceof Function) {
uriResolver = (Function) args[2];
} else {
HostObjectUtil.invalidArgsError(hostObjectName, hostObjectName, "3", "string", args[1], true);
}
}
xho.factory = TransformerFactory.newInstance();
if (uriResolver != null) {
xho.factory.setURIResolver(getUriResolver(cx, ctorObj, uriResolver));
}
return xho;
}
Aggregations