rkelly-turbo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +38 -0
- data/Manifest.txt +203 -0
- data/README.rdoc +135 -0
- data/Rakefile +41 -0
- data/lib/parser.y +883 -0
- data/lib/rkelly.rb +14 -0
- data/lib/rkelly/char_pos.rb +39 -0
- data/lib/rkelly/char_range.rb +33 -0
- data/lib/rkelly/constants.rb +3 -0
- data/lib/rkelly/generated_parser.rb +3380 -0
- data/lib/rkelly/js.rb +14 -0
- data/lib/rkelly/js/array.rb +15 -0
- data/lib/rkelly/js/base.rb +91 -0
- data/lib/rkelly/js/boolean.rb +21 -0
- data/lib/rkelly/js/function.rb +39 -0
- data/lib/rkelly/js/function_prototype.rb +15 -0
- data/lib/rkelly/js/global_object.rb +52 -0
- data/lib/rkelly/js/math.rb +10 -0
- data/lib/rkelly/js/nan.rb +18 -0
- data/lib/rkelly/js/number.rb +22 -0
- data/lib/rkelly/js/object.rb +30 -0
- data/lib/rkelly/js/object_prototype.rb +14 -0
- data/lib/rkelly/js/property.rb +20 -0
- data/lib/rkelly/js/scope.rb +6 -0
- data/lib/rkelly/js/string.rb +21 -0
- data/lib/rkelly/lexeme.rb +18 -0
- data/lib/rkelly/nodes.rb +25 -0
- data/lib/rkelly/nodes/binary_node.rb +18 -0
- data/lib/rkelly/nodes/bracket_accessor_node.rb +11 -0
- data/lib/rkelly/nodes/case_clause_node.rb +11 -0
- data/lib/rkelly/nodes/comma_node.rb +11 -0
- data/lib/rkelly/nodes/conditional_node.rb +11 -0
- data/lib/rkelly/nodes/dot_accessor_node.rb +11 -0
- data/lib/rkelly/nodes/for_in_node.rb +12 -0
- data/lib/rkelly/nodes/for_node.rb +13 -0
- data/lib/rkelly/nodes/function_call_node.rb +16 -0
- data/lib/rkelly/nodes/function_decl_node.rb +6 -0
- data/lib/rkelly/nodes/function_expr_node.rb +12 -0
- data/lib/rkelly/nodes/if_node.rb +12 -0
- data/lib/rkelly/nodes/label_node.rb +11 -0
- data/lib/rkelly/nodes/new_expr_node.rb +11 -0
- data/lib/rkelly/nodes/node.rb +116 -0
- data/lib/rkelly/nodes/not_strict_equal_node.rb +6 -0
- data/lib/rkelly/nodes/op_equal_node.rb +16 -0
- data/lib/rkelly/nodes/postfix_node.rb +11 -0
- data/lib/rkelly/nodes/prefix_node.rb +6 -0
- data/lib/rkelly/nodes/property_node.rb +13 -0
- data/lib/rkelly/nodes/resolve_node.rb +19 -0
- data/lib/rkelly/nodes/strict_equal_node.rb +6 -0
- data/lib/rkelly/nodes/try_node.rb +13 -0
- data/lib/rkelly/nodes/var_decl_node.rb +15 -0
- data/lib/rkelly/parser.rb +106 -0
- data/lib/rkelly/runtime.rb +36 -0
- data/lib/rkelly/runtime/ruby_function.rb +13 -0
- data/lib/rkelly/runtime/scope_chain.rb +57 -0
- data/lib/rkelly/syntax_error.rb +4 -0
- data/lib/rkelly/token.rb +27 -0
- data/lib/rkelly/tokenizer.rb +255 -0
- data/lib/rkelly/visitable.rb +31 -0
- data/lib/rkelly/visitors.rb +4 -0
- data/lib/rkelly/visitors/dot_visitor.rb +228 -0
- data/lib/rkelly/visitors/ecma_visitor.rb +328 -0
- data/lib/rkelly/visitors/enumerable_visitor.rb +18 -0
- data/lib/rkelly/visitors/evaluation_visitor.rb +419 -0
- data/lib/rkelly/visitors/function_visitor.rb +46 -0
- data/lib/rkelly/visitors/pointcut_visitor.rb +31 -0
- data/lib/rkelly/visitors/real_sexp_visitor.rb +16 -0
- data/lib/rkelly/visitors/sexp_visitor.rb +373 -0
- data/lib/rkelly/visitors/visitor.rb +149 -0
- data/test/ecma_script_test_case.rb +21 -0
- data/test/execute_test_case.rb +16 -0
- data/test/execution_contexts/test_10_1_3-1.rb +32 -0
- data/test/expressions/test_11_3_1.rb +64 -0
- data/test/expressions/test_11_3_2.rb +64 -0
- data/test/expressions/test_11_4_2.rb +13 -0
- data/test/expressions/test_11_4_3.rb +52 -0
- data/test/expressions/test_11_4_4.rb +68 -0
- data/test/expressions/test_11_4_5.rb +69 -0
- data/test/expressions/test_11_4_6.rb +94 -0
- data/test/expressions/test_11_4_8.rb +28 -0
- data/test/expressions/test_11_4_9.rb +103 -0
- data/test/expressions/test_11_5_1.rb +51 -0
- data/test/expressions/test_11_5_2.rb +80 -0
- data/test/expressions/test_11_5_3.rb +88 -0
- data/test/expressions/test_11_6_1-1.rb +19 -0
- data/test/expressions/test_11_9_1.rb +19 -0
- data/test/function/test_15_3_1_1-1.rb +34 -0
- data/test/global_object/test_15_1_1_1.rb +29 -0
- data/test/global_object/test_15_1_1_2.rb +17 -0
- data/test/global_object/test_15_1_1_3.rb +9 -0
- data/test/helper.rb +5 -0
- data/test/node_test_case.rb +11 -0
- data/test/object/test_15_2_1_1.rb +257 -0
- data/test/object/test_15_2_1_2.rb +21 -0
- data/test/object/test_15_2_2_1.rb +52 -0
- data/test/statements/test_12_5-1.rb +27 -0
- data/test/test_add_node.rb +8 -0
- data/test/test_arguments_node.rb +8 -0
- data/test/test_array_node.rb +9 -0
- data/test/test_assign_expr_node.rb +8 -0
- data/test/test_automatic_semicolon_insertion.rb +137 -0
- data/test/test_bit_and_node.rb +8 -0
- data/test/test_bit_or_node.rb +8 -0
- data/test/test_bit_x_or_node.rb +8 -0
- data/test/test_bitwise_not_node.rb +8 -0
- data/test/test_block_node.rb +14 -0
- data/test/test_bracket_accessor_node.rb +16 -0
- data/test/test_break_node.rb +11 -0
- data/test/test_case_block_node.rb +11 -0
- data/test/test_case_clause_node.rb +15 -0
- data/test/test_char_pos.rb +39 -0
- data/test/test_char_range.rb +29 -0
- data/test/test_comma_node.rb +13 -0
- data/test/test_comments.rb +45 -0
- data/test/test_conditional_node.rb +17 -0
- data/test/test_const_statement_node.rb +14 -0
- data/test/test_continue_node.rb +11 -0
- data/test/test_delete_node.rb +8 -0
- data/test/test_divide_node.rb +8 -0
- data/test/test_do_while_node.rb +13 -0
- data/test/test_dot_accessor_node.rb +9 -0
- data/test/test_ecma_visitor.rb +213 -0
- data/test/test_element_node.rb +8 -0
- data/test/test_empty_statement_node.rb +8 -0
- data/test/test_equal_node.rb +8 -0
- data/test/test_evaluation_visitor.rb +66 -0
- data/test/test_expression_statement_node.rb +10 -0
- data/test/test_false_node.rb +8 -0
- data/test/test_for_in_node.rb +17 -0
- data/test/test_for_node.rb +24 -0
- data/test/test_function_body_node.rb +8 -0
- data/test/test_function_call_node.rb +10 -0
- data/test/test_function_decl_node.rb +16 -0
- data/test/test_function_expr_node.rb +16 -0
- data/test/test_function_visitor.rb +26 -0
- data/test/test_getter_property_node.rb +10 -0
- data/test/test_global_object.rb +49 -0
- data/test/test_greater_node.rb +8 -0
- data/test/test_greater_or_equal_node.rb +8 -0
- data/test/test_if_node.rb +17 -0
- data/test/test_in_node.rb +8 -0
- data/test/test_instance_of_node.rb +8 -0
- data/test/test_label_node.rb +13 -0
- data/test/test_left_shift_node.rb +8 -0
- data/test/test_less_node.rb +8 -0
- data/test/test_less_or_equal_node.rb +8 -0
- data/test/test_line_number.rb +81 -0
- data/test/test_logical_and_node.rb +8 -0
- data/test/test_logical_not_node.rb +8 -0
- data/test/test_logical_or_node.rb +8 -0
- data/test/test_modulus_node.rb +8 -0
- data/test/test_multiply_node.rb +8 -0
- data/test/test_new_expr_node.rb +9 -0
- data/test/test_not_equal_node.rb +8 -0
- data/test/test_not_strict_equal_node.rb +8 -0
- data/test/test_null_node.rb +8 -0
- data/test/test_number_node.rb +8 -0
- data/test/test_object_literal_node.rb +9 -0
- data/test/test_op_and_equal_node.rb +10 -0
- data/test/test_op_divide_equal_node.rb +10 -0
- data/test/test_op_equal_node.rb +10 -0
- data/test/test_op_l_shift_equal_node.rb +10 -0
- data/test/test_op_minus_equal_node.rb +10 -0
- data/test/test_op_mod_equal_node.rb +10 -0
- data/test/test_op_multiply_equal_node.rb +10 -0
- data/test/test_op_or_equal_node.rb +10 -0
- data/test/test_op_plus_equal_node.rb +10 -0
- data/test/test_op_r_shift_equal_node.rb +10 -0
- data/test/test_op_u_r_shift_equal_node.rb +10 -0
- data/test/test_op_x_or_equal_node.rb +10 -0
- data/test/test_parameter_node.rb +8 -0
- data/test/test_parser.rb +1434 -0
- data/test/test_pointcut_visitor.rb +34 -0
- data/test/test_postfix_node.rb +8 -0
- data/test/test_prefix_node.rb +8 -0
- data/test/test_property_node.rb +8 -0
- data/test/test_regexp_node.rb +8 -0
- data/test/test_resolve_node.rb +22 -0
- data/test/test_return_node.rb +11 -0
- data/test/test_right_shift_node.rb +8 -0
- data/test/test_rkelly.rb +19 -0
- data/test/test_runtime.rb +12 -0
- data/test/test_scope_chain.rb +50 -0
- data/test/test_setter_property_node.rb +10 -0
- data/test/test_source_elements.rb +9 -0
- data/test/test_strict_equal_node.rb +8 -0
- data/test/test_string_node.rb +8 -0
- data/test/test_subtract_node.rb +8 -0
- data/test/test_switch_node.rb +12 -0
- data/test/test_this_node.rb +8 -0
- data/test/test_throw_node.rb +7 -0
- data/test/test_tokenizer.rb +285 -0
- data/test/test_true_node.rb +8 -0
- data/test/test_try_node.rb +59 -0
- data/test/test_type_of_node.rb +8 -0
- data/test/test_unary_minus_node.rb +8 -0
- data/test/test_unary_plus_node.rb +8 -0
- data/test/test_unsigned_right_shift_node.rb +8 -0
- data/test/test_var_decl_node.rb +21 -0
- data/test/test_var_statement_node.rb +14 -0
- data/test/test_void_node.rb +8 -0
- data/test/test_while_node.rb +15 -0
- data/test/test_with_node.rb +8 -0
- metadata +293 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
module RKelly
|
2
|
+
module Visitors
|
3
|
+
class Visitor
|
4
|
+
TERMINAL_NODES = %w{
|
5
|
+
Break Continue EmptyStatement False Null Number Parameter Regexp Resolve
|
6
|
+
String This True
|
7
|
+
}
|
8
|
+
SINGLE_VALUE_NODES = %w{
|
9
|
+
Parenthetical AssignExpr BitwiseNot Block Delete Element ExpressionStatement
|
10
|
+
FunctionBody LogicalNot Return Throw TypeOf UnaryMinus UnaryPlus Void
|
11
|
+
}
|
12
|
+
BINARY_NODES = %w{
|
13
|
+
Add BitAnd BitOr BitXOr CaseClause Comma Divide DoWhile Equal Greater
|
14
|
+
GreaterOrEqual In InstanceOf LeftShift Less LessOrEqual LogicalAnd
|
15
|
+
LogicalOr Modulus Multiply NotEqual NotStrictEqual OpAndEqual
|
16
|
+
OpDivideEqual OpEqual OpLShiftEqual OpMinusEqual OpModEqual
|
17
|
+
OpMultiplyEqual OpOrEqual OpPlusEqual OpRShiftEqual OpURShiftEqual
|
18
|
+
OpXOrEqual RightShift StrictEqual Subtract Switch UnsignedRightShift
|
19
|
+
While With
|
20
|
+
}
|
21
|
+
ARRAY_VALUE_NODES = %w{
|
22
|
+
Arguments Array CaseBlock ConstStatement ObjectLiteral SourceElements
|
23
|
+
VarStatement
|
24
|
+
}
|
25
|
+
NAME_VALUE_NODES = %w{
|
26
|
+
Label Property GetterProperty SetterProperty VarDecl
|
27
|
+
}
|
28
|
+
PREFIX_POSTFIX_NODES = %w{ Postfix Prefix }
|
29
|
+
CONDITIONAL_NODES = %w{ If Conditional }
|
30
|
+
FUNC_CALL_NODES = %w{ NewExpr FunctionCall }
|
31
|
+
FUNC_DECL_NODES = %w{ FunctionExpr FunctionDecl }
|
32
|
+
ALL_NODES = %w{ For ForIn Try BracketAccessor DotAccessor } +
|
33
|
+
TERMINAL_NODES + SINGLE_VALUE_NODES + BINARY_NODES + ARRAY_VALUE_NODES +
|
34
|
+
NAME_VALUE_NODES + PREFIX_POSTFIX_NODES + CONDITIONAL_NODES +
|
35
|
+
FUNC_CALL_NODES + FUNC_DECL_NODES
|
36
|
+
|
37
|
+
def accept(target)
|
38
|
+
target.accept(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
TERMINAL_NODES.each do |type|
|
42
|
+
define_method(:"visit_#{type}Node") { |o| o.value }
|
43
|
+
end
|
44
|
+
|
45
|
+
BINARY_NODES.each do |type|
|
46
|
+
define_method(:"visit_#{type}Node") do |o|
|
47
|
+
[o.left && o.left.accept(self), o.value && o.value.accept(self)]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
ARRAY_VALUE_NODES.each do |type|
|
52
|
+
define_method(:"visit_#{type}Node") do |o|
|
53
|
+
return nil unless o.value
|
54
|
+
out = Array.new(length = o.value.length); i=-1
|
55
|
+
while (i+=1) < length
|
56
|
+
val = o.value[i]
|
57
|
+
out[i] = val ? val.accept(self) : nil
|
58
|
+
end
|
59
|
+
out
|
60
|
+
#o.value && o.value.map { |v| v ? v.accept(self) : nil }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
NAME_VALUE_NODES.each do |type|
|
65
|
+
define_method(:"visit_#{type}Node") do |o|
|
66
|
+
val = o.value
|
67
|
+
[o.name.to_s.to_sym, val ? val.accept(self) : nil]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
SINGLE_VALUE_NODES.each do |type|
|
72
|
+
define_method(:"visit_#{type}Node") do |o|
|
73
|
+
o.value.accept(self) if o.value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
PREFIX_POSTFIX_NODES.each do |type|
|
78
|
+
define_method(:"visit_#{type}Node") do |o|
|
79
|
+
o.operand.accept(self)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
CONDITIONAL_NODES.each do |type|
|
84
|
+
define_method(:"visit_#{type}Node") do |o|
|
85
|
+
[ o.conditions.accept(self),
|
86
|
+
o.value.accept(self),
|
87
|
+
o.else ? o.else.accept(self) : nil
|
88
|
+
]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
FUNC_CALL_NODES.each do |type|
|
92
|
+
define_method(:"visit_#{type}Node") do |o|
|
93
|
+
[o.value.accept(self), o.arguments.accept(self)]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
FUNC_DECL_NODES.each do |type|
|
97
|
+
define_method(:"visit_#{type}Node") do |o|
|
98
|
+
out = Array.new(length = o.arguments.length); i = -1
|
99
|
+
while (i += 1) < length
|
100
|
+
out[i] = o.arguments[i].accept(self)
|
101
|
+
end
|
102
|
+
val = o.value
|
103
|
+
[
|
104
|
+
val ? val : nil,
|
105
|
+
out, #o.arguments.map { |x| x.accept(self) },
|
106
|
+
o.function_body.accept(self)
|
107
|
+
]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def visit_ForNode(o)
|
112
|
+
[
|
113
|
+
o.init ? o.init.accept(self) : nil,
|
114
|
+
o.test ? o.test.accept(self) : nil,
|
115
|
+
o.counter ? o.counter.accept(self) : nil,
|
116
|
+
o.value.accept(self)
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
def visit_ForInNode(o)
|
121
|
+
[
|
122
|
+
o.left.accept(self),
|
123
|
+
o.right.accept(self),
|
124
|
+
o.value.accept(self)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
def visit_TryNode(o)
|
129
|
+
[
|
130
|
+
o.value.accept(self),
|
131
|
+
o.catch_var ? o.catch_var : nil,
|
132
|
+
o.catch_block ? o.catch_block.accept(self) : nil,
|
133
|
+
o.finally_block ? o.finally_block.accept(self) : nil
|
134
|
+
]
|
135
|
+
end
|
136
|
+
|
137
|
+
def visit_BracketAccessorNode(o)
|
138
|
+
[
|
139
|
+
o.value.accept(self),
|
140
|
+
o.accessor.accept(self)
|
141
|
+
]
|
142
|
+
end
|
143
|
+
|
144
|
+
def visit_DotAccessorNode(o)
|
145
|
+
o.value.accept(self)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ECMAScriptTestCase < Test::Unit::TestCase
|
2
|
+
include RKelly::JS
|
3
|
+
|
4
|
+
if method_defined? :default_test
|
5
|
+
undef :default_test
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@runtime = RKelly::Runtime.new
|
10
|
+
@runtime.define_function(:assert_equal) do |*args|
|
11
|
+
assert_equal(*args)
|
12
|
+
end
|
13
|
+
@runtime.define_function(:assert_in_delta) do |*args|
|
14
|
+
assert_in_delta(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def js_assert_equal(expected, actual)
|
19
|
+
@runtime.execute("assert_equal(#{expected}, #{actual});")
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ExecuteTestCase < Test::Unit::TestCase
|
2
|
+
include RKelly::Nodes
|
3
|
+
|
4
|
+
if method_defined? :default_test
|
5
|
+
undef :default_test
|
6
|
+
end
|
7
|
+
|
8
|
+
def assert_execute(expected, code)
|
9
|
+
scope_chain = @runtime.execute(code)
|
10
|
+
expected.each do |name, value|
|
11
|
+
assert scope_chain.has_property?(name)
|
12
|
+
assert_equal value, scope_chain[name].value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class ExecutionContext_10_1_3_1_Test < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@runtime = RKelly::Runtime.new
|
6
|
+
@runtime.define_function(:assert_equal) do |*args|
|
7
|
+
assert_equal(*args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_myfun3_void_0
|
12
|
+
scope_chain = @runtime.execute("
|
13
|
+
function myfun3(a, b, a) {
|
14
|
+
return a;
|
15
|
+
}
|
16
|
+
var x = myfun3(2,4);
|
17
|
+
")
|
18
|
+
assert scope_chain.has_property?('x')
|
19
|
+
#assert_equal :undefined, scope_chain['x'].value
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_myfun3
|
23
|
+
scope_chain = @runtime.execute("
|
24
|
+
function myfun3(a, b, a) {
|
25
|
+
return a;
|
26
|
+
}
|
27
|
+
var x = myfun3(2,4,8);
|
28
|
+
")
|
29
|
+
assert scope_chain.has_property?('x')
|
30
|
+
assert_equal 8, scope_chain['x'].value
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Expressions_11_3_1_Test < ECMAScriptTestCase
|
4
|
+
def test_uninitialized
|
5
|
+
@runtime.execute("var MYVAR; assert_equal(NaN, MYVAR++); assert_equal(NaN, MYVAR);")
|
6
|
+
end
|
7
|
+
|
8
|
+
@@tests = [
|
9
|
+
:undefined => [ '(void 0)', 'NaN', 'NaN'],
|
10
|
+
:null => [ 'null', '0', '1'],
|
11
|
+
:true => [ 'true', '1', '2'],
|
12
|
+
:false => [ 'false', '0', '1'],
|
13
|
+
:positive_infinity => [ 'Number.POSITIVE_INFINITY',
|
14
|
+
'Number.POSITIVE_INFINITY',
|
15
|
+
'Number.POSITIVE_INFINITY'],
|
16
|
+
:negative_infinity => [ 'Number.NEGATIVE_INFINITY',
|
17
|
+
'Number.NEGATIVE_INFINITY',
|
18
|
+
'Number.NEGATIVE_INFINITY'],
|
19
|
+
:nan => [ 'Number.NaN', 'Number.NaN', 'Number.NaN'],
|
20
|
+
:zero => [ '0', '0', '1'],
|
21
|
+
:boolean_false => ['new Boolean(false)', '0', '1'],
|
22
|
+
:boolean_true => ['new Boolean(true)', '1', '2'],
|
23
|
+
:string_string => ["'string'", 'Number.NaN', 'Number.NaN'],
|
24
|
+
:number_s => ["'12345'", '12345', '12346'],
|
25
|
+
:negative_s => ["'-12345'", '-12345', '-12344'],
|
26
|
+
:hex_s => ["'0Xf'", '15', '16'],
|
27
|
+
:num_0_s => ["'077'", '77', '78'],
|
28
|
+
:empty_s => ["''", '0', '1'],
|
29
|
+
:obj_string_string => ['new String("string")', 'Number.NaN', 'Number.NaN'],
|
30
|
+
:obj_string_num => ['new String("12345")', '12345', '12346'],
|
31
|
+
:obj_negative => ['new String("-12345")', '-12345', '-12344'],
|
32
|
+
:obj_hex => ['new String("0Xf")', '15', '16'],
|
33
|
+
:obj_0_s => ['new String("077")', '77', '78'],
|
34
|
+
:obj_empty => ['new String("")', '0', '1'],
|
35
|
+
]
|
36
|
+
|
37
|
+
def test_positive_float
|
38
|
+
@runtime.execute("
|
39
|
+
var MYVAR=0.2345;
|
40
|
+
assert_equal(0.2345, MYVAR++);
|
41
|
+
assert_in_delta(1.2345, MYVAR, 0.00001);
|
42
|
+
")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_negative_float
|
46
|
+
@runtime.execute("
|
47
|
+
var MYVAR=-0.2345;
|
48
|
+
assert_equal(-0.2345, MYVAR++);
|
49
|
+
assert_in_delta(0.7655, MYVAR, 0.00001);
|
50
|
+
")
|
51
|
+
end
|
52
|
+
|
53
|
+
@@tests.each do |testing|
|
54
|
+
testing.each do |name, values|
|
55
|
+
define_method(:"test_#{name}") do
|
56
|
+
@runtime.execute("
|
57
|
+
var MYVAR=#{values[0]};
|
58
|
+
assert_equal(#{values[1]}, MYVAR++);
|
59
|
+
assert_equal(#{values[2]}, MYVAR);
|
60
|
+
")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Expressions_11_3_2_Test < ECMAScriptTestCase
|
4
|
+
def test_uninitialized
|
5
|
+
@runtime.execute("var MYVAR; assert_equal(NaN, MYVAR--); assert_equal(NaN, MYVAR);")
|
6
|
+
end
|
7
|
+
|
8
|
+
@@tests = [
|
9
|
+
:undefined => [ '(void 0)', 'NaN', 'NaN'],
|
10
|
+
:null => [ 'null', '0', '-1'],
|
11
|
+
:true => [ 'true', '1', '0'],
|
12
|
+
:false => [ 'false', '0', '-1'],
|
13
|
+
:positive_infinity => [ 'Number.POSITIVE_INFINITY',
|
14
|
+
'Number.POSITIVE_INFINITY',
|
15
|
+
'Number.POSITIVE_INFINITY'],
|
16
|
+
:negative_infinity => [ 'Number.NEGATIVE_INFINITY',
|
17
|
+
'Number.NEGATIVE_INFINITY',
|
18
|
+
'Number.NEGATIVE_INFINITY'],
|
19
|
+
:nan => [ 'Number.NaN', 'Number.NaN', 'Number.NaN'],
|
20
|
+
:zero => [ '0', '0', '-1'],
|
21
|
+
:boolean_false => ['new Boolean(false)', '0', '-1'],
|
22
|
+
:boolean_true => ['new Boolean(true)', '1', '0'],
|
23
|
+
:string_string => ["'string'", 'Number.NaN', 'Number.NaN'],
|
24
|
+
:number_s => ["'12345'", '12345', '12344'],
|
25
|
+
:negative_s => ["'-12345'", '-12345', '-12346'],
|
26
|
+
:hex_s => ["'0Xf'", '15', '14'],
|
27
|
+
:num_0_s => ["'077'", '77', '76'],
|
28
|
+
:empty_s => ["''", '0', '-1'],
|
29
|
+
:obj_string_string => ['new String("string")', 'Number.NaN', 'Number.NaN'],
|
30
|
+
:obj_string_num => ['new String("12345")', '12345', '12344'],
|
31
|
+
:obj_negative => ['new String("-12345")', '-12345', '-12346'],
|
32
|
+
:obj_hex => ['new String("0Xf")', '15', '14'],
|
33
|
+
:obj_0_s => ['new String("077")', '77', '76'],
|
34
|
+
:obj_empty => ['new String("")', '0', '-1'],
|
35
|
+
]
|
36
|
+
|
37
|
+
def test_positive_float
|
38
|
+
@runtime.execute("
|
39
|
+
var MYVAR=0.2345;
|
40
|
+
assert_equal(0.2345, MYVAR--);
|
41
|
+
assert_in_delta(-0.7655, MYVAR, 0.00001);
|
42
|
+
")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_negative_float
|
46
|
+
@runtime.execute("
|
47
|
+
var MYVAR=-0.2345;
|
48
|
+
assert_equal(-0.2345, MYVAR--);
|
49
|
+
assert_in_delta(-1.2345, MYVAR, 0.00001);
|
50
|
+
")
|
51
|
+
end
|
52
|
+
|
53
|
+
@@tests.each do |testing|
|
54
|
+
testing.each do |name, values|
|
55
|
+
define_method(:"test_#{name}") do
|
56
|
+
@runtime.execute("
|
57
|
+
var MYVAR=#{values[0]};
|
58
|
+
assert_equal(#{values[1]}, MYVAR--);
|
59
|
+
assert_equal(#{values[2]}, MYVAR);
|
60
|
+
")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Expressions_11_4_2_Test < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@runtime = RKelly::Runtime.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_void_1
|
9
|
+
scope_chain = @runtime.execute("var x = void(10);")
|
10
|
+
assert scope_chain.has_property?('x')
|
11
|
+
assert_equal :undefined, scope_chain['x'].value
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Typeof_11_4_3_Test < ExecuteTestCase
|
4
|
+
def setup
|
5
|
+
@runtime = RKelly::Runtime.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_typeof_null
|
9
|
+
assert_execute({ 'x' => 'object' },
|
10
|
+
"var x = typeof(null);")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_typeof_void_0
|
14
|
+
assert_execute({ 'x' => 'undefined' },
|
15
|
+
"var x = typeof(void(0));")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_typeof_true
|
19
|
+
assert_execute({ 'x' => 'boolean' },
|
20
|
+
"var x = typeof(true);")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_typeof_false
|
24
|
+
assert_execute({ 'x' => 'boolean' },
|
25
|
+
"var x = typeof(false);")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_typeof_nan
|
29
|
+
assert_execute({ 'x' => 'number' },
|
30
|
+
"var x = typeof(NaN);")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_typeof_zero
|
34
|
+
assert_execute({ 'x' => 'number' }, "var x = typeof(0);")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_typeof_one
|
38
|
+
assert_execute({ 'x' => 'number' }, "var x = typeof(1);")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_typeof_minus_one
|
42
|
+
assert_execute({ 'x' => 'number' }, "var x = typeof(-1);")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_typeof_plus_one
|
46
|
+
assert_execute({ 'x' => 'number' }, "var x = typeof(+1);")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_typeof_zero_string
|
50
|
+
assert_execute({ 'x' => 'string' }, "var x = typeof('0');")
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../helper"
|
2
|
+
|
3
|
+
class Expressions_11_4_4_Test < ECMAScriptTestCase
|
4
|
+
def test_uninitialized
|
5
|
+
@runtime.execute("
|
6
|
+
var MYVAR;
|
7
|
+
assert_equal(NaN, ++MYVAR);
|
8
|
+
assert_equal(NaN, MYVAR);
|
9
|
+
")
|
10
|
+
end
|
11
|
+
|
12
|
+
@@tests = [
|
13
|
+
:undefined => ['(void 0)', 'NaN'],
|
14
|
+
:null => ['null', '1'],
|
15
|
+
:true => ['true', '2'],
|
16
|
+
:false => ['false', '1'],
|
17
|
+
:positive_infinity => ['Number.POSITIVE_INFINITY',
|
18
|
+
'Number.POSITIVE_INFINITY'],
|
19
|
+
:negative_infinity => ['Number.NEGATIVE_INFINITY',
|
20
|
+
'Number.NEGATIVE_INFINITY'],
|
21
|
+
:nan => ['Number.NaN', 'Number.NaN'],
|
22
|
+
:zero => ['0', '1'],
|
23
|
+
#:pos_float => ['0.2345', '1.2345'],
|
24
|
+
#:neg_float => ['-0.2345', '0.7655'],
|
25
|
+
:boolean_false => ['new Boolean(false)', '1'],
|
26
|
+
:boolean_true => ['new Boolean(true)', '2'],
|
27
|
+
:string_string => ["'string'", 'Number.NaN'],
|
28
|
+
:number_s => ["'12345'", '12346'],
|
29
|
+
:negative_s => ["'-12345'", '-12344'],
|
30
|
+
:hex_s => ["'0Xf'", '16'],
|
31
|
+
:num_0_s => ["'077'", '78'],
|
32
|
+
:empty_s => ["''", '1'],
|
33
|
+
:obj_string_string => ['new String("string")', 'Number.NaN'],
|
34
|
+
:obj_string_num => ['new String("12345")', '12346'],
|
35
|
+
:obj_negative => ['new String("-12345")', '-12344'],
|
36
|
+
:obj_hex => ['new String("0Xf")', '16'],
|
37
|
+
:obj_0_s => ['new String("077")', '78'],
|
38
|
+
:obj_empty => ['new String("")', '1'],
|
39
|
+
]
|
40
|
+
|
41
|
+
def test_positive_float
|
42
|
+
@runtime.execute("
|
43
|
+
var MYVAR=0.2345;
|
44
|
+
assert_in_delta(1.2345, ++MYVAR, 0.00001);
|
45
|
+
assert_in_delta(1.2345, MYVAR, 0.00001);
|
46
|
+
")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_negative_float
|
50
|
+
@runtime.execute("
|
51
|
+
var MYVAR=-0.2345;
|
52
|
+
assert_in_delta(0.7655, ++MYVAR, 0.00001);
|
53
|
+
assert_in_delta(0.7655, MYVAR, 0.00001);
|
54
|
+
")
|
55
|
+
end
|
56
|
+
|
57
|
+
@@tests.each do |testing|
|
58
|
+
testing.each do |name, values|
|
59
|
+
define_method(:"test_#{name}") do
|
60
|
+
@runtime.execute("
|
61
|
+
var MYVAR=#{values[0]};
|
62
|
+
assert_equal(#{values[1]}, ++MYVAR);
|
63
|
+
assert_equal(#{values[1]}, MYVAR);
|
64
|
+
")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|