Skip to content
Browse files

Revert "Map nil to native null object."

This reverts commit 896f5f4.
  • Loading branch information...
1 parent 9ba8cd3 commit 82a5d6d2929e774271c5ff3a59cef0e0f916d654 Adam Beynon committed Jun 3, 2012
Showing with 133 additions and 142 deletions.
  1. +26 −26 core/array.rb
  2. +2 −2 core/basic_object.rb
  3. +3 −3 core/boolean.rb
  4. +4 −4 core/class.rb
  5. +28 −28 core/enumerable.rb
  6. +17 −17 core/hash.rb
  7. +4 −4 core/kernel.rb
  8. +7 −7 core/module.rb
  9. +3 −3 core/nil_class.rb
  10. +1 −1 core/proc.rb
  11. +1 −1 core/regexp.rb
  12. +5 −5 core/string.rb
  13. +27 −32 lib/opal/parser.rb
  14. +5 −7 lib/opal/scope.rb
  15. +0 −2 test/core/array/allocate_spec.rb
View
52 core/array.rb
@@ -120,7 +120,7 @@ def [](index, length = undefined)
index = index.begin;
if (index > size) {
- return null;
+ return nil;
}
if (length < 0) {
@@ -141,14 +141,14 @@ def [](index, length = undefined)
if (length !== undefined) {
if (length < 0 || index > size || index < 0) {
- return null;
+ return nil;
}
return this.slice(index, index + length);
}
else {
if (index >= size || index < 0) {
- return null;
+ return nil;
}
return this[index];
@@ -177,7 +177,7 @@ def assoc(object)
}
}
- return null;
+ return nil;
}
end
@@ -188,7 +188,7 @@ def at(index)
}
if (index < 0 || index >= this.length) {
- return null;
+ return nil;
}
return this[index];
@@ -244,7 +244,7 @@ def compact
var result = [];
for (var i = 0, length = this.length, item; i < length; i++) {
- if ((item = this[i]) !== null) {
+ if ((item = this[i]) !== nil) {
result.push(item);
}
}
@@ -258,15 +258,15 @@ def compact!
var original = this.length;
for (var i = 0, length = this.length; i < length; i++) {
- if (this[i] === null) {
+ if (this[i] === nil) {
this.splice(i, 1);
length--;
i--;
}
}
- return this.length === original ? null : this;
+ return this.length === original ? nil : this;
}
end
@@ -311,7 +311,7 @@ def delete(object)
}
}
- return this.length === original ? null : object;
+ return this.length === original ? nil : object;
}
end
@@ -322,7 +322,7 @@ def delete_at(index)
}
if (index < 0 || index >= this.length) {
- return null;
+ return nil;
}
var result = this[index];
@@ -342,7 +342,7 @@ def delete_if(&block)
return __breaker.$v;
}
- if (value !== false && value !== null) {
+ if (value !== false && value !== nil) {
this.splice(i, 1);
length--;
@@ -367,7 +367,7 @@ def drop_while(&block)
return $breaker.$v;
}
- if (value === false || value === null) {
+ if (value === false || value === nil) {
return this.slice(i);
}
}
@@ -429,7 +429,7 @@ def fetch(index, defaults = undefined, &block)
}
if (block !== null) {
- return block.call($context, null, original);
+ return block.call($context, nil, original);
}
throw RubyIndexError.$new('Array#fetch');
@@ -442,7 +442,7 @@ def first(count = undefined)
return this.slice(0, count);
}
- return this.length === 0 ? null : this[0];
+ return this.length === 0 ? nil : this[0];
}
end
@@ -478,7 +478,7 @@ def flatten!(level = undefined)
var size = this.length;
#{replace flatten level};
- return size === this.length ? null : this;
+ return size === this.length ? nil : this;
}
end
@@ -580,7 +580,7 @@ def insert(index, *objects)
}
if (index > this.length) {
for (var i = this.length; i < index; i++) {
- this.push(null);
+ this.push(nil);
}
}
@@ -640,7 +640,7 @@ def last(count = undefined)
var length = this.length;
if (count === undefined) {
- return length === 0 ? null : this[length - 1];
+ return length === 0 ? nil : this[length - 1];
}
else if (count < 0) {
throw RubyArgError.$new('negative count given');
@@ -667,7 +667,7 @@ def pop(count = undefined)
var length = this.length;
if (count === undefined) {
- return length === 0 ? null : this.pop();
+ return length === 0 ? nil : this.pop();
}
if (count < 0) {
@@ -700,7 +700,7 @@ def rassoc(object)
}
}
- return null;
+ return nil;
}
end
@@ -715,7 +715,7 @@ def reject(&block)
return __breaker.$v;
}
- if (value === false || value === null) {
+ if (value === false || value === nil) {
result.push(this[i]);
}
}
@@ -734,15 +734,15 @@ def reject!(&block)
return __breaker.$v;
}
- if (value !== false && value !== null) {
+ if (value !== false && value !== nil) {
this.splice(i, 1);
length--;
i--;
}
}
- return original === this.length ? null : this;
+ return original === this.length ? nil : this;
}
end
@@ -949,7 +949,7 @@ def uniq!
}
}
- return this.length === original ? null : this;
+ return this.length === original ? nil : this;
}
end
@@ -974,7 +974,7 @@ def zip(*others, &block)
o = others[j][i];
if (o === undefined) {
- o = null;
+ o = nil;
}
part[j + 1] = o;
@@ -983,12 +983,12 @@ def zip(*others, &block)
result[i] = part;
}
- if (block !== null) {
+ if (block !== nil) {
for (var i = 0; i < size; i++) {
block.call(__context, result[i]);
}
- return null;
+ return nil;
}
return result;
View
4 core/basic_object.rb
@@ -21,7 +21,7 @@ def __send__(symbol, *args, &block)
def instance_eval(string, &block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
@@ -31,7 +31,7 @@ def instance_eval(string, &block)
def instance_exec(*args, &block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
View
6 core/boolean.rb
@@ -4,15 +4,15 @@ class Boolean < `Boolean`
}
def &(other)
- `(this == true) ? (other !== false && other != null) : false`
+ `(this == true) ? (other !== false && other !== nil) : false`
end
def |(other)
- `(this == true) ? true : (other !== false && other != null)`
+ `(this == true) ? true : (other !== false && other !== nil)`
end
def ^(other)
- `(this == true) ? (other === false || other == null) : (other !== false && other != null)`
+ `(this == true) ? (other === false || other === nil) : (other !== false && other !== nil)`
end
def ==(other)
View
8 core/class.rb
@@ -2,13 +2,13 @@ class Class
def self.new(sup = Object, &block)
%x{
var klass = boot_class(sup);
- klass._name = null;
+ klass._name = nil;
make_metaclass(klass, sup._klass);
sup.$inherited(klass);
- if (block != null) {
+ if (block !== nil) {
block.call(klass);
}
@@ -38,7 +38,7 @@ def superclass
if (!sup) {
if (this === RubyBasicObject) {
- return null;
+ return nil;
}
throw RubyRuntimeError.$new('uninitialized class');
@@ -49,7 +49,7 @@ def superclass
}
if (!sup) {
- return null;
+ return nil;
}
return sup;
View
56 core/enumerable.rb
@@ -3,27 +3,27 @@ def all?(&block)
%x{
var result = true, proc;
- if (block != null) {
+ if (block !== nil) {
proc = function(obj) {
var value;
if ((value = block.call(__context, obj)) === __breaker) {
return __breaker.$v;
}
- if (value === false || value == null) {
+ if (value === false || value === nil) {
result = false;
- __breaker.$v = null;
+ __breaker.$v = nil;
return __breaker;
}
}
}
else {
proc = function(obj) {
- if (obj === false || obj == null) {
+ if (obj === false || obj === nil) {
result = false;
- __breaker.$v = null;
+ __breaker.$v = nil;
return __breaker;
}
@@ -41,27 +41,27 @@ def any?(&block)
%x{
var result = false, proc;
- if (block != null) {
+ if (block !== nil) {
proc = function(obj) {
var value;
if ((value = block.call(__context, obj)) === __breaker) {
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result = true;
- __breaker.$v = null;
+ __breaker.$v = nil;
return __breaker;
}
}
}
else {
proc = function(obj) {
- if (obj !== false && obj != null) {
+ if (obj !== false && obj !== nil) {
result = true;
- __breaker.$v = null;
+ __breaker.$v = nil;
return __breaker;
}
@@ -102,7 +102,7 @@ def count(object = undefined, &block)
%x{
var result = 0;
- if (block == null) {
+ if (block === nil) {
if (object == null) {
block = function() { return true; };
}
@@ -118,7 +118,7 @@ def count(object = undefined, &block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result++;
}
}
@@ -134,7 +134,7 @@ def detect(ifnone = undefined, &block)
return enum_for :detect, ifnone unless block
%x{
- var result = null;
+ var result = nil;
this.$each._p = function(obj) {
var value;
@@ -143,25 +143,25 @@ def detect(ifnone = undefined, &block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result = obj;
- __breaker.$v = null;
+ __breaker.$v = nil;
return __breaker;
}
};
this.$each();
- if (result != null) {
+ if (result !== nil) {
return result;
}
if (typeof(ifnone) === 'function') {
return ifnone.$call();
}
- return ifnone === undefined ? null : ifnone;
+ return ifnone === undefined ? nil : ifnone;
}
end
@@ -197,7 +197,7 @@ def drop_while(&block)
return __breaker;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result.push(obj);
}
else {
@@ -229,7 +229,7 @@ def each_with_index(&block)
this.$each();
- return null;
+ return nil;
}
end
@@ -280,9 +280,9 @@ def find_all(&block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
//result = obj;
- //__breaker.$v = null;
+ //__breaker.$v = nil;
//return __breaker;
result.push(obj);
@@ -297,7 +297,7 @@ def find_all(&block)
def find_index(object = undefined, &block)
%x{
- var proc, result = null, index = 0;
+ var proc, result = nil, index = 0;
if (object != null) {
proc = function (obj) {
@@ -308,7 +308,7 @@ def find_index(object = undefined, &block)
index += 1;
};
}
- else if (block == null) {
+ else if (block === nil) {
return this.$enum_for("find_index");
} else {
proc = function(obj) {
@@ -318,7 +318,7 @@ def find_index(object = undefined, &block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result = index;
__breaker.$v = index;
@@ -343,7 +343,7 @@ def first(number = undefined)
proc;
if (number == null) {
- result = null;
+ result = nil;
proc = function(obj) {
result = obj; return __breaker;
};
@@ -371,11 +371,11 @@ def grep(pattern, &block)
%x{
var result = [];
- this.$each._p = (block != null
+ this.$each._p = (block !== nil
? function(obj) {
var value = pattern.$eqq$(obj);
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
if ((value = block.call(__context, obj)) === __breaker) {
return __breaker.$v;
}
@@ -386,7 +386,7 @@ def grep(pattern, &block)
: function(obj) {
var value = pattern.$eqq$(obj);
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
result.push(obj);
}
});
View
34 core/hash.rb
@@ -10,8 +10,8 @@ class Hash
assocs = {};
hash.map = assocs;
- hash.none = null;
- hash.proc = null;
+ hash.none = nil;
+ hash.proc = nil;
if (args.length == 1 && args[0]._isArray) {
args = args[0];
@@ -52,7 +52,7 @@ def self.new(defaults = undefined, &block)
if (defaults != null) {
hash.none = defaults;
}
- else if (block != null) {
+ else if (block !== nil) {
hash.proc = block;
}
@@ -120,7 +120,7 @@ def assoc(object)
}
}
- return null;
+ return nil;
}
end
@@ -190,7 +190,7 @@ def delete_if(&block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
delete map[assoc];
}
}
@@ -277,7 +277,7 @@ def fetch(key, defaults = undefined, &block)
return bucket[1];
}
- if (block != null) {
+ if (block !== nil) {
var value;
if ((value = block.call(__context, key)) === __breaker) {
@@ -287,7 +287,7 @@ def fetch(key, defaults = undefined, &block)
return value;
}
- if (defaults !== undefined) {
+ if (defaults != null) {
return defaults;
}
@@ -356,7 +356,7 @@ def index(object)
}
}
- return null;
+ return nil;
}
end
@@ -424,7 +424,7 @@ def keep_if(&block)
return $breaker.$v;
}
- if (value === false || value == null) {
+ if (value === false || value === nil) {
delete map[assoc];
}
}
@@ -477,7 +477,7 @@ def merge(other, &block)
map = other.map;
- if (block == null) {
+ if (block === nil) {
for (var assoc in map) {
var bucket = map[assoc];
@@ -505,7 +505,7 @@ def merge!(other, &block)
var map = this.map,
map2 = other.map;
- if (block == null) {
+ if (block === nil) {
for (var assoc in map2) {
var bucket = map2[assoc];
@@ -540,7 +540,7 @@ def rassoc(object)
}
}
- return null;
+ return nil;
}
end
@@ -558,7 +558,7 @@ def reject(&block)
return __breaker.$v;
}
- if (value === false || value == null) {
+ if (value === false || value === nil) {
map2[bucket[0]] = [bucket[0], bucket[1]];
}
}
@@ -595,7 +595,7 @@ def select(&block)
return __breaker.$v;
}
- if (value !== false && value != null) {
+ if (value !== false && value !== nil) {
map2[bucket[0]] = [bucket[0], bucket[1]];
}
}
@@ -608,7 +608,7 @@ def select!(&block)
return enum_for :select! unless block_given?
%x{
- var map = this.map, result = null;
+ var map = this.map, result = nil;
for (var assoc in map) {
var bucket = map[assoc],
@@ -618,7 +618,7 @@ def select!(&block)
return __breaker.$v;
}
- if (value === false || value == null) {
+ if (value === false || value === nil) {
delete map[assoc];
result = this;
}
@@ -638,7 +638,7 @@ def shift
return [bucket[0], bucket[1]];
}
- return null;
+ return nil;
}
end
View
8 core/kernel.rb
@@ -35,7 +35,7 @@ def class
def define_singleton_method(name, &body)
%x{
- if (body == null) {
+ if (body === nil) {
no_block_given();
}
@@ -84,7 +84,7 @@ def instance_variable_get(name)
%x{
var ivar = this[name.substr(1)];
- return ivar == null ? null : ivar;
+ return ivar == null ? nil : ivar;
}
end
@@ -158,7 +158,7 @@ def private(*)
def proc(&block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
@@ -235,7 +235,7 @@ def singleton_class
def tap(&block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
View
14 core/module.rb
@@ -92,7 +92,7 @@ def append_features(klass)
klass._alloc.prototype[get_jsid] = function() {
var res = this[name];
- return res == null ? null : res;
+ return res == null ? nil : res;
};
__donate(klass, [get_jsid]);
@@ -116,7 +116,7 @@ def attr_accessor(*attrs)
define_attr(this, attrs[i], true, true);
}
- return null;
+ return nil;
}
end
@@ -126,7 +126,7 @@ def attr_reader(*attrs)
define_attr(this, attrs[i], true, false);
}
- return null;
+ return nil;
}
end
@@ -136,7 +136,7 @@ def attr_writer(*attrs)
define_attr(this, attrs[i], false, true);
}
- return null;
+ return nil;
}
end
@@ -148,7 +148,7 @@ def attr(name, setter = false)
def define_method(name, &block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
@@ -158,7 +158,7 @@ def define_method(name, &block)
this._alloc.prototype[jsid] = block;
__donate(this, [jsid]);
- return null;
+ return nil;
}
end
@@ -187,7 +187,7 @@ def included(mod)
def module_eval(&block)
%x{
- if (block == null) {
+ if (block === nil) {
no_block_given();
}
View
6 core/nil_class.rb
@@ -4,15 +4,15 @@ def &(other)
end
def |(other)
- `other !== false && other != null`
+ `other !== false && other !== nil`
end
def ^(other)
- `other !== false && other != null`
+ `other !== false && other !== nil`
end
def ==(other)
- `other == null`
+ `other === nil`
end
def inspect
View
2 core/proc.rb
@@ -4,7 +4,7 @@ class Proc < `Function`
}
def self.new(&block)
- `if (block == null) no_block_given();`
+ `if (block === nil) no_block_given();`
block
end
View
2 core/regexp.rb
@@ -29,7 +29,7 @@ def =~(string)
#{$~ = nil};
}
- return result ? result.index : null;
+ return result ? result.index : nil;
}
end
View
10 core/string.rb
@@ -48,7 +48,7 @@ def +(other)
def <=>(other)
%x{
if (typeof other !== 'string') {
- return null;
+ return nil;
}
return this > other ? 1 : (this < other ? -1 : 0);
@@ -97,7 +97,7 @@ def [](index, length = undefined)
}
if (index >= this.length || index < 0) {
- return null;
+ return nil;
}
return this.substr(index, 1);
@@ -108,7 +108,7 @@ def [](index, length = undefined)
}
if (index > this.length || index < 0) {
- return null;
+ return nil;
}
return this.substr(index, length);
@@ -269,7 +269,7 @@ def index(what, offset = undefined)
}
}
- return result === -1 ? null : result;
+ return result === -1 ? nil : result;
}
end
@@ -382,7 +382,7 @@ def sub(pattern, replace = undefined, &block)
if (typeof(replace) === 'string') {
return this.replace(pattern, replace);
}
- if (block != null) {
+ if (block !== nil) {
return this.replace(pattern, function(str) {
//$opal.match_data = arguments
View
59 lib/opal/parser.rb
@@ -101,8 +101,7 @@ def parse(source, file = '(file)')
@file = file
@helpers = {
:breaker => true,
- :slice => true,
- :nil => true
+ :slice => true
}
@grammar = Grammar.new
@@ -154,6 +153,7 @@ def top(sexp, options = {})
vars << "__opal = Opal"
vars << "__scope = __opal"
+ vars << "nil = __opal.nil"
vars.concat @helpers.keys.map { |h| "__#{h} = __opal.#{h}" }
code = "var #{vars.join ', '};\n" + @scope.to_vars + "\n" + code
@@ -290,7 +290,7 @@ def process_scope(sexp, level)
stmt = returns stmt unless @scope.donates_methods
code = process stmt, :stmt
else
- code = "null"
+ code = "nil"
end
code
@@ -324,7 +324,7 @@ def process_operator(sexp, level)
def js_block_given(sexp, level)
@scope.uses_block!
- "(#{@scope.block_name} != null)"
+ "(#{@scope.block_name} !== nil)"
end
# s(:lit, 1)
@@ -399,7 +399,7 @@ def process_defined(sexp, level)
when :call
mid = mid_to_jsid part[2].to_s
recv = part[1] ? process(part[1], :expr) : 'this'
- "(#{recv}.#{mid} ? 'method' : null)"
+ "(#{recv}.#{mid} ? 'method' : nil)"
else
raise "bad defined? part: #{part[0]}"
end
@@ -445,7 +445,7 @@ def process_iter(sexp, level)
args[1..-1].each do |arg|
arg = arg[1]
arg = "#{arg}$" if RESERVED.include? arg.to_s
- # code += "if (#{arg} == null) #{arg} = null;\n"
+ code += "if (#{arg} == null) #{arg} = nil;\n"
end
params = js_block_args(args[1..-1])
@@ -522,7 +522,7 @@ def attr_optimize(meth, attrs)
unless meth == :attr_writer
attr = mid_to_jsid ivar
- check = "this.#{ivar} == null ? null : this.#{ivar}"
+ check = "this.#{ivar} == null ? nil : this.#{ivar}"
out << "def.#{attr} = function() { return #{check}; }"
end
@@ -563,8 +563,6 @@ def process_call(sexp, level)
splat = arglist[1..-1].any? { |a| a.first == :splat }
- tmprecv = @scope.new_temp
-
if Array === arglist.last and arglist.last.first == :block_pass
block = process s(:js_tmp, process(arglist.pop, :expr)), :expr
elsif iter
@@ -573,11 +571,11 @@ def process_call(sexp, level)
recv ||= [:self]
- # if block
-
- # elsif splat or true# and recv != [:self] and recv[0] != :lvar
- # tmprecv = @scope.new_temp
- # end
+ if block
+ tmprecv = @scope.new_temp
+ elsif splat and recv != [:self] and recv[0] != :lvar
+ tmprecv = @scope.new_temp
+ end
recv_code = process recv, :recv
args = ""
@@ -596,7 +594,7 @@ def process_call(sexp, level)
"%s(%s))" % [dispatch, args]
end
else
- dispatch = tmprecv ? "((#{tmprecv} = #{recv_code}) == null ? __nil : #{tmprecv}).#{mid}" : "(#{recv_code} == null ? __nil : #{recv_code}).#{mid}"
+ dispatch = tmprecv ? "(#{tmprecv} = #{recv_code}).#{mid}" : "#{recv_code}.#{mid}"
splat ? "#{dispatch}.apply(#{tmprecv || recv_code}, #{args})" : "#{dispatch}(#{args})"
end
end
@@ -816,7 +814,7 @@ def js_def(recvr, mid, args, stmts, line, end_line)
if @scope.uses_block?
@scope.add_temp '__context'
@scope.add_temp yielder
- blk = "\n#{@indent}#{yielder} = #{scope_name}._p || null;\n#{@indent}__context = (#{yielder} && #{yielder}._s)"
+ blk = "\n#{@indent}#{yielder} = #{scope_name}._p || nil;\n#{@indent}__context = #{yielder}._s"
blk += ";\n#{@indent}#{scope_name}._p = null;\n#{@indent}"
code = blk + code
end
@@ -883,13 +881,10 @@ def process_self(sexp, level)
'this'
end
- def process_nil(sexp, level)
- 'null'
- end
-
# s(:true) # => true
# s(:false) # => false
- %w(true false).each do |name|
+ # s(:nil) # => nil
+ %w(true false nil).each do |name|
define_method "process_#{name}" do |exp, level|
name
end
@@ -965,7 +960,7 @@ def process_while(sexp, level)
@scope.queue_temp redo_var
if stmt_level == :stmt_closure
- code = "(function() {#{code}; return null;}).call(this)"
+ code = "(function() {#{code}; return nil;}).call(this)"
end
code
@@ -1001,7 +996,7 @@ def process_until(exp, level)
@scope.queue_temp redo_var
if stmt_level == :stmt_closure
- code = "(function() {#{code}; return null;}).call(this)"
+ code = "(function() {#{code}; return nil;}).call(this)"
end
code
@@ -1047,7 +1042,7 @@ def process_masgn(sexp, level)
code << process(s, :expr)
else
if idx >= len
- l << s(:js_tmp, "(#{tmp}[#{idx}] == null ? null : #{tmp}[#{idx}])")
+ l << s(:js_tmp, "(#{tmp}[#{idx}] == null ? nil : #{tmp}[#{idx}])")
else
l << s(:js_tmp, "#{tmp}[#{idx}]")
end
@@ -1211,7 +1206,7 @@ def process_if(sexp, level)
indent { code += "\n#@indent} else {\n#@indent#{process falsy, :stmt}" } if falsy
code += "\n#@indent}"
- code = "(function() { #{code}; return null; }).call(this)" if returnable
+ code = "(function() { #{code}; return nil; }).call(this)" if returnable
code
end
@@ -1235,7 +1230,7 @@ def js_truthy(sexp)
tmp = @scope.new_temp
@scope.queue_temp tmp
- "(%s = %s) !== false && %s != null" % [tmp, process(sexp, :expr), tmp]
+ "(%s = %s) !== false && %s !== nil" % [tmp, process(sexp, :expr), tmp]
end
# s(:and, lhs, rhs)
@@ -1253,7 +1248,7 @@ def process_and(sexp, level)
@scope.queue_temp tmp
- "(%s = %s, %s !== false && %s != null ? %s : %s)" %
+ "(%s = %s, %s !== false && %s !== nil ? %s : %s)" %
[tmp, process(lhs, :expr), tmp, tmp, process(rhs, :expr), tmp]
end
@@ -1272,7 +1267,7 @@ def process_or(sexp, level)
@scope.queue_temp tmp
- "(%s = %s, %s !== false && %s != null ? %s : %s)" %
+ "(%s = %s, %s !== false && %s !== nil ? %s : %s)" %
[tmp, process(lhs, :expr), tmp, tmp, tmp, process(rhs, :expr)]
end
@@ -1304,7 +1299,7 @@ def process_yield(sexp, level)
end
def process_break(exp, level)
- val = exp.empty? ? 'null' : process(exp.shift, :expr)
+ val = exp.empty? ? 'nil' : process(exp.shift, :expr)
if in_while?
if @while_loop[:closure]
"return #{val};"
@@ -1339,7 +1334,7 @@ def process_case(exp, level)
end
end
- code << "else {return null}" if returnable and !done_else
+ code << "else {return nil}" if returnable and !done_else
code = "$case = #{expr};#{code.join "\n"}"
code = "(function() { #{code} }).call(this)" if returnable
@@ -1394,7 +1389,7 @@ def process_match3(sexp, level)
def process_cvar(exp, level)
tmp = @scope.new_temp
@scope.queue_temp tmp
- "((%s = Opal.cvars[%s]) == null ? null : %s)" % [tmp, exp.shift.to_s.inspect, tmp]
+ "((%s = Opal.cvars[%s]) == null ? nil : %s)" % [tmp, exp.shift.to_s.inspect, tmp]
end
# @@name = rhs
@@ -1559,7 +1554,7 @@ def process_begin(exp, level)
end
def process_next(exp, level)
- val = exp.empty? ? 'null' : process(exp.shift, :expr)
+ val = exp.empty? ? 'nil' : process(exp.shift, :expr)
if in_while?
"continue;"
else
View
12 lib/opal/scope.rb
@@ -68,18 +68,16 @@ def to_vars
vars << 'def = (this._isObject ? this._klass._proto : this._proto)' if @defines_defn
end
- # locals.each { |l| vars << "#{l} = nil" }
- locals.each { |l| vars << l }
+ locals.each { |l| vars << "#{l} = nil" }
temps.each { |t| vars << t }
- # iv = ivars.map do |ivar|
- # "if (this#{ivar} == null) this#{ivar} = nil;\n"
- # end
+ iv = ivars.map do |ivar|
+ "if (this#{ivar} == null) this#{ivar} = nil;\n"
+ end
indent = @parser.parser_indent
res = vars.empty? ? '' : "var #{vars.join ', '}; "
- res
- # ivars.empty? ? res : "#{res}\n#{indent}#{iv.join indent}"
+ ivars.empty? ? res : "#{res}\n#{indent}#{iv.join indent}"
end
# Generates code for this module to donate methods
View
2 test/core/array/allocate_spec.rb
@@ -1,6 +1,4 @@
describe "Array.allocate" do
- `console.log("in here")`
- `console.log(this)`
it "returns an instance of Array" do
ary = Array.allocate
ary.should be_kind_of(Array)

0 comments on commit 82a5d6d

Please sign in to comment.
Something went wrong with that request. Please try again.