Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0-11-stable'
Browse files Browse the repository at this point in the history
* origin/0-11-stable:
  Move the remaining JS API specs to corelib/runtime
  Move all Opal.exit specs under corelib/runtime
  Let bin/opal load bundler/setup
  Try to coerce Kernel#exit status to int
  Fix Kernel#exit check on numbers
  • Loading branch information
elia committed Nov 4, 2018
2 parents c24627c + a28ddf4 commit ed29a98
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 87 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Whitespace conventions:
- At run-time `LoadError` wasn't being raised even with `Opal.config.missing_require_severity;` set to `'error'`.
- Fixed `Kernel#public_methods` to return instance methods if the argument is set to false.
- Fixed an issue in `String#gsub` that made it start an infinite loop when used recursively. (#1879)
- `Kernel#exit` was using status 0 when a number or a generic object was provided, now accepts numbers and tries to convert objects with `#to_int` (#1898).


<!-- generated-content-beyond-this-comment -->
Expand Down
8 changes: 2 additions & 6 deletions opal/corelib/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,10 @@ def exit(status = true)
end

%x{
if (status == null) {
status = 0
} else if (status.$$is_boolean) {
if (status.$$is_boolean) {
status = status ? 0 : 1;
} else if (status.$$is_number) {
status = status.$to_i();
} else {
status = 0
status = #{Opal.coerce_to(status, Integer, :to_int)}
}
Opal.exit(status);
Expand Down
16 changes: 16 additions & 0 deletions spec/opal/core/runtime/constants_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module RuntimeFixtures
class A
end

class A::B
module C

end
end
end

describe "Constants access via .$$ with dots (regression for #1418)" do
it "allows to acces scopes on `Opal`" do
`Opal.Object.$$.RuntimeFixtures.$$.A.$$.B`.should == RuntimeFixtures::A::B::C

This comment has been minimized.

Copy link
@ggrossetie

ggrossetie Nov 5, 2018

Member

@elia The test is wrong no ? It should read:

`Opal.Object.$$.RuntimeFixtures.$$.A.$$.B.$$C` == RuntimeFixtures::A::B::C

or:

`Opal.Object.$$.RuntimeFixtures.$$.A.$$.B` == RuntimeFixtures::A::B

Right ?

end
end
29 changes: 29 additions & 0 deletions spec/opal/core/runtime/exit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe "Exit (Kernel#exit / Opal.exit())" do
it "forwards the status code to Opal.exit(status)" do
received_status { Kernel.exit }.should == 0

received_status { Kernel.exit(0) }.should == 0
received_status { Kernel.exit(1) }.should == 1
received_status { Kernel.exit(2) }.should == 2
received_status { Kernel.exit(123) }.should == 123

received_status { Kernel.exit(true) }.should == 0
received_status { Kernel.exit(false) }.should == 1

lambda { received_status { Kernel.exit(Object.new) } }.should raise_error(TypeError)
lambda { received_status { Kernel.exit([]) } }.should raise_error(TypeError)
lambda { received_status { Kernel.exit(/123/) } }.should raise_error(TypeError)
end

def received_status
received_status = nil
original_exit = `Opal.exit`
begin
`Opal.exit = function(status) { #{received_status = `status`} }`
yield
ensure
`Opal.exit = #{original_exit}`
end
received_status
end
end
20 changes: 20 additions & 0 deletions spec/opal/core/runtime/loaded_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe 'Opal.loaded' do
before do
%w[foo bar baz].each do |module_name|
`delete Opal.require_table[#{module_name}]`
`Opal.loaded_features.splice(Opal.loaded_features.indexOf(#{module_name}))`
end
end

it 'it works with multiple paths' do
`Opal.loaded(['bar'])`
`(Opal.require_table.foo == null)`.should == true
`(Opal.require_table.bar === true)`.should == true
`(Opal.require_table.baz == null)`.should == true

`Opal.loaded(['foo', 'bar', 'baz'])`
`(Opal.require_table.foo === true)`.should == true
`(Opal.require_table.bar === true)`.should == true
`(Opal.require_table.baz === true)`.should == true
end
end
81 changes: 0 additions & 81 deletions spec/opal/javascript_api_spec.rb

This file was deleted.

0 comments on commit ed29a98

Please sign in to comment.