Skip to content

Commit

Permalink
Revert "Map nil to native null object."
Browse files Browse the repository at this point in the history
This reverts commit 896f5f4.
  • Loading branch information
Adam Beynon committed Jun 3, 2012
1 parent 9ba8cd3 commit 82a5d6d
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 142 deletions.
52 changes: 26 additions & 26 deletions core/array.rb
Expand Up @@ -120,7 +120,7 @@ def [](index, length = undefined)
index = index.begin; index = index.begin;
if (index > size) { if (index > size) {
return null; return nil;
} }
if (length < 0) { if (length < 0) {
Expand All @@ -141,14 +141,14 @@ def [](index, length = undefined)
if (length !== undefined) { if (length !== undefined) {
if (length < 0 || index > size || index < 0) { if (length < 0 || index > size || index < 0) {
return null; return nil;
} }
return this.slice(index, index + length); return this.slice(index, index + length);
} }
else { else {
if (index >= size || index < 0) { if (index >= size || index < 0) {
return null; return nil;
} }
return this[index]; return this[index];
Expand Down Expand Up @@ -177,7 +177,7 @@ def assoc(object)
} }
} }
return null; return nil;
} }
end end


Expand All @@ -188,7 +188,7 @@ def at(index)
} }
if (index < 0 || index >= this.length) { if (index < 0 || index >= this.length) {
return null; return nil;
} }
return this[index]; return this[index];
Expand Down Expand Up @@ -244,7 +244,7 @@ def compact
var result = []; var result = [];
for (var i = 0, length = this.length, item; i < length; i++) { for (var i = 0, length = this.length, item; i < length; i++) {
if ((item = this[i]) !== null) { if ((item = this[i]) !== nil) {
result.push(item); result.push(item);
} }
} }
Expand All @@ -258,15 +258,15 @@ def compact!
var original = this.length; var original = this.length;
for (var i = 0, length = this.length; i < length; i++) { for (var i = 0, length = this.length; i < length; i++) {
if (this[i] === null) { if (this[i] === nil) {
this.splice(i, 1); this.splice(i, 1);
length--; length--;
i--; i--;
} }
} }
return this.length === original ? null : this; return this.length === original ? nil : this;
} }
end end


Expand Down Expand Up @@ -311,7 +311,7 @@ def delete(object)
} }
} }
return this.length === original ? null : object; return this.length === original ? nil : object;
} }
end end


Expand All @@ -322,7 +322,7 @@ def delete_at(index)
} }
if (index < 0 || index >= this.length) { if (index < 0 || index >= this.length) {
return null; return nil;
} }
var result = this[index]; var result = this[index];
Expand All @@ -342,7 +342,7 @@ def delete_if(&block)
return __breaker.$v; return __breaker.$v;
} }
if (value !== false && value !== null) { if (value !== false && value !== nil) {
this.splice(i, 1); this.splice(i, 1);
length--; length--;
Expand All @@ -367,7 +367,7 @@ def drop_while(&block)
return $breaker.$v; return $breaker.$v;
} }
if (value === false || value === null) { if (value === false || value === nil) {
return this.slice(i); return this.slice(i);
} }
} }
Expand Down Expand Up @@ -429,7 +429,7 @@ def fetch(index, defaults = undefined, &block)
} }
if (block !== null) { if (block !== null) {
return block.call($context, null, original); return block.call($context, nil, original);
} }
throw RubyIndexError.$new('Array#fetch'); throw RubyIndexError.$new('Array#fetch');
Expand All @@ -442,7 +442,7 @@ def first(count = undefined)
return this.slice(0, count); return this.slice(0, count);
} }
return this.length === 0 ? null : this[0]; return this.length === 0 ? nil : this[0];
} }
end end


Expand Down Expand Up @@ -478,7 +478,7 @@ def flatten!(level = undefined)
var size = this.length; var size = this.length;
#{replace flatten level}; #{replace flatten level};
return size === this.length ? null : this; return size === this.length ? nil : this;
} }
end end


Expand Down Expand Up @@ -580,7 +580,7 @@ def insert(index, *objects)
} }
if (index > this.length) { if (index > this.length) {
for (var i = this.length; i < index; i++) { for (var i = this.length; i < index; i++) {
this.push(null); this.push(nil);
} }
} }
Expand Down Expand Up @@ -640,7 +640,7 @@ def last(count = undefined)
var length = this.length; var length = this.length;
if (count === undefined) { if (count === undefined) {
return length === 0 ? null : this[length - 1]; return length === 0 ? nil : this[length - 1];
} }
else if (count < 0) { else if (count < 0) {
throw RubyArgError.$new('negative count given'); throw RubyArgError.$new('negative count given');
Expand All @@ -667,7 +667,7 @@ def pop(count = undefined)
var length = this.length; var length = this.length;
if (count === undefined) { if (count === undefined) {
return length === 0 ? null : this.pop(); return length === 0 ? nil : this.pop();
} }
if (count < 0) { if (count < 0) {
Expand Down Expand Up @@ -700,7 +700,7 @@ def rassoc(object)
} }
} }
return null; return nil;
} }
end end


Expand All @@ -715,7 +715,7 @@ def reject(&block)
return __breaker.$v; return __breaker.$v;
} }
if (value === false || value === null) { if (value === false || value === nil) {
result.push(this[i]); result.push(this[i]);
} }
} }
Expand All @@ -734,15 +734,15 @@ def reject!(&block)
return __breaker.$v; return __breaker.$v;
} }
if (value !== false && value !== null) { if (value !== false && value !== nil) {
this.splice(i, 1); this.splice(i, 1);
length--; length--;
i--; i--;
} }
} }
return original === this.length ? null : this; return original === this.length ? nil : this;
} }
end end


Expand Down Expand Up @@ -949,7 +949,7 @@ def uniq!
} }
} }
return this.length === original ? null : this; return this.length === original ? nil : this;
} }
end end


Expand All @@ -974,7 +974,7 @@ def zip(*others, &block)
o = others[j][i]; o = others[j][i];
if (o === undefined) { if (o === undefined) {
o = null; o = nil;
} }
part[j + 1] = o; part[j + 1] = o;
Expand All @@ -983,12 +983,12 @@ def zip(*others, &block)
result[i] = part; result[i] = part;
} }
if (block !== null) { if (block !== nil) {
for (var i = 0; i < size; i++) { for (var i = 0; i < size; i++) {
block.call(__context, result[i]); block.call(__context, result[i]);
} }
return null; return nil;
} }
return result; return result;
Expand Down
4 changes: 2 additions & 2 deletions core/basic_object.rb
Expand Up @@ -21,7 +21,7 @@ def __send__(symbol, *args, &block)


def instance_eval(string, &block) def instance_eval(string, &block)
%x{ %x{
if (block == null) { if (block === nil) {
no_block_given(); no_block_given();
} }
Expand All @@ -31,7 +31,7 @@ def instance_eval(string, &block)


def instance_exec(*args, &block) def instance_exec(*args, &block)
%x{ %x{
if (block == null) { if (block === nil) {
no_block_given(); no_block_given();
} }
Expand Down
6 changes: 3 additions & 3 deletions core/boolean.rb
Expand Up @@ -4,15 +4,15 @@ class Boolean < `Boolean`
} }


def &(other) def &(other)
`(this == true) ? (other !== false && other != null) : false` `(this == true) ? (other !== false && other !== nil) : false`
end end


def |(other) def |(other)
`(this == true) ? true : (other !== false && other != null)` `(this == true) ? true : (other !== false && other !== nil)`
end end


def ^(other) def ^(other)
`(this == true) ? (other === false || other == null) : (other !== false && other != null)` `(this == true) ? (other === false || other === nil) : (other !== false && other !== nil)`
end end


def ==(other) def ==(other)
Expand Down
8 changes: 4 additions & 4 deletions core/class.rb
Expand Up @@ -2,13 +2,13 @@ class Class
def self.new(sup = Object, &block) def self.new(sup = Object, &block)
%x{ %x{
var klass = boot_class(sup); var klass = boot_class(sup);
klass._name = null; klass._name = nil;
make_metaclass(klass, sup._klass); make_metaclass(klass, sup._klass);
sup.$inherited(klass); sup.$inherited(klass);
if (block != null) { if (block !== nil) {
block.call(klass); block.call(klass);
} }
Expand Down Expand Up @@ -38,7 +38,7 @@ def superclass
if (!sup) { if (!sup) {
if (this === RubyBasicObject) { if (this === RubyBasicObject) {
return null; return nil;
} }
throw RubyRuntimeError.$new('uninitialized class'); throw RubyRuntimeError.$new('uninitialized class');
Expand All @@ -49,7 +49,7 @@ def superclass
} }
if (!sup) { if (!sup) {
return null; return nil;
} }
return sup; return sup;
Expand Down

0 comments on commit 82a5d6d

Please sign in to comment.