[HtmlUnit] SVN: [14122] trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ javascript/host

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [14122] trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ javascript/host

asashour-2
Revision: 14122
          http://sourceforge.net/p/htmlunit/code/14122
Author:   asashour
Date:     2017-04-16 21:04:33 +0000 (Sun, 16 Apr 2017)
Log Message:
-----------
cleanup

Modified Paths:
--------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ObjectCustom.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeList.java

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ObjectCustom.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ObjectCustom.java 2017-04-16 20:55:10 UTC (rev 14121)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ObjectCustom.java 2017-04-16 21:04:33 UTC (rev 14122)
@@ -19,7 +19,6 @@
 
 import net.sourceforge.htmlunit.corejs.javascript.Context;
 import net.sourceforge.htmlunit.corejs.javascript.Function;
-import net.sourceforge.htmlunit.corejs.javascript.NativeArray;
 import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime;
 import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
 import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
@@ -41,7 +40,7 @@
      * @param function the function
      * @return array
      */
-    public static NativeArray getOwnPropertySymbols(
+    public static Scriptable getOwnPropertySymbols(
             final Context context, final Scriptable thisObj, final Object[] args, final Function function) {
         if (args.length == 0) {
             throw ScriptRuntime.typeError("Cannot convert undefined or null to object");
@@ -56,6 +55,6 @@
                 list.add(id);
             }
         }
-        return new NativeArray(list.toArray(new Object[list.size()]));
+        return context.newArray(thisObj, list.toArray(new Object[list.size()]));
     }
 }

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-04-16 20:55:10 UTC (rev 14121)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Promise.java 2017-04-16 21:04:33 UTC (rev 14122)
@@ -33,9 +33,7 @@
 import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
 import net.sourceforge.htmlunit.corejs.javascript.NativeArray;
 import net.sourceforge.htmlunit.corejs.javascript.NativeObject;
-import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime;
 import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
-import net.sourceforge.htmlunit.corejs.javascript.TopLevel;
 import net.sourceforge.htmlunit.corejs.javascript.Undefined;
 
 /**
@@ -149,9 +147,7 @@
                     values[i] = p.value_;
                 }
             }
-            final NativeArray array = new NativeArray(values);
-            ScriptRuntime.setBuiltinProtoAndParent(array, getParentScope(), TopLevel.Builtins.Array);
-            value_ = array;
+            value_ = Context.getCurrentContext().newArray(getParentScope(), values);
         }
         return resolve_;
     }

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-04-16 20:55:10 UTC (rev 14121)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-04-16 21:04:33 UTC (rev 14122)
@@ -190,10 +190,9 @@
                     mutationRecord.setOldValue(event.getValue());
                 }
 
-                final NativeArray array = new NativeArray(new Object[] {mutationRecord});
-                ScriptRuntime.setBuiltinProtoAndParent(array, scope, TopLevel.Builtins.Array);
                 final Context context = Context.enter();
                 try {
+                    final Scriptable array = context.newArray(scope, new Object[] {mutationRecord});
                     function_.call(context, scope, this, new Object[] {array});
                 }
                 finally {

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeList.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeList.java 2017-04-16 20:55:10 UTC (rev 14121)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeList.java 2017-04-16 21:04:33 UTC (rev 14122)
@@ -50,6 +50,9 @@
 @JsxClass
 public class NodeList extends AbstractList {
 
+    private static final String ITERATOR_NAME = "Iterator";
+    private static Iterator ITERATOR_PROTOTYPE_;
+
     /**
      * Creates an instance.
      */
@@ -113,8 +116,9 @@
         for (int i = 0; i < length; i++) {
             list.add(i);
         }
-        final Iterator object = new Iterator("Iterator", list.iterator());
+        final Iterator object = new Iterator(ITERATOR_NAME, list.iterator());
         object.setParentScope(getParentScope());
+        setIteratorPrototype(object);
         return object;
     }
 
@@ -125,8 +129,9 @@
     @JsxFunction({@WebBrowser(CHROME), @WebBrowser(value = FF, minVersion = 52)})
     public Iterator values() {
         final List<DomNode> list = getElements();
-        final Iterator object = new Iterator("Iterator", list.iterator());
+        final Iterator object = new Iterator(ITERATOR_NAME, list.iterator());
         object.setParentScope(getParentScope());
+        setIteratorPrototype(object);
         return object;
     }
 
@@ -137,17 +142,27 @@
     @JsxFunction({@WebBrowser(CHROME), @WebBrowser(value = FF, minVersion = 52)})
     public Iterator entries() {
         final List<DomNode> elements = getElements();
-        
+        final Context context = Context.getCurrentContext();
+        final Scriptable scope = getParentScope();
+
         final List<Scriptable> list = new ArrayList<>();
         for (int i = 0; i < elements.size(); i++) {
             final Object[] array = new Object[] {i, elements.get(i).getScriptableObject()};
-            list.add(Context.getCurrentContext().newArray(getParentScope(), array));
+            list.add(context.newArray(scope, array));
         }
-        final Iterator object = new Iterator("Iterator", list.iterator());
-        object.setParentScope(getParentScope());
+        final Iterator object = new Iterator(ITERATOR_NAME, list.iterator());
+        object.setParentScope(scope);
+        setIteratorPrototype(object);
         return object;
     }
 
+    private static void setIteratorPrototype(final Scriptable scriptable) {
+        if (ITERATOR_PROTOTYPE_ == null) {
+            ITERATOR_PROTOTYPE_ = new Iterator(ITERATOR_NAME, null);
+        }
+        scriptable.setPrototype(ITERATOR_PROTOTYPE_);
+    }
+
     /**
      * Calls the {@code callback} given in parameter once for each value pair in the list, in insertion order.
      * @param callback function to execute for each element


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...