opal 0.10.0.beta3 → 0.10.0.beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +9 -1
  4. data/HACKING.md +2 -2
  5. data/docs/compiled_ruby.md +6 -6
  6. data/lib/opal/cli_runners/nodejs.rb +3 -1
  7. data/lib/opal/nodes/args/mlhsarg.rb +1 -3
  8. data/lib/opal/nodes/def.rb +18 -54
  9. data/lib/opal/nodes/helpers.rb +3 -3
  10. data/lib/opal/nodes/iter.rb +32 -3
  11. data/lib/opal/nodes/logic.rb +5 -5
  12. data/lib/opal/nodes/node_with_args.rb +31 -0
  13. data/lib/opal/parser/lexer.rb +9 -7
  14. data/lib/opal/sprockets/processor.rb +2 -2
  15. data/lib/opal/version.rb +1 -1
  16. data/opal/corelib/array.rb +16 -0
  17. data/opal/corelib/basic_object.rb +1 -1
  18. data/opal/corelib/class.rb +15 -0
  19. data/opal/corelib/constants.rb +1 -1
  20. data/opal/corelib/enumerable.rb +32 -62
  21. data/opal/corelib/file.rb +2 -0
  22. data/opal/corelib/helpers.rb +41 -1
  23. data/opal/corelib/module.rb +26 -10
  24. data/opal/corelib/runtime.js +47 -12
  25. data/spec/filters/bugs/date.rb +0 -9
  26. data/spec/filters/bugs/hash.rb +0 -2
  27. data/spec/filters/bugs/kernel.rb +0 -5
  28. data/spec/filters/bugs/language.rb +4 -19
  29. data/spec/filters/bugs/module.rb +0 -30
  30. data/spec/filters/bugs/pathname.rb +5 -0
  31. data/spec/filters/bugs/proc.rb +0 -6
  32. data/spec/filters/unsupported/thread.rb +1 -0
  33. data/spec/lib/compiler_spec.rb +29 -29
  34. data/spec/opal/core/runtime/truthy_spec.rb +26 -0
  35. data/spec/ruby_specs +0 -3
  36. data/stdlib/date.rb +21 -0
  37. data/stdlib/native.rb +1 -1
  38. data/stdlib/nodejs/file.rb +36 -11
  39. data/stdlib/nodejs/io.rb +55 -0
  40. data/stdlib/pathname.rb +43 -0
  41. data/stdlib/promise.rb +1 -1
  42. data/tasks/testing.rake +55 -31
  43. data/test/nodejs/test_file.rb +30 -0
  44. metadata +6 -2
@@ -904,7 +904,14 @@
904
904
  }
905
905
  }
906
906
 
907
- parent = parent.$$is_class ? parent.$$super : null;
907
+ // only the actual singleton class gets included in its ancestry
908
+ // after that, traverse the normal class hierarchy
909
+ if (parent.$$is_singleton && parent.$$singleton_of.$$is_module) {
910
+ parent = parent.$$singleton_of.$$super;
911
+ }
912
+ else {
913
+ parent = parent.$$is_class ? parent.$$super : null;
914
+ }
908
915
  }
909
916
 
910
917
  return result;
@@ -993,7 +1000,10 @@
993
1000
  method_missing_stub.$$p = null;
994
1001
 
995
1002
  // call method missing with correct args (remove '$' prefix on method name)
996
- return this.$method_missing.apply(this, [method_name.slice(1)].concat($slice.call(arguments)));
1003
+ var args_ary = new Array(arguments.length);
1004
+ for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i]; }
1005
+
1006
+ return this.$method_missing.apply(this, [method_name.slice(1)].concat(args_ary));
997
1007
  }
998
1008
 
999
1009
  method_missing_stub.$$stub = true;
@@ -1005,7 +1015,13 @@
1005
1015
  // Methods
1006
1016
  // -------
1007
1017
 
1008
- // Arity count error dispatcher
1018
+ // Arity count error dispatcher for methods
1019
+ //
1020
+ // @param actual [Fixnum] number of arguments given to method
1021
+ // @param expected [Fixnum] expected number of arguments
1022
+ // @param object [Object] owner of the method +meth+
1023
+ // @param meth [String] method name that got wrong number of arguments
1024
+ // @raise [ArgumentError]
1009
1025
  Opal.ac = function(actual, expected, object, meth) {
1010
1026
  var inspect = '';
1011
1027
  if (object.$$is_class || object.$$is_module) {
@@ -1019,6 +1035,18 @@
1019
1035
  throw Opal.ArgumentError.$new('[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')');
1020
1036
  };
1021
1037
 
1038
+ // Arity count error dispatcher for blocks
1039
+ //
1040
+ // @param actual [Fixnum] number of arguments given to block
1041
+ // @param expected [Fixnum] expected number of arguments
1042
+ // @param context [Object] context of the block definition
1043
+ // @raise [ArgumentError]
1044
+ Opal.block_ac = function(actual, expected, context) {
1045
+ var inspect = "`block in " + context + "'";
1046
+
1047
+ throw Opal.ArgumentError.$new(inspect + ': wrong number of arguments (' + actual + ' for ' + expected + ')');
1048
+ }
1049
+
1022
1050
  // Super dispatcher
1023
1051
  Opal.find_super_dispatcher = function(obj, jsid, current_func, defcheck, defs) {
1024
1052
  var dispatcher;
@@ -1184,7 +1212,10 @@
1184
1212
  }
1185
1213
 
1186
1214
  if (!args.$$is_array) {
1187
- args = $slice.call(args);
1215
+ var args_ary = new Array(args.length);
1216
+ for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; }
1217
+
1218
+ return block.apply(null, args_ary);
1188
1219
  }
1189
1220
 
1190
1221
  return block.apply(null, args);
@@ -1369,26 +1400,30 @@
1369
1400
  // @param mid [String] ruby method to call
1370
1401
  // @return [Object] forwards the return value of the method (or of method_missing)
1371
1402
  Opal.send = function(recv, mid) {
1372
- var args = $slice.call(arguments, 2),
1373
- func = recv['$' + mid];
1403
+ var args_ary = new Array(Math.max(arguments.length - 2, 0));
1404
+ for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i + 2]; }
1405
+
1406
+ var func = recv['$' + mid];
1374
1407
 
1375
1408
  if (func) {
1376
- return func.apply(recv, args);
1409
+ return func.apply(recv, args_ary);
1377
1410
  }
1378
1411
 
1379
- return recv.$method_missing.apply(recv, [mid].concat(args));
1412
+ return recv.$method_missing.apply(recv, [mid].concat(args_ary));
1380
1413
  };
1381
1414
 
1382
1415
  Opal.block_send = function(recv, mid, block) {
1383
- var args = $slice.call(arguments, 3),
1384
- func = recv['$' + mid];
1416
+ var args_ary = new Array(Math.max(arguments.length - 3, 0));
1417
+ for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i + 3]; }
1418
+
1419
+ var func = recv['$' + mid];
1385
1420
 
1386
1421
  if (func) {
1387
1422
  func.$$p = block;
1388
- return func.apply(recv, args);
1423
+ return func.apply(recv, args_ary);
1389
1424
  }
1390
1425
 
1391
- return recv.$method_missing.apply(recv, [mid].concat(args));
1426
+ return recv.$method_missing.apply(recv, [mid].concat(args_ary));
1392
1427
  };
1393
1428
 
1394
1429
  // Used to define methods on an object. This is a helper method, used by the
@@ -1,8 +1,4 @@
1
1
  opal_filter "Date" do
2
- fails "Date#<< raises an error on non numeric parameters"
3
- fails "Date#<=> returns -1 when self is less than a Numeric"
4
- fails "Date#<=> returns 1 when self is greater than a Numeric"
5
- fails "Date#=== compares to another numeric"
6
2
  fails "Date#>> returns the day of the reform if date falls within calendar reform"
7
3
  fails "Date#ajd determines the Astronomical Julian day"
8
4
  fails "Date#amjd determines the Astronomical Modified Julian day"
@@ -12,8 +8,6 @@ opal_filter "Date" do
12
8
  fails "Date#commercial Creates a Date for the correct day given the year, week and day number"
13
9
  fails "Date#commercial Creates a Date for the monday in the year and week given"
14
10
  fails "Date#commercial creates only Date objects for valid weeks"
15
- fails "Date#cwday determines the commercial week day"
16
- fails "Date#cweek determines the commercial week"
17
11
  fails "Date#cwyear determines the commercial year"
18
12
  fails "Date#day_fraction determines the day fraction"
19
13
  fails "Date#downto creates earlier dates when passed a negative step"
@@ -21,8 +15,6 @@ opal_filter "Date" do
21
15
  fails "Date#gregorian converts a date object into another with the Gregorian calendar"
22
16
  fails "Date#gregorian? marks a day after the calendar reform as Julian"
23
17
  fails "Date#gregorian? marks a day before the calendar reform as Julian"
24
- fails "Date#gregorian_leap? returns false if a year is not a leap year in the Gregorian calendar"
25
- fails "Date#gregorian_leap? returns true if a year is a leap year in the Gregorian calendar"
26
18
  fails "Date#hash returns the same value for equal dates"
27
19
  fails "Date#italy converts a date object into another with the Italian calendar reform"
28
20
  fails "Date#julian converts a date object into another with the Julian calendar"
@@ -36,7 +28,6 @@ opal_filter "Date" do
36
28
  fails "Date#parse parses a day name into a Date object"
37
29
  fails "Date#parse parses a month day into a Date object"
38
30
  fails "Date#parse parses a month name into a Date object"
39
- fails "Date#parse parses DDD as year day number" # requires Date.gregorian_leap?
40
31
  fails "Date#prev_year returns the day of the reform if date falls within calendar reform"
41
32
  fails "Date#step steps backward in time"
42
33
  fails "Date#step steps forward in time"
@@ -2,8 +2,6 @@ opal_filter "Hash" do
2
2
  fails "Hash#== compares keys with eql? semantics" # spec relies on integer and float being different
3
3
  fails "Hash#== computes equality for complex recursive hashes"
4
4
  fails "Hash#== computes equality for recursive hashes & arrays"
5
- fails "Hash#each yields the key only to a block expecting |key,|" # procs in Opal do not have access to this info (yet)
6
- fails "Hash#each_pair yields the key only to a block expecting |key,|" # procs in Opal do not have access to this info (yet)
7
5
  fails "Hash#eql? compares keys with eql? semantics" # spec relies on integer and float being different
8
6
  fails "Hash#eql? computes equality for complex recursive hashes"
9
7
  fails "Hash#eql? computes equality for recursive hashes & arrays"
@@ -273,14 +273,9 @@ opal_filter "Kernel" do
273
273
  fails "Kernel.__method__ returns the caller from define_method too"
274
274
  fails "Kernel.global_variables finds subset starting with std"
275
275
  fails "Kernel.global_variables is a private method"
276
- fails "Kernel.lambda accepts 0 arguments when used with ||"
277
- fails "Kernel.lambda checks the arity of the call when no args are specified"
278
- fails "Kernel.lambda checks the arity when 1 arg is specified"
279
- fails "Kernel.lambda does not check the arity when passing a Proc with &"
280
276
  fails "Kernel.lambda is a private method"
281
277
  fails "Kernel.lambda raises an ArgumentError when no block is given"
282
278
  fails "Kernel.lambda returns from the lambda itself, not the creation site of the lambda"
283
- fails "Kernel.lambda strictly checks the arity when 0 or 2..inf args are specified"
284
279
  fails "Kernel.loop is a private method"
285
280
  fails "Kernel.loop rescues StopIteration"
286
281
  fails "Kernel.loop rescues StopIteration's subclasses"
@@ -32,13 +32,9 @@ opal_filter "language" do
32
32
  fails "A constant on a singleton class is not defined on the object's class"
33
33
  fails "A constant on a singleton class is not preserved when the object is duped"
34
34
  fails "A constant on a singleton class raises a NameError for anonymous_module::CONST"
35
- fails "A lambda expression 'lambda { ... }' assigns variables from parameters for definition '@a = lambda { |a, | a }'" # requires arity checking to be enabled
36
- fails "A lambda expression 'lambda { ... }' assigns variables from parameters for definition \n def m(*a) yield(*a) end\n @a = lambda { |a| a }"
37
35
  fails "A lambda expression 'lambda { ... }' assigns variables from parameters for definition \n def m(a) yield a end\n def m2() yield end\n @a = lambda { |a, | a }"
38
36
  fails "A lambda expression 'lambda { ... }' requires a block"
39
37
  fails "A lambda expression 'lambda { ... }' with an implicit block can be created"
40
- fails "A lambda literal -> () { } assigns variables from parameters for definition '@a = -> (a, b) { [a, b] }'"
41
- fails "A lambda literal -> () { } assigns variables from parameters for definition '@a = -> (a={}) { a }'"
42
38
  fails "A lambda literal -> () { } assigns variables from parameters for definition \n @a = -> (a: @a = -> (a: 1) { a }, b:) do\n [a, b]\n end"
43
39
  fails "A lambda literal -> () { } assigns variables from parameters with circular optional argument reference shadows an existing local with the same name as the argument"
44
40
  fails "A lambda literal -> () { } assigns variables from parameters with circular optional argument reference shadows an existing method with the same name as the argument"
@@ -230,7 +226,6 @@ opal_filter "language" do
230
226
  fails "Predefined global $_ is set at the method-scoped level rather than block-scoped"
231
227
  fails "Predefined global $_ is Thread-local"
232
228
  fails "The predefined global constants includes TOPLEVEL_BINDING"
233
- fails "A block yielded a single Array assigns the first element to a single argument with trailing comma"
234
229
  fails "A block yielded a single Array assigns elements to required arguments when a keyword rest argument is present"
235
230
  fails "A block yielded a single Array assigns symbol keys from a Hash to keyword arguments"
236
231
  fails "A block yielded a single Array assigns symbol keys from a Hash returned by #to_hash to keyword arguments"
@@ -242,7 +237,6 @@ opal_filter "language" do
242
237
  fails "A block taking identically-named arguments raises a SyntaxError for standard arguments"
243
238
  fails "Block-local variables can not have the same name as one of the standard parameters"
244
239
  fails "Block-local variables override shadowed variables from the outer scope"
245
- fails "Post-args are required"
246
240
  fails "Post-args with optional args with a circular argument reference shadows an existing method with the same name as the argument"
247
241
  fails "Post-args with optional args with a circular argument reference shadows an existing local with the same name as the argument"
248
242
  fails "The break statement in a captured block when the invocation of the scope creating the block is still active raises a LocalJumpError when invoking the block from the scope creating the block"
@@ -257,19 +251,6 @@ opal_filter "language" do
257
251
  fails "The break statement in a lambda from a scope that has returned raises a LocalJumpError when yielding to a lambda passed as a block argument"
258
252
  fails "Break inside a while loop with a value passes the value returned by a method with omitted parenthesis and passed block"
259
253
  fails "Executing break from within a block returns from the original invoking method even in case of chained calls"
260
- fails "A Proc taking zero arguments raises an ArgumentErro if a value is passed"
261
- fails "A Proc taking || arguments raises an ArgumentError if a value is passed"
262
- fails "A Proc taking |a| arguments raises an ArgumentError if no value is passed"
263
- fails "A Proc taking |a, b| arguments raises an ArgumentError if passed no values"
264
- fails "A Proc taking |a, b| arguments raises an ArgumentError if passed one value"
265
- fails "A Proc taking |a, b| arguments does not call #to_ary to convert a single passed object to an Array"
266
- fails "A Proc taking |a, *b| arguments raises an ArgumentError if passed no values"
267
- fails "A Proc taking |a, | arguments raises an ArgumentError when passed no values"
268
- fails "A Proc taking |a, | arguments raises an ArgumentError when passed more than one value"
269
- fails "A Proc taking |(a, b)| arguments raises an ArgumentError when passed no values"
270
- fails "A Proc taking |(a, b)| arguments calls #to_ary to convert a single passed object to an Array"
271
- fails "A Proc taking |(a, b)| arguments calls #to_ary to convert a single passed object to an Array"
272
- fails "A Proc taking |(a, b)| arguments raises a TypeError if #to_ary does not return an Array"
273
254
  fails "A singleton method definition can be declared for a global variable"
274
255
  fails "A nested method definition creates an instance method when evaluated in an instance method"
275
256
  fails "A nested method definition creates a class method when evaluated in a class method"
@@ -286,4 +267,8 @@ opal_filter "language" do
286
267
  fails "Invoking a method allows []= with a *args and multiple rhs args"
287
268
  fails "Invoking a method does not expand final array arguments after a splat expansion"
288
269
  fails "Invoking a private getter method does not permit self as a receiver"
270
+ fails "The yield call taking no arguments ignores assignment to the explicit block argument and calls the passed block"
271
+ fails "The return keyword invoked with a method call without parentheses with a block returns the value returned from the method call"
272
+ fails "The next statement from within the block passes the value returned by a method with omitted parenthesis and passed block"
273
+ fails "The next statement in a method is invalid and raises a SyntaxError"
289
274
  end
@@ -63,16 +63,10 @@ opal_filter "Module" do
63
63
  fails "Module#autoload when changing $LOAD_PATH does not reload a file due to a different load path"
64
64
  fails "Module#autoload? returns nil if no file has been registered for a constant"
65
65
  fails "Module#autoload? returns the name of the file that will be autoloaded"
66
- fails "Module#class_eval adds methods respecting the lexical constant scope"
67
66
  fails "Module#class_eval converts a non-string filename to a string using to_str"
68
67
  fails "Module#class_eval converts non string eval-string to string using to_str"
69
- fails "Module#class_eval defines constants in the receiver's scope"
70
- fails "Module#class_eval evaluates a given string in the context of self"
71
68
  fails "Module#class_eval raises a TypeError when the given eval-string can't be converted to string using to_str"
72
69
  fails "Module#class_eval raises a TypeError when the given filename can't be converted to string using to_str"
73
- fails "Module#class_eval resolves constants in the caller scope ignoring send"
74
- fails "Module#class_eval resolves constants in the caller scope"
75
- fails "Module#class_eval resolves constants in the receiver's scope"
76
70
  fails "Module#class_eval uses the optional filename and lineno parameters for error messages"
77
71
  fails "Module#class_exec defines method in the receiver's scope"
78
72
  fails "Module#class_variable_defined? converts a non string/symbol/fixnum name to string using to_str"
@@ -95,22 +89,6 @@ opal_filter "Module" do
95
89
  fails "Module#constants returns all constants including inherited when passed true"
96
90
  fails "Module#constants returns an array of Symbol names of all constants defined in the module and all included modules"
97
91
  fails "Module#constants returns only public constants"
98
- fails "Module#define_method does not change the arity check style of the original proc"
99
- fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed one argument"
100
- fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed two arguments"
101
- fails "Module#define_method passed { |a, *b| } creates a method that raises an ArgumentError when passed zero arguments"
102
- fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument and a block"
103
- fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument"
104
- fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed zero arguments"
105
- fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument and a block"
106
- fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument"
107
- fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed three arguments"
108
- fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed zero arguments"
109
- fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed two arguments"
110
- fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments and a block"
111
- fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments"
112
- fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed one argument"
113
- fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed two arguments"
114
92
  fails "Module#define_method raises a TypeError when a Method from a singleton class is defined on another class"
115
93
  fails "Module#define_method raises a TypeError when a Method from one class is defined on an unrelated class"
116
94
  fails "Module#define_method raises a TypeError when an UnboundMethod from a child class is defined on a parent class"
@@ -140,16 +118,10 @@ opal_filter "Module" do
140
118
  fails "Module#const_defined? returns true when passed a scoped constant name for a constant in the inheritance hierarchy and the inherited flag is true"
141
119
  fails "Module#const_defined? returns true or false for the nested name"
142
120
  fails "Module#const_defined? returns true when passed a constant name with EUC-JP characters"
143
- fails "Module#module_eval adds methods respecting the lexical constant scope"
144
121
  fails "Module#module_eval converts a non-string filename to a string using to_str"
145
122
  fails "Module#module_eval converts non string eval-string to string using to_str"
146
- fails "Module#module_eval defines constants in the receiver's scope"
147
- fails "Module#module_eval evaluates a given string in the context of self"
148
123
  fails "Module#module_eval raises a TypeError when the given eval-string can't be converted to string using to_str"
149
124
  fails "Module#module_eval raises a TypeError when the given filename can't be converted to string using to_str"
150
- fails "Module#module_eval resolves constants in the caller scope ignoring send"
151
- fails "Module#module_eval resolves constants in the caller scope"
152
- fails "Module#module_eval resolves constants in the receiver's scope"
153
125
  fails "Module#module_eval uses the optional filename and lineno parameters for error messages"
154
126
  fails "Module#module_exec defines method in the receiver's scope"
155
127
  fails "Module#module_function as a toggle (no arguments) in a Module body does not affect module_evaled method definitions also if outside the eval itself"
@@ -221,6 +193,4 @@ opal_filter "Module" do
221
193
  fails "Module.new creates a new Module and passes it to the provided block"
222
194
  fails "Module::Nesting returns the list of Modules nested at the point of call"
223
195
  fails "Module::Nesting returns the nesting for module/class declaring the called method"
224
- fails "passed { |a, b = 1| } creates a method that raises an ArgumentError when passed three arguments"
225
- fails "passed { |a, b = 1| } creates a method that raises an ArgumentError when passed zero arguments"
226
196
  end
@@ -0,0 +1,5 @@
1
+ opal_filter "Pathname" do
2
+ fails "Pathname#relative_path_from raises an error when the two paths do not share a common prefix"
3
+ fails "Pathname#relative_path_from raises an error when the base directory has .."
4
+ fails "Pathname#relative_path_from returns current and pattern when only those patterns are used"
5
+ end
@@ -1,11 +1,7 @@
1
1
  opal_filter "Proc" do
2
2
  fails "Proc as an implicit block pass argument remains the same object if re-vivified by the target method"
3
- fails "Proc#=== on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on excess arguments when self is a lambda"
4
- fails "Proc#=== on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on missing arguments when self is a lambda"
5
3
  fails "Proc#binding returns a Binding instance"
6
4
  fails "Proc#binding returns the binding associated with self"
7
- fails "Proc#call on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on excess arguments when self is a lambda"
8
- fails "Proc#call on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on missing arguments when self is a lambda"
9
5
  fails "Proc#curry with arity argument returns Procs with arities of -1 regardless of the value of _arity_"
10
6
  fails "Proc#inspect for a proc created with UnboundMethod#to_proc returns a description including '(lambda)' and optionally including file and line number"
11
7
  fails "Proc#inspect for a proc created with lambda returns a description including '(lambda)' and optionally including file and line number"
@@ -19,8 +15,6 @@ opal_filter "Proc" do
19
15
  fails "Proc#source_location works even if the proc was created on the same line"
20
16
  fails "Proc#to_s for a proc created with UnboundMethod#to_proc returns a description including '(lambda)' and optionally including file and line number"
21
17
  fails "Proc#to_s for a proc created with lambda returns a description including '(lambda)' and optionally including file and line number"
22
- fails "Proc#yield on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on excess arguments when self is a lambda"
23
- fails "Proc#yield on a Proc created with Kernel#lambda or Kernel#proc raises an ArgumentError on missing arguments when self is a lambda"
24
18
  fails "Proc.allocate raises a TypeError"
25
19
  fails "Proc.new with a block argument called indirectly from a subclass returns the passed proc created from a block"
26
20
  fails "Proc.new with a block argument called indirectly from a subclass returns the passed proc created from a method"
@@ -3,4 +3,5 @@ opal_filter "Thread" do
3
3
  fails "The throw keyword raises an ArgumentError if used to exit a thread"
4
4
  fails "The throw keyword clears the current exception"
5
5
  fails "Module#autoload loads the registered constant even if the constant was already loaded by another thread"
6
+ fails "The return keyword in a Thread raises a LocalJumpError if used to exit a thread"
6
7
  end
@@ -172,7 +172,7 @@ describe Opal::Compiler do
172
172
  end
173
173
 
174
174
  it 'adds nil check for strings' do
175
- expect_compiled('foo = 42 if "test" > "bar"').to include('if ((($a = $rb_gt("test", "bar")) !== nil && (!$a.$$is_boolean || $a == true)))')
175
+ expect_compiled('foo = 42 if "test" > "bar"').to include('if ((($a = $rb_gt("test", "bar")) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
176
176
  end
177
177
 
178
178
  it 'specifically == excludes nil check for strings' do
@@ -180,7 +180,7 @@ describe Opal::Compiler do
180
180
  end
181
181
 
182
182
  it 'adds nil check for lvars' do
183
- expect_compiled("bar = 4\nfoo = 42 if bar > 5").to include('if ((($a = $rb_gt(bar, 5)) !== nil && (!$a.$$is_boolean || $a == true)))')
183
+ expect_compiled("bar = 4\nfoo = 42 if bar > 5").to include('if ((($a = $rb_gt(bar, 5)) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
184
184
  end
185
185
 
186
186
  it 'specifically == excludes nil check for lvars' do
@@ -188,7 +188,7 @@ describe Opal::Compiler do
188
188
  end
189
189
 
190
190
  it 'adds nil check for constants' do
191
- expect_compiled("foo = 42 if Test > 4").to include("if ((($a = $rb_gt($scope.get('Test'), 4)) !== nil && (!$a.$$is_boolean || $a == true))) ")
191
+ expect_compiled("foo = 42 if Test > 4").to include("if ((($a = $rb_gt($scope.get('Test'), 4)) !== nil && $a != null && (!$a.$$is_boolean || $a == true))) ")
192
192
  end
193
193
 
194
194
  it 'specifically == excludes nil check for constants' do
@@ -198,25 +198,25 @@ describe Opal::Compiler do
198
198
 
199
199
  context 'without operators' do
200
200
  it 'adds nil check for primitives' do
201
- expect_compiled('foo = 42 if 2').to include('if ((($a = 2) !== nil && (!$a.$$is_boolean || $a == true)))')
202
- expect_compiled('foo = 42 if 2.5').to include('if ((($a = 2.5) !== nil && (!$a.$$is_boolean || $a == true)))')
203
- expect_compiled('foo = 42 if true').to include('if ((($a = true) !== nil && (!$a.$$is_boolean || $a == true)))')
201
+ expect_compiled('foo = 42 if 2').to include('if ((($a = 2) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
202
+ expect_compiled('foo = 42 if 2.5').to include('if ((($a = 2.5) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
203
+ expect_compiled('foo = 42 if true').to include('if ((($a = true) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
204
204
  end
205
205
 
206
206
  it 'adds nil check for boolean method calls' do
207
- expect_compiled('foo = 42 if true.something').to include('if ((($a = true.$something()) !== nil && (!$a.$$is_boolean || $a == true)))')
207
+ expect_compiled('foo = 42 if true.something').to include('if ((($a = true.$something()) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
208
208
  end
209
209
 
210
210
  it 'adds nil check for strings' do
211
- expect_compiled('foo = 42 if "test"').to include('if ((($a = "test") !== nil && (!$a.$$is_boolean || $a == true)))')
211
+ expect_compiled('foo = 42 if "test"').to include('if ((($a = "test") !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
212
212
  end
213
213
 
214
214
  it 'adds nil check for lvars' do
215
- expect_compiled("bar = 4\nfoo = 42 if bar").to include('if (bar !== false && bar !== nil)')
215
+ expect_compiled("bar = 4\nfoo = 42 if bar").to include('if (bar !== false && bar !== nil && bar != null)')
216
216
  end
217
217
 
218
218
  it 'adds nil check for constants' do
219
- expect_compiled("foo = 42 if Test").to include("if ((($a = $scope.get('Test')) !== nil && (!$a.$$is_boolean || $a == true)))")
219
+ expect_compiled("foo = 42 if Test").to include("if ((($a = $scope.get('Test')) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
220
220
  end
221
221
  end
222
222
  end
@@ -224,52 +224,52 @@ describe Opal::Compiler do
224
224
  context 'parentheses' do
225
225
  context 'with operators' do
226
226
  it 'adds nil check for primitives' do
227
- expect_compiled('foo = 42 if (2 > 3)').to include('if ((($a = ($rb_gt(2, 3))) !== nil && (!$a.$$is_boolean || $a == true)))')
228
- expect_compiled('foo = 42 if (2.5 > 3.5)').to include('if ((($a = ($rb_gt(2.5, 3.5))) !== nil && (!$a.$$is_boolean || $a == true)))')
229
- expect_compiled('foo = 42 if (true > false)').to include('if ((($a = ($rb_gt(true, false))) !== nil && (!$a.$$is_boolean || $a == true)))')
227
+ expect_compiled('foo = 42 if (2 > 3)').to include('if ((($a = ($rb_gt(2, 3))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
228
+ expect_compiled('foo = 42 if (2.5 > 3.5)').to include('if ((($a = ($rb_gt(2.5, 3.5))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
229
+ expect_compiled('foo = 42 if (true > false)').to include('if ((($a = ($rb_gt(true, false))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
230
230
 
231
- expect_compiled('foo = 42 if (2 == 3)').to include("if ((($a = ((2)['$=='](3))) !== nil && (!$a.$$is_boolean || $a == true)))")
232
- expect_compiled('foo = 42 if (2.5 == 3.5)').to include("if ((($a = ((2.5)['$=='](3.5))) !== nil && (!$a.$$is_boolean || $a == true)))")
233
- expect_compiled('foo = 42 if (true == false)').to include("if ((($a = (true['$=='](false))) !== nil && (!$a.$$is_boolean || $a == true)))")
231
+ expect_compiled('foo = 42 if (2 == 3)').to include("if ((($a = ((2)['$=='](3))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
232
+ expect_compiled('foo = 42 if (2.5 == 3.5)').to include("if ((($a = ((2.5)['$=='](3.5))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
233
+ expect_compiled('foo = 42 if (true == false)').to include("if ((($a = (true['$=='](false))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
234
234
  end
235
235
 
236
236
  it 'adds nil check for strings' do
237
- expect_compiled('foo = 42 if ("test" > "bar")').to include('if ((($a = ($rb_gt("test", "bar"))) !== nil && (!$a.$$is_boolean || $a == true)))')
238
- expect_compiled('foo = 42 if ("test" == "bar")').to include("if ((($a = (\"test\"['$=='](\"bar\"))) !== nil && (!$a.$$is_boolean || $a == true)))")
237
+ expect_compiled('foo = 42 if ("test" > "bar")').to include('if ((($a = ($rb_gt("test", "bar"))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
238
+ expect_compiled('foo = 42 if ("test" == "bar")').to include("if ((($a = (\"test\"['$=='](\"bar\"))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
239
239
  end
240
240
 
241
241
  it 'adds nil check for lvars' do
242
- expect_compiled("bar = 4\nfoo = 42 if (bar > 5)").to include('if ((($a = ($rb_gt(bar, 5))) !== nil && (!$a.$$is_boolean || $a == true)))')
243
- expect_compiled("bar = 4\nfoo = 42 if (bar == 5)").to include("if ((($a = (bar['$=='](5))) !== nil && (!$a.$$is_boolean || $a == true))) ")
242
+ expect_compiled("bar = 4\nfoo = 42 if (bar > 5)").to include('if ((($a = ($rb_gt(bar, 5))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
243
+ expect_compiled("bar = 4\nfoo = 42 if (bar == 5)").to include("if ((($a = (bar['$=='](5))) !== nil && $a != null && (!$a.$$is_boolean || $a == true))) ")
244
244
  end
245
245
 
246
246
  it 'adds nil check for constants' do
247
- expect_compiled("foo = 42 if (Test > 4)").to include("if ((($a = ($rb_gt($scope.get('Test'), 4))) !== nil && (!$a.$$is_boolean || $a == true)))")
248
- expect_compiled("foo = 42 if (Test == 4)").to include("if ((($a = ($scope.get('Test')['$=='](4))) !== nil && (!$a.$$is_boolean || $a == true)))")
247
+ expect_compiled("foo = 42 if (Test > 4)").to include("if ((($a = ($rb_gt($scope.get('Test'), 4))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
248
+ expect_compiled("foo = 42 if (Test == 4)").to include("if ((($a = ($scope.get('Test')['$=='](4))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
249
249
  end
250
250
  end
251
251
 
252
252
  context 'without operators' do
253
253
  it 'adds nil check for primitives' do
254
- expect_compiled('foo = 42 if (2)').to include('if ((($a = (2)) !== nil && (!$a.$$is_boolean || $a == true)))')
255
- expect_compiled('foo = 42 if (2.5)').to include('if ((($a = (2.5)) !== nil && (!$a.$$is_boolean || $a == true)))')
256
- expect_compiled('foo = 42 if (true)').to include('if ((($a = (true)) !== nil && (!$a.$$is_boolean || $a == true)))')
254
+ expect_compiled('foo = 42 if (2)').to include('if ((($a = (2)) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
255
+ expect_compiled('foo = 42 if (2.5)').to include('if ((($a = (2.5)) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
256
+ expect_compiled('foo = 42 if (true)').to include('if ((($a = (true)) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
257
257
  end
258
258
 
259
259
  it 'adds nil check for boolean method calls' do
260
- expect_compiled('foo = 42 if (true.something)').to include('if ((($a = (true.$something())) !== nil && (!$a.$$is_boolean || $a == true)))')
260
+ expect_compiled('foo = 42 if (true.something)').to include('if ((($a = (true.$something())) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
261
261
  end
262
262
 
263
263
  it 'adds nil check for strings' do
264
- expect_compiled('foo = 42 if ("test")').to include('if ((($a = ("test")) !== nil && (!$a.$$is_boolean || $a == true)))')
264
+ expect_compiled('foo = 42 if ("test")').to include('if ((($a = ("test")) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
265
265
  end
266
266
 
267
267
  it 'adds nil check for lvars' do
268
- expect_compiled("bar = 4\nfoo = 42 if (bar)").to include('if ((($a = (bar)) !== nil && (!$a.$$is_boolean || $a == true)))')
268
+ expect_compiled("bar = 4\nfoo = 42 if (bar)").to include('if ((($a = (bar)) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))')
269
269
  end
270
270
 
271
271
  it 'adds nil check for constants' do
272
- expect_compiled("foo = 42 if (Test)").to include("if ((($a = ($scope.get('Test'))) !== nil && (!$a.$$is_boolean || $a == true)))")
272
+ expect_compiled("foo = 42 if (Test)").to include("if ((($a = ($scope.get('Test'))) !== nil && $a != null && (!$a.$$is_boolean || $a == true)))")
273
273
  end
274
274
  end
275
275
  end