lib/minjs/ecma262/exp.rb in minjs-0.2.1 vs lib/minjs/ecma262/exp.rb in minjs-0.2.2
- old
+ new
@@ -358,15 +358,19 @@
self.class.new(@name.deep_dup,
@args ? @args.collect{|x| x.deep_dup} : nil)
end
def replace(from, to)
- @args.each_index do |i|
- arg = @args[i]
- if arg .eql? from
- @args[i] = to
- break
+ if @name .eql? from
+ @name = to
+ else
+ @args.each_index do |i|
+ arg = @args[i]
+ if arg .eql? from
+ @args[i] = to
+ break
+ end
end
end
end
def traverse(parent, &block)
@@ -464,12 +468,11 @@
def ==(obj)
self.class == obj.class and @name == obj.name and @args == obj.args
end
def to_js(options = {})
- #TODO => simple_replacement
- if @args# and @args.length > 0
+ if @args
args = @args.collect{|x| x.to_js(options)}.join(",")
concat options, :new, @name, '(', args, ')'
else
concat options, :new, @name
end
@@ -1192,20 +1195,17 @@
def priority
PRIORITY_LOGICAL_AND
end
def to_ecma262_boolean
- if @val.respond_to? :to_ecma262_boolean and @val2.respond_to? :to_ecma262_boolean
- return nil if @val.to_ecma262_boolean == nil or @val2.to_ecma262_boolean == nil
- if @val.to_ecma262_boolean and @val2.to_ecma262_boolean
- true
- else
- false
- end
- else
- nil
- end
+ return nil if !(@val.respond_to? :to_ecma262_boolean)
+ return nil if @val.to_ecma262_boolean == nil
+ return false if @val.to_ecma262_boolean == false
+ return nil if !(@val2.respond_to? :to_ecma262_boolean)
+ return nil if @val2.to_ecma262_boolean == nil
+ return false if @val2.to_ecma262_boolean == false
+ true
end
def ecma262_typeof
if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
if @val.ecma262_typeof == @val2.ecma262_typeof
@@ -1225,20 +1225,17 @@
def priority
PRIORITY_LOGICAL_OR
end
def to_ecma262_boolean
- if @val.respond_to? :to_ecma262_boolean and @val2.respond_to? :to_ecma262_boolean
- return nil if @val.to_ecma262_boolean == nil or @val2.to_ecma262_boolean == nil
- if @val.to_ecma262_boolean or @val2.to_ecma262_boolean
- true
- else
- false
- end
- else
- nil
- end
+ return nil if !(@val.respond_to? :to_ecma262_boolean)
+ return nil if @val.to_ecma262_boolean == nil
+ return true if @val.to_ecma262_boolean == true
+ return nil if !(@val2.respond_to? :to_ecma262_boolean)
+ return nil if @val2.to_ecma262_boolean == nil
+ return true if @val2.to_ecma262_boolean == true
+ false
end
def ecma262_typeof
if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
if @val.ecma262_typeof == @val2.ecma262_typeof
@@ -1253,9 +1250,10 @@
#
# val ? val2 : val3
#
class ExpCond < Exp
attr_reader :val, :val2, :val3
+ alias :cond :val
def initialize(val, val2, val3)
@val = val
@val2 = val2
@val3 = val3