lib/minjs/ecma262/env.rb in minjs-0.1.10 vs lib/minjs/ecma262/env.rb in minjs-0.2.0
- old
+ new
@@ -23,30 +23,52 @@
@binding[n][:value] = v
@binding[n].merge!(options)
end
end
+ class DeclarativeEnvRecord < EnvRecord
+ end
+
+ class ObjectEnvRecord < EnvRecord
+ end
+
class ExObject
def initialize(options = {})
@attr = options[:attr] || {}
@prop = options[:prop] || {}
end
end
class LexEnv
attr_reader :record
attr_reader :outer
+ attr_reader :type
def initialize(options = {})
@outer = options[:outer]
- @record = EnvRecord.new
+ if options[:type] == :object
+ @record = ObjectEnvRecord.new
+ else #if options[:type] == :declarative
+ @record = DeclarativeEnvRecord.new
+ end
end
def new_declarative_env(outer = nil)
- LexEnv.new(outer: (outer || self))
+ e = LexEnv.new(outer: (outer || self), type: :declarative)
end
+ def new_object_env(object, outer = nil)#TODO
+ raise 'TODO'
+ e = LexEnv.new(outer: (outer || self), type: :object)
+ object.val.each do |k, v|
+ if k.id_name?
+ e.create_mutable_binding(k)
+ e.set_mutable_binding(k, v)
+ end
+ end
+ end
+
def debug
STDERR.puts @record.binding
end
end
@@ -56,10 +78,11 @@
attr_accessor :this_binding
def initialize(options = {})
@var_env = LexEnv.new(options)
@lex_env = LexEnv.new(options)
+ #TODO
@this_binding = ExObject.new(
{
attr: {
writable: true,
enumerable: false,
@@ -71,11 +94,8 @@
def debug
@var_env.debug
end
- def inspect
- @var_env.record.binding.to_s
- end
end
end
end