Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
charliesome committed Nov 5, 2011
1 parent 4c8291e commit aeabf3c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/twostroke/runtime/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def self.register(&bk)
INITIALIZERS << bk
end

require File.expand_path("../lib/object.rb", __FILE__)
Dir.glob File.expand_path("../lib/*.rb", __FILE__) do |f|
require f
end
Expand Down
16 changes: 8 additions & 8 deletions lib/twostroke/runtime/lib/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ module Twostroke::Runtime
obj.put "prototype", proto
scope.set_var "Object", obj

proto.put "toString", Types::Function.new(->(scope, this, args) { Types::String.new "[hi object #{this._class || "Object"}]" }, nil, "toString", [])
proto.put "toString", Types::Function.new(->(scope, this, args) { Types::String.new "[object #{this._class || "Object"}]" }, nil, "toString", [])
proto.put "valueOf", Types::Function.new(->(scope, this, args) { this }, nil, "valueOf", [])
proto.put "hasOwnProperty", Types::Function.new(->(scope, this, args) {
Types::Boolean.new Types.to_object(this || Undefined.new).has_own_property(Types.to_string(args[0] || Undefined.new).string)
}, nil, "hasOwnProperty", [])
proto.put "isPrototypeOf", Types::Function.new(->(scope, this, args) {
proto = Types.to_object(args[0] || Undefined.new).prototype
this = Types.to_object(this || Undefined.new)
this = Types.to_object(this || Types::Undefined.new)
while proto.is_a?(Types::Object)
return Boolean.new(true) if args[0] == proto
proto = proto.prototype
end
Boolean.new false
Types::Boolean.new false
}, nil, "isPrototypeOf", [])
proto.put "propertyIsEnumerable", Types::Function.new(->(scope, this, args) {
this = Types.to_object(this || Undefined.new)
prop = Types.to_string(args[0] || Undefined.new).string
this = Types.to_object(this || Types::Undefined.new)
prop = Types.to_string(args[0] || Types::Undefined.new).string
if this.has_accessor(prop)
Boolean.new this.accessors[prop][:enumerable]
Types::Boolean.new this.accessors[prop][:enumerable]
elsif this.has_property
Boolean.new true
Types::Boolean.new true
else
Boolean.new false
Types::Boolean.new false
end
}, nil, "propertyIsEnumerable", [])

Expand Down
8 changes: 2 additions & 6 deletions lib/twostroke/runtime/types/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def get(prop, this = self)
accessors[prop][:get].(this)
elsif properties.has_key? prop
properties[prop]
elsif prop == "prototype" # lazily create prototype property
properties[prop] = Object.new
else
prototype && prototype.is_a?(Object) ? prototype.get(prop, this) : Undefined.new
end
Expand All @@ -56,8 +54,6 @@ def get_own_property(prop)
accessors[prop][:get] ? accessors[prop][:get].(this) : Undefined.new
elsif properties.has_key? prop
properties[prop]
elsif prop == "prototype" # lazily create prototype property
properties[prop] = Object.new
else
Undefined.new
end
Expand All @@ -84,15 +80,15 @@ def can_put(prop)
end

def has_property(prop)
accessors.has_key?(prop) || properties.has_key?(prop) || (prototype && prototype.is_a?(Object) && prototype.has_property(prop)) || prop == "prototype"
accessors.has_key?(prop) || properties.has_key?(prop) || (prototype && prototype.is_a?(Object) && prototype.has_property(prop))
end

def has_accessor(prop)
accessors.has_key?(prop)
end

def has_own_property(prop)
accessors.has_key?(prop) || properties.has_key?(prop) || prop == "prototype"
accessors.has_key?(prop) || properties.has_key?(prop)
end

def delete(prop)
Expand Down
2 changes: 1 addition & 1 deletion test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
throw :test_failure, (args[1] ? T.to_string(args[1]).string : "") unless T.is_truthy(args[0])
}, nil, nil, [])
vm.global_scope.set_var "assert_equal", T::Function.new(->(scope, this, args) {
throw :test_failure, "<#{T.to_string(args[0]).string}> !== <#{T.to_string(args[1]).string}>" unless T.seq args[0], args[1]
throw :test_failure, "<#{T.to_string(args[0]).string}> !== <#{T.to_string(args[1]).string}> #{T.to_string(args[2].string) if args[2]}" unless T.seq args[0], args[1]
}, nil, nil, [])
vm.global_scope.set_var "test", T::Function.new(->(scope, this, args) {
test_name = T.to_string(args[0] || T::Undefined.new).string
Expand Down

0 comments on commit aeabf3c

Please sign in to comment.