use of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject in project htmlunit by HtmlUnit.
the class ScriptableWrapper method get.
/**
* {@inheritDoc}
* @see ScriptableObject#get(java.lang.String,net.sourceforge.htmlunit.corejs.javascript.Scriptable)
*/
@Override
public Object get(final String name, final Scriptable start) {
final Method propertyGetter = properties_.get(name);
final Object response;
if (propertyGetter != null) {
response = invoke(propertyGetter);
} else {
final Object fromSuper = super.get(name, start);
if (fromSuper != Scriptable.NOT_FOUND) {
response = fromSuper;
} else {
final Object byName = invoke(getByNameFallback_, new Object[] { name });
if (byName != null) {
response = byName;
} else {
response = Scriptable.NOT_FOUND;
}
}
}
return Context.javaToJS(response, ScriptableObject.getTopLevelScope(start));
}
use of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject in project htmlunit by HtmlUnit.
the class DebugFrameImpl method getFunctionName.
/**
* Returns the name of the function corresponding to this frame, if it is a function and it has
* a name. If the function does not have a name, this method will try to return the name under
* which it was referenced. See <a
* href="http://www.digital-web.com/articles/scope_in_javascript/">this page</a> for a good
* explanation of how the <tt>thisObj</tt> plays into this guess.
*
* @param thisObj the object via which the function was referenced, used to try to guess a
* function name if the function is anonymous
* @return the name of the function corresponding to this frame
*/
private String getFunctionName(final Scriptable thisObj) {
if (functionOrScript_.isFunction()) {
final String name = functionOrScript_.getFunctionName();
if (name != null && !name.isEmpty()) {
// A named function -- we can just return the name.
return name;
}
// on our HtmlUnitScriptable we need to avoid looking at the properties we have defined => TODO: improve it
if (thisObj instanceof HtmlUnitScriptable) {
return "[anonymous]";
}
Scriptable obj = thisObj;
while (obj != null) {
for (final Object id : obj.getIds()) {
if (id instanceof String) {
final String s = (String) id;
if (obj instanceof ScriptableObject) {
Object o = ((ScriptableObject) obj).getGetterOrSetter(s, 0, thisObj, false);
if (o == null) {
o = ((ScriptableObject) obj).getGetterOrSetter(s, 0, thisObj, true);
if (o != null) {
return "__defineSetter__ " + s;
}
} else {
return "__defineGetter__ " + s;
}
}
final Object o;
try {
// within a try block as this sometimes throws (not sure why)
o = obj.get(s, obj);
} catch (final Exception e) {
return "[anonymous]";
}
if (o instanceof NativeFunction) {
final NativeFunction f = (NativeFunction) o;
if (f.getDebuggableView() == functionOrScript_) {
return s;
}
}
}
}
obj = obj.getPrototype();
}
// Unable to intuit a name -- doh!
return "[anonymous]";
}
// Just a script -- no function name.
return "[script]";
}
use of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject in project htmlunit by HtmlUnit.
the class Range method getClientRects.
/**
* Retrieves a collection of rectangles that describes the layout of the contents of an object
* or range within the client. Each rectangle describes a single line.
* @return a collection of rectangles that describes the layout of the contents
*/
@JsxFunction
public ClientRectList getClientRects() {
final Window w = getWindow();
final ClientRectList rectList = new ClientRectList();
rectList.setParentScope(w);
rectList.setPrototype(getPrototype(rectList.getClass()));
// simple impl for now
for (final DomNode node : toW3C().containedNodes()) {
final ScriptableObject scriptable = node.getScriptableObject();
if (scriptable instanceof HTMLElement) {
final ClientRect rect = new ClientRect(0, 0, 1, 1);
rect.setParentScope(w);
rect.setPrototype(getPrototype(rect.getClass()));
rectList.add(rect);
}
}
return rectList;
}
use of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject in project htmlunit by HtmlUnit.
the class MessageEvent method jsConstructor.
/**
* JavaScript constructor.
*
* @param type the event type
* @param details the event details (optional)
*/
@Override
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public void jsConstructor(final String type, final ScriptableObject details) {
super.jsConstructor(type, details);
if (getBrowserVersion().hasFeature(EVENT_ONMESSAGE_DEFAULT_DATA_NULL)) {
data_ = null;
}
String origin = "";
String lastEventId = "";
if (details != null && !Undefined.isUndefined(details)) {
data_ = details.get("data");
final String detailOrigin = (String) details.get(HttpHeader.ORIGIN_LC);
if (detailOrigin != null) {
origin = detailOrigin;
}
final Object detailLastEventId = details.get("lastEventId");
if (detailLastEventId != null) {
lastEventId = Context.toString(detailLastEventId);
}
source_ = null;
final Object detailSource = details.get("source");
if (detailSource instanceof Window) {
source_ = (Window) detailSource;
} else if (detailSource instanceof WindowProxy) {
source_ = ((WindowProxy) detailSource).getDelegee();
}
ports_ = details.get("ports");
}
origin_ = origin;
lastEventId_ = lastEventId;
}
use of net.sourceforge.htmlunit.corejs.javascript.ScriptableObject in project htmlunit by HtmlUnit.
the class MouseEvent method jsConstructor.
/**
* JavaScript constructor.
*
* @param type the event type
* @param details the event details (optional)
*/
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
@Override
public void jsConstructor(final String type, final ScriptableObject details) {
super.jsConstructor(ScriptRuntime.toString(type), details);
if (details != null && !Undefined.isUndefined(details)) {
final Object screenX = details.get("screenX", details);
if (NOT_FOUND != screenX) {
screenX_ = ScriptRuntime.toInt32(screenX);
}
final Object screenY = details.get("screenY", details);
if (NOT_FOUND != screenX) {
screenY_ = ScriptRuntime.toInt32(screenY);
}
final Object clientX = details.get("clientX", details);
if (NOT_FOUND != clientX) {
clientX_ = ScriptRuntime.toInt32(clientX);
}
final Object clientY = details.get("clientY", details);
if (NOT_FOUND != clientX) {
clientY_ = ScriptRuntime.toInt32(clientY);
}
final Object button = details.get("button", details);
if (NOT_FOUND != button) {
button_ = ScriptRuntime.toInt32(button);
}
final Object buttons = details.get("buttons", details);
if (NOT_FOUND != buttons) {
buttons_ = ScriptRuntime.toInt32(buttons);
}
setAltKey(ScriptRuntime.toBoolean(details.get("altKey")));
setCtrlKey(ScriptRuntime.toBoolean(details.get("ctrlKey")));
setMetaKey(ScriptRuntime.toBoolean(details.get("metaKey")));
setShiftKey(ScriptRuntime.toBoolean(details.get("shiftKey")));
}
}
Aggregations