use of net.sourceforge.htmlunit.corejs.javascript.NativeArray in project htmlunit by HtmlUnit.
the class MutationObserver method attributeReplaced.
/**
* {@inheritDoc}
*/
@Override
public void attributeReplaced(final HtmlAttributeChangeEvent event) {
final HtmlElement target = event.getHtmlElement();
if (subtree_ || target == node_.getDomNodeOrDie()) {
final String attributeName = event.getName();
if (attributeFilter_ == null || attributeFilter_.contains(attributeName)) {
final MutationRecord mutationRecord = new MutationRecord();
final Scriptable scope = getParentScope();
mutationRecord.setParentScope(scope);
mutationRecord.setPrototype(getPrototype(mutationRecord.getClass()));
mutationRecord.setAttributeName(attributeName);
mutationRecord.setType("attributes");
mutationRecord.setTarget(target.getScriptableObject());
if (attributeOldValue_) {
mutationRecord.setOldValue(event.getValue());
}
final Window window = getWindow();
final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
final JavaScriptEngine jsEngine = (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
jsEngine.addPostponedAction(new PostponedAction(owningPage, "MutationObserver.attributeReplaced") {
@Override
public void execute() throws Exception {
final NativeArray array = new NativeArray(new Object[] { mutationRecord });
ScriptRuntime.setBuiltinProtoAndParent(array, scope, TopLevel.Builtins.Array);
jsEngine.callFunction(owningPage, function_, scope, MutationObserver.this, new Object[] { array });
}
});
}
}
}
use of net.sourceforge.htmlunit.corejs.javascript.NativeArray in project jenkins by jenkinsci.
the class HeteroListTest method xssPrevented_usingToolInstallation_withJustDisplayName.
// correspond to the hardening of escapeEntryTitleAndDescription
@Test
@Issue("SECURITY-2035")
public void xssPrevented_usingToolInstallation_withJustDisplayName() throws Exception {
JenkinsRule.WebClient wc = j.createWebClient();
HtmlPage page = wc.goTo("configureTools/");
// check the displayName
Object resultDN = page.executeJavaScript("var settingFields = document.querySelectorAll('.jenkins-form-label');" + "var children = Array.from(settingFields).filter(b => b.textContent.indexOf('XSS:') !== -1)[0].children;" + "Array.from(children).filter(c => c.tagName === 'IMG')").getJavaScriptResult();
assertThat(resultDN, instanceOf(NativeArray.class));
NativeArray resultDNNA = (NativeArray) resultDN;
assertEquals(0, resultDNNA.size());
// check the description
Object resultDesc = page.executeJavaScript("var settingFields = document.querySelectorAll('.jenkins-form-description');" + "var children = Array.from(settingFields).filter(b => b.textContent.indexOf('XSS:') !== -1)[0].children;" + "Array.from(children).filter(c => c.tagName === 'IMG')").getJavaScriptResult();
assertThat(resultDesc, instanceOf(NativeArray.class));
NativeArray resultDescNA = (NativeArray) resultDesc;
assertEquals(0, resultDescNA.size());
}
use of net.sourceforge.htmlunit.corejs.javascript.NativeArray in project htmlunit by HtmlUnit.
the class DateTimeFormat method jsConstructor.
/**
* JavaScript constructor.
* @param cx the current context
* @param args the arguments to the WebSocket constructor
* @param ctorObj the function object
* @param inNewExpr Is new or not
* @return the java object to allow JavaScript to access
*/
@JsxConstructor
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
final String[] locales;
if (args.length != 0) {
if (args[0] instanceof NativeArray) {
final NativeArray array = (NativeArray) args[0];
locales = new String[(int) array.getLength()];
for (int i = 0; i < locales.length; i++) {
locales[i] = Context.toString(array.get(i));
}
} else {
locales = new String[] { Context.toString(args[0]) };
}
} else {
locales = new String[] { "" };
}
final Window window = getWindow(ctorObj);
final DateTimeFormat format = new DateTimeFormat(locales, window.getBrowserVersion());
format.setParentScope(window);
format.setPrototype(window.getPrototype(format.getClass()));
return format;
}
use of net.sourceforge.htmlunit.corejs.javascript.NativeArray in project htmlunit by HtmlUnit.
the class MutationObserver method characterDataChanged.
/**
* {@inheritDoc}
*/
@Override
public void characterDataChanged(final CharacterDataChangeEvent event) {
final ScriptableObject target = event.getCharacterData().getScriptableObject();
if (subtree_ || target == node_) {
final MutationRecord mutationRecord = new MutationRecord();
final Scriptable scope = getParentScope();
mutationRecord.setParentScope(scope);
mutationRecord.setPrototype(getPrototype(mutationRecord.getClass()));
mutationRecord.setType("characterData");
mutationRecord.setTarget(target);
if (characterDataOldValue_) {
mutationRecord.setOldValue(event.getOldValue());
}
final Window window = getWindow();
final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
final JavaScriptEngine jsEngine = (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
jsEngine.addPostponedAction(new PostponedAction(owningPage, "MutationObserver.characterDataChanged") {
@Override
public void execute() throws Exception {
final NativeArray array = new NativeArray(new Object[] { mutationRecord });
ScriptRuntime.setBuiltinProtoAndParent(array, scope, TopLevel.Builtins.Array);
jsEngine.callFunction(owningPage, function_, scope, MutationObserver.this, new Object[] { array });
}
});
}
}
Aggregations