Class: Minjs::ECMA262::IdentifierName

Inherits:
Literal show all
Defined in:
lib/minjs/ecma262/literal.rb

Overview

Class of ECMA262 IdentifierName Element

See Also:

Constant Summary collapse

RESERVED_WORD =

reserved word list

See Also:

Set.new [
  #keywords
  :break, :do, :instanceof, :typeof,
  :case, :else, :new, :var,
  :catch, :finally, :return, :void,
  :continue, :for, :switch, :while,
  :debugger, :function, :this, :with,
  :default, :if, :throw,
  :delete, :in, :try,
  #future reserved words
  :class, :enum, :extends, :super,
  :const, :export, :import,
  #future reserved words(strict mode) (TODO)
  #:implements, :let, :private, :public, :yield,
  #:interface, :package, :protected, :static,
  :null, :false, :true
]
@@sym =
{}

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Literal

#lt?, #priority, #side_effect?, #ws?

Methods inherited from Base

#add_remove_paren, #concat, #replace

Constructor Details

#initialize(val) ⇒ IdentifierName

Returns a new instance of IdentifierName.



1182
1183
1184
# File 'lib/minjs/ecma262/literal.rb', line 1182

def initialize(val)
  @val = val.to_sym
end

Instance Attribute Details

#exe_contextObject

Returns the value of attribute exe_context.



1177
1178
1179
# File 'lib/minjs/ecma262/literal.rb', line 1177

def exe_context
  @exe_context
end

#valObject (readonly)

Returns the value of attribute val.



1178
1179
1180
# File 'lib/minjs/ecma262/literal.rb', line 1178

def val
  @val
end

Class Method Details

.get(val) ⇒ Object

get instance



1187
1188
1189
1190
1191
1192
1193
# File 'lib/minjs/ecma262/literal.rb', line 1187

def self.get(val)
  if reserved?(val)
    @@sym[val] ||= self.new(val)
  else
    self.new(val)
  end
end

.reserved?(val) ⇒ Boolean

Returns true if val is reserved word.

Parameters:

  • val (String)

    value

Returns:



1223
1224
1225
# File 'lib/minjs/ecma262/literal.rb', line 1223

def self.reserved?(val)
  RESERVED_WORD.include?(val)
end

Instance Method Details

#==(obj) ⇒ Object

compare object



1241
1242
1243
# File 'lib/minjs/ecma262/literal.rb', line 1241

def ==(obj)
  self.class == obj.class and self.val == obj.val
end

#binding_env(lex_env) ⇒ EnvRecord

Returns binding environment.

Returns:



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'lib/minjs/ecma262/literal.rb', line 1261

def binding_env(lex_env)
  return nil if lex_env.nil?
  v = lex_env

  while v
    if v.record.binding[val]
      return v
    else
      v = v.outer
    end
  end
  nil
end

#deep_dupObject

duplicate object

See Also:



1236
1237
1238
# File 'lib/minjs/ecma262/literal.rb', line 1236

def deep_dup
  self.class.new(@val)
end

#left_hand_side_exp?Boolean

Returns true if expression is kind of LeftHandSideExpression.

Returns:

  • (Boolean)

    true if expression is kind of LeftHandSideExpression.



1256
1257
1258
# File 'lib/minjs/ecma262/literal.rb', line 1256

def left_hand_side_exp?
  true
end

#reserved?Boolean

Returns true if this literal is reserved word.

Returns:



1217
1218
1219
# File 'lib/minjs/ecma262/literal.rb', line 1217

def reserved?
  RESERVED_WORD.include?(val)
end

#to_js(options = {}) ⇒ Object

Returns a ECMAScript string containg the representation of element.

See Also:



1247
1248
1249
# File 'lib/minjs/ecma262/literal.rb', line 1247

def to_js(options = {})
  val.to_s
end

#to_sObject



1251
1252
1253
# File 'lib/minjs/ecma262/literal.rb', line 1251

def to_s
  val.to_s
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:

See Also:



1230
1231
1232
# File 'lib/minjs/ecma262/literal.rb', line 1230

def traverse(parent)
  yield parent, self
end