Skip to content

Commit

Permalink
recent Rhino changes and fix globalThis handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jul 2, 2021
1 parent 986b5b1 commit 34aa27d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<body>
<release version="2.51.0" date="June xx, 2021" description="Bugfixes, Firefox 89, Chrome/Edge 91, JS Template support">
<action type="fix" dev="RhinoTeam">
core-js: globalThis implemented.
</action>
<action type="fix" dev="RhinoTeam">
core-js: Fix bug when calling function on custom global object.
</action>
<action type="add" dev="rbri" due-to="Frank Danek" issue="360">
CSSConditionRule.conditionText added (for CSSMediaRule).
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,10 @@ public enum BrowserVersionFeatures {
@BrowserFeature(IE)
JS_FRAME_CONTENT_DOCUMENT_ACCESS_DENIED_THROWS,

/** Supports globalThis. */
@BrowserFeature({CHROME, EDGE, FF, FF78})
JS_GLOBAL_THIS,

/** The index parameter of {@link CSSGroupingRule#insertRule(String, Object)} is optional. */
@BrowserFeature({FF, FF78})
JS_GROUPINGRULE_INSERTRULE_INDEX_OPTIONAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ERROR_CAPTURE_STACK_TRACE;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ERROR_STACK_TRACE_LIMIT;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_DATA_ITERATOR_SIMPLE_NAME;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GLOBAL_THIS;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_PROTOTYPE_SAME_AS_HTML_IMAGE;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INTL_NAMED_OBJECT;
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OBJECT_GET_OWN_PROPERTY_SYMBOLS;
Expand Down Expand Up @@ -502,6 +503,10 @@ public static void configureRhino(final WebClient webClient,

NativeFunctionToStringFunction.installFix(scriptable, browserVersion);

if (!browserVersion.hasFeature(JS_GLOBAL_THIS)) {
deleteProperties(scriptable, "globalThis");
}

datePrototype.defineFunctionProperties(new String[] {"toLocaleDateString", "toLocaleTimeString"},
DateCustom.class, ScriptableObject.DONTENUM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2606,4 +2606,25 @@ public void xmlNotInWindow() throws Exception {

loadPageVerifyTitle2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = {"[object Window]", "true", "true"},
IE = "globalThis is undefined")
public void globalThis() throws Exception {
final String html
= "<html><head></head><body>\n"
+ "<script>\n"
+ LOG_TITLE_FUNCTION
+ " try {\n"
+ " log(globalThis);\n"
+ " log(window === globalThis);\n"
+ " log(self === globalThis);\n"
+ " } catch(e) { log('globalThis is undefined'); }"
+ "</script>\n"
+ "</body></html>";
loadPageVerifyTitle2(html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ public void atobUndefined() throws Exception {
testJs(workerJs);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = {"object", "true"},
IE = {"undefined", "globalThis is undefined"})
public void globalThis() throws Exception {
final String workerJs
= " try {\n"
+ " postMessage(typeof globalThis);\n"
+ " postMessage(self === globalThis);\n"
+ " } catch(e) { postMessage('globalThis is undefined'); }";
testJs(workerJs);
}

private void testJs(final String workerJs) throws Exception {
final String html = "<html><body>\n"
+ "<script async>\n"
Expand Down

0 comments on commit 34aa27d

Please sign in to comment.