changeset 648:f31ee3a2847d

8027150: ScriptObjectListAdapter won't work as expected Reviewed-by: jlaskey, attila
author sundar
date Wed, 23 Oct 2013 20:15:43 +0530
parents 5df55690fd5b
children 640c1854f742 7985ec3782b5
files src/jdk/nashorn/internal/runtime/ListAdapter.java src/jdk/nashorn/internal/runtime/ScriptObjectListAdapter.java
diffstat 2 files changed, 3 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/ListAdapter.java	Wed Oct 23 17:30:13 2013 +0530
+++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java	Wed Oct 23 20:15:43 2013 +0530
@@ -33,6 +33,7 @@
 import java.util.RandomAccess;
 import java.util.concurrent.Callable;
 import jdk.nashorn.api.scripting.JSObject;
+import jdk.nashorn.api.scripting.ScriptObjectMirror;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
 import jdk.nashorn.internal.runtime.linker.InvokeByName;
 
@@ -135,7 +136,8 @@
      */
     public static ListAdapter create(final Object obj) {
         if (obj instanceof ScriptObject) {
-            return new ScriptObjectListAdapter((ScriptObject)obj);
+            final Object mirror = ScriptObjectMirror.wrap(obj, Context.getGlobal());
+            return new JSObjectListAdapter((JSObject)mirror);
         } else if (obj instanceof JSObject) {
             return new JSObjectListAdapter((JSObject)obj);
         } else {
--- a/src/jdk/nashorn/internal/runtime/ScriptObjectListAdapter.java	Wed Oct 23 17:30:13 2013 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-/**
- * A ListAdapter that can wrap a ScriptObject.
- */
-public final class ScriptObjectListAdapter extends ListAdapter {
-    /**
-     * Creates a new list wrapper for the specified ScriptObject.
-     * @param obj script the object to wrap
-     */
-    public ScriptObjectListAdapter(final ScriptObject obj) {
-        super(obj);
-    }
-
-    @Override
-    public int size() {
-        return JSType.toInt32(((ScriptObject)obj).getLength());
-    }
-
-    @Override
-    protected Object getAt(int index) {
-        return ((ScriptObject)obj).get(index);
-    }
-
-    @Override
-    protected void setAt(int index, Object element) {
-        ((ScriptObject)obj).set(index, element, false);
-    }
-}