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: d33488ef9966^
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 425e4405e652
Choose a head ref
  • 14 commits
  • 18 files changed
  • 1 contributor

Commits on Oct 21, 2014

  1. Copy the full SHA
    d33488e View commit details
  2. Add node mspec runner

    elia committed Oct 21, 2014
    Copy the full SHA
    f02b63d View commit details
  3. Add stubs to stdlib

    elia committed Oct 21, 2014
    Copy the full SHA
    4771f5a View commit details
  4. Copy the full SHA
    541059c View commit details
  5. Copy the full SHA
    47df618 View commit details
  6. Fix some compiler option names

    elia committed Oct 21, 2014
    Copy the full SHA
    e92ae69 View commit details
  7. Copy the full SHA
    9ef166f View commit details
  8. Clean the path of registered modules

    Some paths come with double slashes //
    elia committed Oct 21, 2014
    Copy the full SHA
    95ddd96 View commit details
  9. Copy the full SHA
    906ffb8 View commit details
  10. Copy the full SHA
    8502697 View commit details
  11. Prefer Kernel#node_require to NodeJS.require

    The latter is interpreted as a regular require by
    the compiler.
    elia committed Oct 21, 2014
    Copy the full SHA
    c9e8eb0 View commit details
  12. Copy the full SHA
    4213113 View commit details
  13. Copy the full SHA
    520955c View commit details
  14. Ignore /tmp

    elia committed Oct 21, 2014
    Copy the full SHA
    425e440 View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ build/
/cdn
/node_modules
/gh-pages
/tmp
36 changes: 35 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -18,9 +18,43 @@ MSpec::Opal::RakeTask.new(:mspec) do |config|
config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
end

task :default => [:rspec, :mspec]
task :default => [:rspec, :mspec, :mspec_node]


task :mspec_node do
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty?
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

p [rubyspecs.size, :rubyspecs]
p [filters.size, :filters]
p [shared.size, :shared]

specs = []
specs += filters
specs += rubyspecs
specs += shared

requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}

File.write 'tmp/mspec_node.rb', <<-RUBY
require 'spec_helper'
#{requires.join(" \n")}
OSpecRunner.main.did_finish
RUBY

stubs = " -smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian"

exec 'RUBYOPT="-rbundler/setup -rmspec/opal/special_calls" '\
"bin/opal -Ispec -Ilib -gmspec #{stubs} -rnodejs -Dwarning -A tmp/mspec2.rb"
end

require 'opal/version'
desc <<-DESC
Build *corelib* and *stdlib* to "build/"
37 changes: 7 additions & 30 deletions lib/mspec/opal/rake_task.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
require 'opal/nodes'
class Opal::Nodes::CallNode
# Rubyspec uses this call to load in language specific features at runtime.
# We can't do this at runtime, so handle it during compilation
add_special :language_version do
if meth == :language_version and scope.top?
lang_type = arglist[2][1]
target = "corelib/language/versions/#{lang_type}_1.9"

if File.exist?(target)
compiler.requires << target
end

push fragment("nil")
end
end

add_special :not_supported_on do
unless meth == :not_supported_on and arglist[1][1] == :opal
compile_default!
end
end
end


require 'rack'
require 'webrick'
require 'mspec/opal/special_calls'

module MSpec
module Opal
@@ -205,16 +181,17 @@ def files_to_run(pattern=nil)

if pattern
# add custom opal specs from spec/
add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom_pattern
add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom_pattern
add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom
add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom

else
# add opal specific specs
add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), 'opal/*'
add_files paths_from_glob("#{basedir}/lib/{lexer_spec.rb,parser/**/*_spec.rb}"), 'lib/{lexer,parser}'
add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), :shared
add_files paths_from_glob("#{basedir}/lib/lexer_spec.rb"), :lexer
add_files paths_from_glob("#{basedir}/lib/parser/**/*_spec.rb"), :parser

# add any rubyspecs we want to run (defined in spec/rubyspecs)
add_files rubyspec_white_list, :rubyspec_white_list
add_files rubyspec_white_list, :rubyspecs
end
end

32 changes: 32 additions & 0 deletions lib/mspec/opal/runner.rb
Original file line number Diff line number Diff line change
@@ -144,6 +144,38 @@ def after(state)
end
end

class NodeJSFormatter < BrowserFormatter
def green(str)
`process.stdout.write("\033[32m"+#{str}+"\033[0m")`
end

def red(str)
`process.stdout.write("\033[31m"+#{str}+"\033[0m")`
end

def log(str)
puts str
end

def after(state)
super
unless exception?
green('.')
else
red(failure? ? 'F' : 'E')
end
end

def finish_with_code(code)
`global.OPAL_SPEC_CODE = code;`
end

def finish
super
puts "\n\n"
end
end

class PhantomDebugFormatter < PhantomFormatter
def after(state = nil)
(@exception && state) ? red(state.description) : green(state.description)
25 changes: 25 additions & 0 deletions lib/mspec/opal/special_calls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'opal/nodes'
class Opal::Nodes::CallNode
# Rubyspec uses this call to load in language specific features at runtime.
# We can't do this at runtime, so handle it during compilation
add_special :language_version do
if meth == :language_version and scope.top?
lang_type = arglist[2][1]
target = "corelib/language/versions/#{lang_type}_1.9"

if File.exist?(target)
compiler.requires << target
end

push fragment("nil")
end
end

add_special :not_supported_on do
unless meth == :not_supported_on and arglist[1][1] == :opal
compile_default!
end
end
end


8 changes: 4 additions & 4 deletions lib/opal/cli.rb
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ def initialize options = nil
@filename = options.fetch(:filename) { @file && @file.path }; options.delete(:filename)
@skip_opal_require = options.delete(:skip_opal_require)
@compiler_options = Hash[
*processor_option_names.map do |option|
*compiler_option_names.map do |option|
key = option.to_sym
next unless options.has_key? key
value = options.delete(key)
@@ -129,10 +129,10 @@ def map
compiler.source_map
end

def processor_option_names
def compiler_option_names
%w[
method_missing_enabled
arity_check_enabled
method_missing
arity_check
dynamic_require_severity
source_map_enabled
irb_enabled
2 changes: 1 addition & 1 deletion lib/opal/compiler.rb
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ def error(msg, line = nil)
# method simply appends the filename and curent line number onto
# the message and issues a warning.
def warning(msg, line = nil)
warn "WARNING: #{msg} :#{file}:#{line}"
warn "WARNING: #{msg} -- #{file}:#{line}"
end

# Instances of `Scope` can use this to determine the current
3 changes: 2 additions & 1 deletion lib/opal/nodes/top.rb
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ def compile

def opening
if compiler.requirable?
line "Opal.modules[#{compiler.file.inspect}] = function($opal) {"
path = Pathname(compiler.file).cleanpath.to_s
line "Opal.modules[#{path.inspect}] = function($opal) {"
else
line "(function($opal) {"
end
3 changes: 2 additions & 1 deletion opal/corelib/runtime.js
Original file line number Diff line number Diff line change
@@ -1072,6 +1072,7 @@

for (var i = 0, ii = parts.length; i < ii; i++) {
part = parts[i];
if (part == '') continue;
(part === '..') ? new_parts.pop() : new_parts.push(part)
}

@@ -1094,7 +1095,7 @@
Opal.LoadError ? Opal.LoadError.$new(message) : function(){throw message}();
}
else if (severity === "warning") {
Opal.gvars.stderr.$puts('WARNING: LoadError: ' + message);
console.warn('WARNING: LoadError: ' + message);
}
}

15 changes: 10 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -26,11 +26,16 @@ def at_exit(&block)
end
end

if `!!window.OPAL_SPEC_PHANTOM`
require 'phantomjs'
formatter_class = PhantomFormatter
else
formatter_class = BrowserFormatter
case
when defined?(NodeJS)
formatter_class = NodeJSFormatter
when `(typeof(window) !== 'undefined')`
if `!!window.OPAL_SPEC_PHANTOM`
require 'phantomjs'
formatter_class = PhantomFormatter
else
formatter_class = BrowserFormatter
end
end

# Uncomment the following to see example titles when they're executed.
Empty file added stdlib/fileutils.rb
Empty file.
Empty file added stdlib/iconv.rb
Empty file.
3 changes: 3 additions & 0 deletions stdlib/nodejs.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module NodeJS
end

require 'nodejs/runtime'
require 'nodejs/file'
require 'nodejs/dir'
2 changes: 1 addition & 1 deletion stdlib/nodejs/dir.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Dir
@__glob__ = NodeJS.require :glob
@__glob__ = node_require :glob
`var __glob__ = #{@__glob__}`

def self.[] glob
4 changes: 2 additions & 2 deletions stdlib/nodejs/file.rb
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ class File < IO
include ::IO::Writable
include ::IO::Readable

@__fs__ = NodeJS.require :fs
@__path__ = NodeJS.require :path
@__fs__ = node_require :fs
@__path__ = node_require :path
`var __fs__ = #{@__fs__}`
`var __path__ = #{@__path__}`

2 changes: 1 addition & 1 deletion stdlib/nodejs/io.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$stdout.write_proc = -> (string) {`process.stdout.write(#{string})`}
$stdout.write_proc = -> (string) {`process.stdout.write(string)`}
$stderr.write_proc = -> (string) {`process.stderr.write(string)`}
5 changes: 3 additions & 2 deletions stdlib/nodejs/runtime.rb
Original file line number Diff line number Diff line change
@@ -17,8 +17,9 @@
}).call(this);
}

module NodeJS
def self.require name

module Kernel
def node_require name
`OpalNode.node_require(#{name})`
end
end
1 change: 1 addition & 0 deletions stdlib/yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'nodejs/yaml' if defined? NodeJS