Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 20, 2024
1 parent 13a3732 commit abeae64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/htmlunit/javascript/host/MimeTypeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ protected Object getWithPreemption(final String name) {
return NOT_FOUND;
}

/**
* {@inheritDoc}.
*/
@Override
public boolean has(final String name, final Scriptable start) {
if (NOT_FOUND != getWithPreemption(name)) {
return true;
}

return super.has(name, start);
}

/**
* Returns the element at the specified index, or {@code null} if the index is invalid.
* {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/javascript/host/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ protected Object getWithPreemption(final String name) {
* {@inheritDoc}
*/
@Override
public final MimeType get(final int index, final Scriptable start) {
public final Object get(final int index, final Scriptable start) {
final Plugin plugin = (Plugin) start;
final List<MimeType> elements = plugin.elements_;

if (index >= 0 && index < elements.size()) {
return elements.get(index);
}
return null;
return NOT_FOUND;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/htmlunit/javascript/host/PluginArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ protected Object getWithPreemption(final String name) {
return NOT_FOUND;
}

/**
* {@inheritDoc}.
*/
@Override
public boolean has(final String name, final Scriptable start) {
if (NOT_FOUND != getWithPreemption(name)) {
return true;
}

return super.has(name, start);
}

/**
* Returns the element at the specified index, or {@code null} if the index is invalid.
* {@inheritDoc}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/htmlunit/javascript/host/MimeTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ public void mimeType() throws Exception {
loadPageVerifyTitle2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts({"true", "false"})
public void in() throws Exception {
final String html = "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ "function test() {\n"
+ " log('application/pdf' in navigator.mimeTypes);\n"
+ " log('pdf' in navigator.mimeTypes);\n"
+ "}\n"
+ "</script></head>\n"
+ "<body onload='test()'></body></html>";

loadPageVerifyTitle2(html);
}

/**
* Tests default configuration of Pdf plugin.
* @throws Exception if the test fails
Expand Down

0 comments on commit abeae64

Please sign in to comment.