32 import java.util.NoSuchElementException; |
32 import java.util.NoSuchElementException; |
33 import java.util.RandomAccess; |
33 import java.util.RandomAccess; |
34 import java.util.concurrent.Callable; |
34 import java.util.concurrent.Callable; |
35 import jdk.nashorn.api.scripting.JSObject; |
35 import jdk.nashorn.api.scripting.JSObject; |
36 import jdk.nashorn.api.scripting.ScriptObjectMirror; |
36 import jdk.nashorn.api.scripting.ScriptObjectMirror; |
|
37 import jdk.nashorn.internal.objects.Global; |
37 import jdk.nashorn.internal.runtime.linker.Bootstrap; |
38 import jdk.nashorn.internal.runtime.linker.Bootstrap; |
38 import jdk.nashorn.internal.runtime.linker.InvokeByName; |
39 import jdk.nashorn.internal.runtime.linker.InvokeByName; |
39 |
40 |
40 /** |
41 /** |
41 * An adapter that can wrap any ECMAScript Array-like object (that adheres to the array rules for the property |
42 * An adapter that can wrap any ECMAScript Array-like object (that adheres to the array rules for the property |
52 */ |
53 */ |
53 public abstract class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { |
54 public abstract class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { |
54 // These add to the back and front of the list |
55 // These add to the back and front of the list |
55 private static final Object PUSH = new Object(); |
56 private static final Object PUSH = new Object(); |
56 private static InvokeByName getPUSH() { |
57 private static InvokeByName getPUSH() { |
57 return ((GlobalObject)Context.getGlobal()).getInvokeByName(PUSH, |
58 return Context.getGlobal().getInvokeByName(PUSH, |
58 new Callable<InvokeByName>() { |
59 new Callable<InvokeByName>() { |
59 @Override |
60 @Override |
60 public InvokeByName call() { |
61 public InvokeByName call() { |
61 return new InvokeByName("push", Object.class, void.class, Object.class); |
62 return new InvokeByName("push", Object.class, void.class, Object.class); |
62 } |
63 } |
63 }); |
64 }); |
64 } |
65 } |
65 |
66 |
66 private static final Object UNSHIFT = new Object(); |
67 private static final Object UNSHIFT = new Object(); |
67 private static InvokeByName getUNSHIFT() { |
68 private static InvokeByName getUNSHIFT() { |
68 return ((GlobalObject)Context.getGlobal()).getInvokeByName(UNSHIFT, |
69 return Context.getGlobal().getInvokeByName(UNSHIFT, |
69 new Callable<InvokeByName>() { |
70 new Callable<InvokeByName>() { |
70 @Override |
71 @Override |
71 public InvokeByName call() { |
72 public InvokeByName call() { |
72 return new InvokeByName("unshift", Object.class, void.class, Object.class); |
73 return new InvokeByName("unshift", Object.class, void.class, Object.class); |
73 } |
74 } |
75 } |
76 } |
76 |
77 |
77 // These remove from the back and front of the list |
78 // These remove from the back and front of the list |
78 private static final Object POP = new Object(); |
79 private static final Object POP = new Object(); |
79 private static InvokeByName getPOP() { |
80 private static InvokeByName getPOP() { |
80 return ((GlobalObject)Context.getGlobal()).getInvokeByName(POP, |
81 return Context.getGlobal().getInvokeByName(POP, |
81 new Callable<InvokeByName>() { |
82 new Callable<InvokeByName>() { |
82 @Override |
83 @Override |
83 public InvokeByName call() { |
84 public InvokeByName call() { |
84 return new InvokeByName("pop", Object.class, Object.class); |
85 return new InvokeByName("pop", Object.class, Object.class); |
85 } |
86 } |
86 }); |
87 }); |
87 } |
88 } |
88 |
89 |
89 private static final Object SHIFT = new Object(); |
90 private static final Object SHIFT = new Object(); |
90 private static InvokeByName getSHIFT() { |
91 private static InvokeByName getSHIFT() { |
91 return ((GlobalObject)Context.getGlobal()).getInvokeByName(SHIFT, |
92 return Context.getGlobal().getInvokeByName(SHIFT, |
92 new Callable<InvokeByName>() { |
93 new Callable<InvokeByName>() { |
93 @Override |
94 @Override |
94 public InvokeByName call() { |
95 public InvokeByName call() { |
95 return new InvokeByName("shift", Object.class, Object.class); |
96 return new InvokeByName("shift", Object.class, Object.class); |
96 } |
97 } |
98 } |
99 } |
99 |
100 |
100 // These insert and remove in the middle of the list |
101 // These insert and remove in the middle of the list |
101 private static final Object SPLICE_ADD = new Object(); |
102 private static final Object SPLICE_ADD = new Object(); |
102 private static InvokeByName getSPLICE_ADD() { |
103 private static InvokeByName getSPLICE_ADD() { |
103 return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_ADD, |
104 return Context.getGlobal().getInvokeByName(SPLICE_ADD, |
104 new Callable<InvokeByName>() { |
105 new Callable<InvokeByName>() { |
105 @Override |
106 @Override |
106 public InvokeByName call() { |
107 public InvokeByName call() { |
107 return new InvokeByName("splice", Object.class, void.class, int.class, int.class, Object.class); |
108 return new InvokeByName("splice", Object.class, void.class, int.class, int.class, Object.class); |
108 } |
109 } |
109 }); |
110 }); |
110 } |
111 } |
111 |
112 |
112 private static final Object SPLICE_REMOVE = new Object(); |
113 private static final Object SPLICE_REMOVE = new Object(); |
113 private static InvokeByName getSPLICE_REMOVE() { |
114 private static InvokeByName getSPLICE_REMOVE() { |
114 return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_REMOVE, |
115 return Context.getGlobal().getInvokeByName(SPLICE_REMOVE, |
115 new Callable<InvokeByName>() { |
116 new Callable<InvokeByName>() { |
116 @Override |
117 @Override |
117 public InvokeByName call() { |
118 public InvokeByName call() { |
118 return new InvokeByName("splice", Object.class, void.class, int.class, int.class); |
119 return new InvokeByName("splice", Object.class, void.class, int.class, int.class); |
119 } |
120 } |