Wed, 23 Oct 2013 20:15:43 +0530
8027150: ScriptObjectListAdapter won't work as expected
Reviewed-by: jlaskey, attila
1.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Wed Oct 23 17:30:13 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Wed Oct 23 20:15:43 2013 +0530 1.3 @@ -33,6 +33,7 @@ 1.4 import java.util.RandomAccess; 1.5 import java.util.concurrent.Callable; 1.6 import jdk.nashorn.api.scripting.JSObject; 1.7 +import jdk.nashorn.api.scripting.ScriptObjectMirror; 1.8 import jdk.nashorn.internal.runtime.linker.Bootstrap; 1.9 import jdk.nashorn.internal.runtime.linker.InvokeByName; 1.10 1.11 @@ -135,7 +136,8 @@ 1.12 */ 1.13 public static ListAdapter create(final Object obj) { 1.14 if (obj instanceof ScriptObject) { 1.15 - return new ScriptObjectListAdapter((ScriptObject)obj); 1.16 + final Object mirror = ScriptObjectMirror.wrap(obj, Context.getGlobal()); 1.17 + return new JSObjectListAdapter((JSObject)mirror); 1.18 } else if (obj instanceof JSObject) { 1.19 return new JSObjectListAdapter((JSObject)obj); 1.20 } else {
2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObjectListAdapter.java Wed Oct 23 17:30:13 2013 +0530 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,54 +0,0 @@ 2.4 -/* 2.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 - * 2.8 - * This code is free software; you can redistribute it and/or modify it 2.9 - * under the terms of the GNU General Public License version 2 only, as 2.10 - * published by the Free Software Foundation. Oracle designates this 2.11 - * particular file as subject to the "Classpath" exception as provided 2.12 - * by Oracle in the LICENSE file that accompanied this code. 2.13 - * 2.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 2.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 - * version 2 for more details (a copy is included in the LICENSE file that 2.18 - * accompanied this code). 2.19 - * 2.20 - * You should have received a copy of the GNU General Public License version 2.21 - * 2 along with this work; if not, write to the Free Software Foundation, 2.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 - * 2.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.25 - * or visit www.oracle.com if you need additional information or have any 2.26 - * questions. 2.27 - */ 2.28 - 2.29 -package jdk.nashorn.internal.runtime; 2.30 - 2.31 -/** 2.32 - * A ListAdapter that can wrap a ScriptObject. 2.33 - */ 2.34 -public final class ScriptObjectListAdapter extends ListAdapter { 2.35 - /** 2.36 - * Creates a new list wrapper for the specified ScriptObject. 2.37 - * @param obj script the object to wrap 2.38 - */ 2.39 - public ScriptObjectListAdapter(final ScriptObject obj) { 2.40 - super(obj); 2.41 - } 2.42 - 2.43 - @Override 2.44 - public int size() { 2.45 - return JSType.toInt32(((ScriptObject)obj).getLength()); 2.46 - } 2.47 - 2.48 - @Override 2.49 - protected Object getAt(int index) { 2.50 - return ((ScriptObject)obj).get(index); 2.51 - } 2.52 - 2.53 - @Override 2.54 - protected void setAt(int index, Object element) { 2.55 - ((ScriptObject)obj).set(index, element, false); 2.56 - } 2.57 -}