File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
src/main/java/org/truffleruby/debug Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. This
2
+ # code is released under a tri EPL/GPL/LGPL license. You can use it,
3
+ # redistribute it and/or modify it under the terms of the:
4
+ #
5
+ # Eclipse Public License version 1.0, or
6
+ # GNU General Public License version 2, or
7
+ # GNU Lesser General Public License version 2.1.
8
+
9
+ require_relative '../../ruby/spec_helper'
10
+
11
+ describe "Array.new" do
12
+ def storage ( ary )
13
+ Truffle ::Debug . array_storage ( ary )
14
+ end
15
+
16
+ def capacity ( ary )
17
+ Truffle ::Debug . array_capacity ( ary )
18
+ end
19
+
20
+ before :each do
21
+ @long = 1 << 52
22
+ end
23
+
24
+ it "creates arrays with the requested capacity" do
25
+ a = Array . new ( 17 )
26
+ capacity ( a ) . should == 17
27
+ end
28
+
29
+ it "creates arrays with the requested capacity with a default value" do
30
+ a = Array . new ( 17 , 1 )
31
+ capacity ( a ) . should == 17
32
+ end
33
+
34
+ it "creates arrays with the requested capacity with a value block" do
35
+ a = Array . new ( 17 ) { 1 }
36
+ capacity ( a ) . should == 17
37
+ end
38
+ end
39
+
Original file line number Diff line number Diff line change @@ -295,6 +295,17 @@ public DynamicObject arrayStorage(DynamicObject array) {
295
295
296
296
}
297
297
298
+ @ CoreMethod (names = "array_capacity" , onSingleton = true , required = 1 )
299
+ public abstract static class ArrayCapacityNode extends CoreMethodArrayArgumentsNode {
300
+
301
+ @ TruffleBoundary
302
+ @ Specialization (guards = "isRubyArray(array)" )
303
+ public int arrayStorage (DynamicObject array ) {
304
+ return ArrayStrategy .of (array ).capacityNode ().execute (Layouts .ARRAY .getStore (array ));
305
+ }
306
+
307
+ }
308
+
298
309
@ CoreMethod (names = "hash_storage" , onSingleton = true , required = 1 )
299
310
public abstract static class HashStorageNode extends CoreMethodArrayArgumentsNode {
300
311
You can’t perform that action at this time.
0 commit comments