Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6639f14a8ad8
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7718535c433f
Choose a head ref
  • 3 commits
  • 26 files changed
  • 1 contributor

Commits on Nov 8, 2013

  1. Verified

    This commit was signed with the committer’s verified signature.
    lukekarrys Luke Karrys
    Copy the full SHA
    07b974d View commit details
  2. Spaces cleanup in Boolean

    meh committed Nov 8, 2013

    Verified

    This commit was signed with the committer’s verified signature.
    lukekarrys Luke Karrys
    Copy the full SHA
    87f498c View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    lukekarrys Luke Karrys
    Copy the full SHA
    7718535 View commit details
19 changes: 0 additions & 19 deletions opal/core/array.rb
Original file line number Diff line number Diff line change
@@ -1227,25 +1227,6 @@ def to_a

alias to_ary to_a

def to_n
%x{
var result = [], obj
for (var i = 0, len = self.length; i < len; i++) {
obj = self[i];
if (#{`obj`.respond_to? :to_n}) {
result.push(#{`obj`.to_n});
}
else {
result.push(obj);
}
}
return result;
}
end

alias to_s inspect

def transpose
8 changes: 2 additions & 6 deletions opal/core/boolean.rb
Original file line number Diff line number Diff line change
@@ -28,14 +28,10 @@ def ==(other)
def to_s
`(self == true) ? 'true' : 'false'`
end

def to_n
`self.valueOf()`
end
end

TrueClass = Boolean
TrueClass = Boolean
FalseClass = Boolean

TRUE = true
TRUE = true
FALSE = false
50 changes: 10 additions & 40 deletions opal/core/hash.rb
Original file line number Diff line number Diff line change
@@ -28,8 +28,9 @@ class Hash
}
}
else {
for (var i = 0, length = arguments.length, key; i < length; i++) {
var key = arguments[i], obj = arguments[++i];
for (var i = 0, length = arguments.length; i < length; i++) {
var key = arguments[i],
obj = arguments[++i];
if (assocs[key] == null) {
keys.push(key);
@@ -50,8 +51,10 @@ class Hash
%x{
var $hash2 = Opal.hash2 = function(keys, map) {
var hash = new Hash._alloc;
hash.keys = keys;
hash.map = map;
hash.map = map;
return hash;
};
}
@@ -65,27 +68,18 @@ def self.[](*objs)
def self.allocate
%x{
var hash = new self._alloc;
hash.map = {};
hash.map = {};
hash.keys = [];
return hash;
}
end

def initialize(defaults = undefined, &block)
%x{
if (defaults != null) {
if (defaults.constructor == Object) {
var map = self.map, keys = self.keys, value;
for (var key in defaults) {
keys.push(key);
value = defaults[key];
map[key] = value != null ? value : nil
}
}
else {
self.none = defaults;
}
self.none = defaults;
}
else if (block !== nil) {
self.proc = block;
@@ -725,30 +719,6 @@ def to_hash
self
end

def to_n
%x{
var result = {},
keys = self.keys,
map = self.map,
bucket,
value;
for (var i = 0, length = keys.length; i < length; i++) {
var key = keys[i],
obj = map[key];
if (#{`obj`.respond_to? :to_n}) {
result[key] = #{`obj`.to_n};
}
else {
result[key] = obj;
}
}
return result;
}
end

alias to_s inspect

alias update merge!
5 changes: 1 addition & 4 deletions opal/core/kernel.rb
Original file line number Diff line number Diff line change
@@ -58,9 +58,6 @@ def Array(object, *args, &block)
if (object == null || object === nil) {
return [];
}
else if (#{native?(object)}) {
return #{Native::Array.new(object, *args, &block).to_a};
}
else if (#{object.respond_to? :to_ary}) {
return #{object.to_ary};
}
@@ -434,7 +431,7 @@ def raise(exception = undefined, string = undefined)
if (exception == null && #$!) {
exception = #$!;
}
else if (typeof(exception) === 'string') {
else if (exception._isString) {
exception = #{RuntimeError.new exception};
}
else if (!#{exception.is_a? Exception}) {
4 changes: 0 additions & 4 deletions opal/core/match_data.rb
Original file line number Diff line number Diff line change
@@ -85,10 +85,6 @@ def to_s
`#@matches[0]`
end

def to_n
@matches
end

def values_at(*indexes)
%x{
var values = [],
310 changes: 0 additions & 310 deletions opal/core/native.rb

This file was deleted.

4 changes: 0 additions & 4 deletions opal/core/nil_class.rb
Original file line number Diff line number Diff line change
@@ -45,10 +45,6 @@ def to_i

alias to_f to_i

def to_n
`null`
end

def to_s
''
end
4 changes: 0 additions & 4 deletions opal/core/numeric.rb
Original file line number Diff line number Diff line change
@@ -384,10 +384,6 @@ def divmod(rhs)
[q, r]
end

def to_n
`self.valueOf()`
end

def upto(finish, &block)
return enum_for :upto, finish unless block

4 changes: 0 additions & 4 deletions opal/core/proc.rb
Original file line number Diff line number Diff line change
@@ -49,8 +49,4 @@ def lambda?
def arity
`self.length`
end

def to_n
self
end
end
4 changes: 0 additions & 4 deletions opal/core/regexp.rb
Original file line number Diff line number Diff line change
@@ -117,8 +117,4 @@ def source
end

alias to_s source

def to_n
`self.valueOf()`
end
end
4 changes: 0 additions & 4 deletions opal/core/string.rb
Original file line number Diff line number Diff line change
@@ -713,10 +713,6 @@ def to_s

alias to_sym intern

def to_n
`#{self}.valueOf()`
end

def tr(from, to)
%x{
if (from.length == 0 || from === to) {
24 changes: 3 additions & 21 deletions opal/core/struct.rb
Original file line number Diff line number Diff line change
@@ -52,17 +52,9 @@ def self.inherited(klass)
include Enumerable

def initialize(*args)
if args.length == 1 && native?(args[0])
object = args[0]

members.each {|name|
instance_variable_set "@#{name}", Native(`#{object}[#{name}]`)
}
else
members.each_with_index {|name, index|
instance_variable_set "@#{name}", args[index]
}
end
members.each_with_index {|name, index|
instance_variable_set "@#{name}", args[index]
}
end

def members
@@ -123,16 +115,6 @@ def to_a

alias values to_a

def to_n
result = `{}`

each_pair {|name, value|
`#{result}[#{name}] = #{value.to_n}`
}

result
end

def inspect
result = "#<struct "

4 changes: 0 additions & 4 deletions opal/core/time.rb
Original file line number Diff line number Diff line change
@@ -508,10 +508,6 @@ def wednesday?
def year
`self.getFullYear()`
end

def to_n
self
end
end

# FIXME: move this to stdlib when the corelib has its own path
1 change: 0 additions & 1 deletion opal/opal.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
require 'core/range'
require 'core/time'
require 'core/struct'
require 'core/native'
require 'core/io'
require 'core/main'

8 changes: 0 additions & 8 deletions spec/corelib/hash/hash_spec.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/corelib/native/ext_spec.rb

This file was deleted.

1 change: 1 addition & 0 deletions spec/opal/compiler/irb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'native'

describe Opal::Compiler do
describe "irb parser option" do
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
describe "Native::Base.alias_native" do
require 'native'

describe "Native.alias_native" do
it "refers to an attribute on @native" do
Class.new {
include Native::Base
include Native

alias_native :a, :a
}.new(`{ a: 2 }`).a.should == 2
end

it "refers to an attribute on @native and calls it if it's a function" do
Class.new {
include Native::Base
include Native

alias_native :a, :a
}.new(`{ a: function() { return 42; } }`).a.should == 42
end

it "defaults old to new" do
Class.new {
include Native::Base
include Native

alias_native :a
}.new(`{ a: 42 }`).a.should == 42
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe "Native#each" do
require 'native'

describe "Native::Object#each" do
it "enumerates on object properties" do
Native(`{ a: 2, b: 3 }`).each {|name, value|
((name == :a && value == 2) || (name == :b && value == 3)).should be_true
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe "Native#[]" do
require 'native'

describe "Native::Object#[]" do
it "should return the same value for bridged classes" do
Native(`2`).should === 2
Native(`"lol"`).should === "lol"
19 changes: 19 additions & 0 deletions spec/stdlib/native/ext_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'native'

describe Hash do
describe '#initialize' do
it "returns a hash with a nil value" do
h = Hash.new(`{a: null}`)
h[:a].should == nil
end
end

describe '#to_n' do
it "should return a js object representing hash" do
Hash.new({:a => 100, :b => 200}.to_n).should == {:a => 100, :b => 200}
end
end
end

describe "Hash#to_n" do
end
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'core/native'
require 'native'

describe "Native::Base#initialize" do
it "works when Native::Base is included in a BasicObject" do
describe "Native#initialize" do
it "works when Native is included in a BasicObject" do
basic_class = Class.new(BasicObject)
basic_object = basic_class.new
lambda { basic_object.native? }.should raise_error(NoMethodError)

basic_class.send :include, Native::Base
basic_class.send :include, Native
lambda { basic_class.new(`{}`) }.should_not raise_error
end

it "detects a non native object" do
object = Object.new
lambda { Native.new(object) }.should raise_error(ArgumentError)
lambda { Native::Object.new(object) }.should raise_error(ArgumentError)
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe "Native#method_missing" do
require 'native'

describe "Native::Object#method_missing" do
it "should return values" do
Native(`{ a: 23 }`).a.should == 23
Native(`{ a: { b: 42 } }`).a.b.should == 42
@@ -44,6 +46,6 @@
end

it "should wrap result" do
Native(`{ a: function() { return {}; } }`).a.class.should == Native
Native(`{ a: function() { return {}; } }`).a.class.should == Native::Object
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe "Native.new" do
require 'native'

describe "Native()" do
it "should return nil for null or undefined" do
Native(`null`).should be_nil
Native(`undefined`).should be_nil
2 changes: 1 addition & 1 deletion stdlib/json.rb
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ def self.from_object(js_object, options = {})
options[:object_class] ||= Hash
options[:array_class] ||= Array

`to_opal(js_object, #{options.to_n})`
`to_opal(js_object, options.map)`
end

def self.generate(obj, options = {})
475 changes: 475 additions & 0 deletions stdlib/native.rb

Large diffs are not rendered by default.