Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix join, sparse arrays, etc

  • Loading branch information...
commit eb9c7c051bb88cc1a09587709cefda252a262189 1 parent 15136b5
@charliesome authored
Showing with 14 additions and 2 deletions.
  1. +1 −1  lib/twostroke/runtime/types/array.rb
  2. +4 −1 repl.rb
  3. +9 −0 test/array.js
View
2  lib/twostroke/runtime/types/array.rb
@@ -7,7 +7,7 @@ def self.constructor_function
if args.length.zero?
Array.new
elsif args.length == 1
- Array.new([Undefined.new] * Types.to_uint32(args[0]))
+ Array.new([nil] * Types.to_uint32(args[0]))
else
Array.new args
end
View
5 repl.rb
@@ -25,7 +25,7 @@ def repl_inspect(obj)
elsif obj.is_a? T::RegExp
Paint[obj.regexp.inspect + (obj.global ? "g" : ""), :bright, :red]
elsif obj.is_a? T::Array
- "[#{obj.items.map(&method(:repl_inspect)).join(", ")}]"
+ "[#{obj.items.reject(&:nil?).map(&method(:repl_inspect)).join(", ")}]"
elsif obj.is_a? T::Object and obj._class == T::Object.constructor_function
"{ #{obj.enum_for(:each_enumerable_property).map { |k| Paint[k, :magenta] + ": " + repl_inspect(obj.get(k)) }.join ", "} }"
else
@@ -109,6 +109,9 @@ def repl_inspect(obj)
exception = catch(:exception) { obj = vm.execute(:"repl_#{sect}_main", vm.global_scope) || Twostroke::Runtime::Types::Undefined.new; nil }
if exception
obj = exception
+ vm.global_scope.set_var "$EX", obj
+ else
+ vm.global_scope.set_var "$_", obj
end
str = repl_inspect obj
if exception
View
9 test/array.js
@@ -54,6 +54,15 @@ test("length=", function() {
assert("1,2,3,4" == a);
});
+test("join", function() {
+ assert_equal("", [].join(""));
+ assert_equal("", [].join(","));
+ assert_equal("12", [1,2].join(""));
+ assert_equal("1,2", [1,2].join(","));
+ assert_equal("1,2", [1,2].join());
+ assert_equal(",,,,", Array(5).join(), "join sparse array");
+});
+
test("concat", function() {
var a = [];
Please sign in to comment.
Something went wrong with that request. Please try again.