提交 4443f54c 编写于 作者: S sundar

8027150: ScriptObjectListAdapter won't work as expected

Reviewed-by: jlaskey, attila
上级 a38fb34a
......@@ -33,6 +33,7 @@ import java.util.NoSuchElementException;
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 abstract class ListAdapter extends AbstractList<Object> implements Random
*/
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 {
......
/*
* 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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册