From 008bb68789bf23433756533eca83f7c565e23149 Mon Sep 17 00:00:00 2001 From: duonglaiquang Date: Tue, 17 Mar 2026 17:32:45 +0900 Subject: [PATCH] FunctionWrapper: implement SymbolScriptable interface --- .../htmlunit/javascript/FunctionWrapper.java | 37 +++++- .../javascript/FunctionsWrapperTest.java | 115 ++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/htmlunit/javascript/FunctionWrapper.java b/src/main/java/org/htmlunit/javascript/FunctionWrapper.java index e19472e667..e72da66180 100644 --- a/src/main/java/org/htmlunit/javascript/FunctionWrapper.java +++ b/src/main/java/org/htmlunit/javascript/FunctionWrapper.java @@ -19,6 +19,8 @@ import org.htmlunit.corejs.javascript.Context; import org.htmlunit.corejs.javascript.Function; import org.htmlunit.corejs.javascript.Scriptable; +import org.htmlunit.corejs.javascript.Symbol; +import org.htmlunit.corejs.javascript.SymbolScriptable; /** * Wrapper for a {@link Function} delegating all calls to the wrapped instance. @@ -26,8 +28,9 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Ronald Brill + * @author Lai Quang Duong */ -public class FunctionWrapper implements Function, Serializable { +public class FunctionWrapper implements Function, SymbolScriptable, Serializable { private final Function wrapped_; /** @@ -78,6 +81,14 @@ public Object get(final int index, final Scriptable start) { return wrapped_.get(index, start); } + /** + * {@inheritDoc} + */ + @Override + public Object get(final Symbol key, final Scriptable start) { + return ((SymbolScriptable) wrapped_).get(key, start); + } + /** * {@inheritDoc} */ @@ -94,6 +105,14 @@ public boolean has(final int index, final Scriptable start) { return wrapped_.has(index, start); } + /** + * {@inheritDoc} + */ + @Override + public boolean has(final Symbol key, final Scriptable start) { + return ((SymbolScriptable) wrapped_).has(key, start); + } + /** * {@inheritDoc} */ @@ -110,6 +129,14 @@ public void put(final int index, final Scriptable start, final Object value) { wrapped_.put(index, wrapped_, value); } + /** + * {@inheritDoc} + */ + @Override + public void put(final Symbol key, final Scriptable start, final Object value) { + ((SymbolScriptable) wrapped_).put(key, wrapped_, value); + } + /** * {@inheritDoc} */ @@ -126,6 +153,14 @@ public void delete(final int index) { wrapped_.delete(index); } + /** + * {@inheritDoc} + */ + @Override + public void delete(final Symbol key) { + ((SymbolScriptable) wrapped_).delete(key); + } + /** * {@inheritDoc} */ diff --git a/src/test/java/org/htmlunit/javascript/FunctionsWrapperTest.java b/src/test/java/org/htmlunit/javascript/FunctionsWrapperTest.java index 808dbea284..5f54da114d 100644 --- a/src/test/java/org/htmlunit/javascript/FunctionsWrapperTest.java +++ b/src/test/java/org/htmlunit/javascript/FunctionsWrapperTest.java @@ -46,4 +46,119 @@ public void function_toString() throws Exception { loadPageVerifyTitle2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("true") + public void symbolHasInstance() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"[object Function]", "[object Function]", "[object Function]"}) + public void symbolToStringTag() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"undefined", "undefined", "false", "false"}) + public void symbolPropertyAccess() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"undefined", "hello", "true"}) + public void symbolPropertyWriteRead() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"hello", "true", "undefined", "false"}) + public void symbolPropertyDelete() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + }