Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruby specs #2154

Merged
merged 14 commits into from
Jan 2, 2021
Merged
27 changes: 14 additions & 13 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ plugins:
channel: rubocop-0-53

exclude_patterns:
- "benchmark/*"
- "build/*"
- "coverage/*"
- "docs/*"
- "examples/*"
- "tasks/*"
- "spec/*"
- "test/*"
- "vendored-minitest/*"
- "**/node_modules/*"
- stdlib/nodejs/js-yaml-3-6-1.js
- lib/opal/source_map/vlq.rb
- lib/opal/cli_runners/source-map-support.js
- "benchmark/*"
- "build/*"
- "coverage/*"
- "docs/*"
- "examples/*"
- "tasks/*"
- "spec/*"
- "test/*"
- "vendored-minitest/*"
- "**/node_modules/*"
- stdlib/nodejs/js-yaml-3-6-1.js
- lib/opal/source_map/vlq.rb
- lib/opal/cli_runners/source-map-support.js
- lib/opal/cli_runners/source-map-support-browser.js
15 changes: 3 additions & 12 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<!--
Whitespace conventions:
- 4 spaces before ## titles
- 2 spaces before ### titles
- 1 spaces before normal text
-->

### Added

- Basic support for `uplevel:` keyword argument in `Kernel#warn` (#2006)
Expand All @@ -21,8 +14,8 @@ Whitespace conventions:
- Source-map support for Node.js in the default runner (#2045)
- SecureRandom#hex(n) (#2050)
- Added a generic implementation of Kernel#caller and #warn(uplevel:) that works with sourcemaps in Node.js and Chrome (#2065)
- Added support for numblocks `-> { _1 + _2 }.call(3, 4) # => 7` #2149

- Added support for numblocks `-> { _1 + _2 }.call(3, 4) # => 7` (#2149)
- Support `<internal:…>` and `<js:…>` in stacktraces, like MRI we now distinguish internal lines from lib/app lines (#2154)

### Fixed

Expand Down Expand Up @@ -59,7 +52,6 @@ Whitespace conventions:
- Fix ruby 2.7 warnings (#2071)
- Improve the --help descriptions (#2146)


### Changed

- Updated outdated parser version (#2013)
Expand All @@ -71,8 +63,7 @@ Whitespace conventions:
- `Encoding.default_external` is now initialized with `__ENCODING__` (#2072)
- Keep the MersenneTwister implementation private (#2108)
- Change parser to 3.0 (#2148)


- Fix forwarding a rescued error to a global var: `rescue => $gvar` (#2154)

### Deprecated

Expand Down
5 changes: 5 additions & 0 deletions bin/build-browser-source-map-support
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

yarn -s browserify -r ./lib/opal/cli_runners/source-map-support.js -o ./lib/opal/cli_runners/source-map-support-browser.js -s sourceMapSupport ~/C/opal


6,446 changes: 6,445 additions & 1 deletion lib/opal/cli_runners/source-map-support-browser.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion lib/opal/cli_runners/source-map-support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Taken and adapted from the work of Evan Wallace
// IMPORTANT NOTICE:
// Remember to update the browser version whenever this file is changed,
// to do so, `run bin/build-browser-source-map-support`

// The following is taken and adapted from the work of Evan Wallace
// https://github.com/evanw/node-source-map-support v0.5.12

// The MIT License (MIT)
Expand Down Expand Up @@ -307,6 +311,13 @@ function CallSiteToString() {
// an eval string.
fileLocation += "<anonymous>";
}

if (fileLocation.startsWith("corelib/")) {
fileLocation = "<internal:" + fileLocation + ">";
} else if (fileLocation.endsWith(".js")) {
fileLocation = "<js:" + fileLocation + ">";
}

var lineNumber = this.getLineNumber();
if (lineNumber != null) {
fileLocation += ":" + lineNumber;
Expand All @@ -330,6 +341,9 @@ function CallSiteToString() {
}
var methodName = this.getMethodName();
if (functionName) {
if (functionName.startsWith("$")) {
functionName = functionName.slice(1);
}
if (typeName && functionName.indexOf(typeName) != 0) {
line += typeName + ".";
}
Expand Down
2 changes: 2 additions & 0 deletions lib/opal/nodes/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def wrap_with_definition

def source_location
file = @sexp.loc.expression.source_buffer.name
file = "<internal:#{file}>" if file.start_with?("corelib/")
file = "<js:#{file}>" if file.end_with?(".js")
line = @sexp.loc.line
"['#{file}', #{line}]"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/opal/nodes/rescue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def compile
push 'if (Opal.rescue($err, ', expr(klasses), ')) {'
indent do
if lvar
push expr(lvar), '$err;'
push expr(lvar.updated(nil, [*lvar.children, s(:js_tmp, '$err')]))
end

# Need to ensure we clear the current exception out after the rescue block ends
Expand Down
21 changes: 15 additions & 6 deletions opal/corelib/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ def at_exit(&block)
end

def caller(start = 1, length = nil)
start += 1
stack = `(new Error().stack || "").split("\n")`
stack = length ? `stack.slice(start, start + length)` : `stack.slice(start)`
stack.map do |line|
`#{line}.replace(/^ *\w+ +/, '').split(':', 3).slice(0,2).join(':')`
end
%x{
var stack, result

stack = (new Error().stack || "").split("\n")
result = []

// Skip the initial line ("Error:") and Kernel#caller with i=3
for (var i = 3, ii = stack.length; i < ii; i++) {
if (!stack[i].match("runtime.js")) {
result.push(stack[i].replace(/^ *\w+ +/, ''))
if (length && result.length == length) break
}
}
return result
}
end

def class
Expand Down
19 changes: 2 additions & 17 deletions opal/corelib/string/unpack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'base64'
require 'corelib/pack_unpack/format_string_parser'

class String
Expand Down Expand Up @@ -234,23 +235,7 @@ class String

function base64Decode(callback) {
return function(data) {
var string = callback(data);
if (typeof(atob) === 'function') {
// Browser
return atob(string);
} else if (typeof(Buffer) === 'function') {
// Node
if (typeof(Buffer.from) === 'function') {
// Node 5.10+
return Buffer.from(string, 'base64').toString();
} else {
return new Buffer(string, 'base64').toString();
}
} else if (#{defined?(Base64)}) {
return #{Base64.decode64(`string`)};
} else {
#{raise "To use String#unpack('m'), you must first require 'base64'."}
}
return #{Base64.decode64(`callback(data)`)};
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"dependencies": {
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"jshint": "^2.11.0-rc1",
"source-map-support": "^0.5.16",
"uglify-js": "^3.7.2"
Expand Down
10 changes: 9 additions & 1 deletion spec/filters/bugs/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
opal_filter "Array" do
fails "Array#== compares with an equivalent Array-like object using #to_ary" # Expected false to be true
fails "Array#== returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" # Expected [NaN] to equal [NaN]
fails "Array#[] raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
fails "Array#[] raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
fails "Array#[] raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
fails "Array#drop raises a TypeError when the passed argument can't be coerced to Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
fails "Array#drop raises a TypeError when the passed argument isn't an integer and #to_int returns non-Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
fails "Array#drop tries to convert the passed argument to an Integer using #to_int" # Expected [1, 2, 3] == [3] to be truthy but was false
fails "Array#each does not yield elements deleted from the end of the array" # Expected [2, 3, nil] to equal [2, 3]
fails "Array#each yields elements added to the end of the array by the block" # Expected [2] to equal [2, 0, 0]
fails "Array#flatten does not call #to_ary on elements beyond the given level"
Expand All @@ -13,7 +19,9 @@
fails "Array#rassoc calls elem == obj on the second element of each contained array"
fails "Array#rassoc does not check the last element in each contained but specifically the second" # Expected [1, "foobar", #<MockObject:0x4ef6e>] to equal [2, #<MockObject:0x4ef6e>, 1]
fails "Array#select returns a new array of elements for which block is true"
fails "Array#slice raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
fails "Array#slice raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
fails "Array#slice raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
fails "Array#to_s does not call #to_str on the object returned from #to_s when it is not a String" # Exception: Cannot convert object to primitive value
fails "Array#uniq! properly handles recursive arrays"
fails "Array#zip fills nil when the given enumerator is shorter than self" # LocalJumpError: no block given
end
10 changes: 10 additions & 0 deletions spec/filters/bugs/base64.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# NOTE: run bin/format-filters after changing this file
opal_filter "Base64" do
fails "Base64#decode64 returns a binary encoded string" # Expected #<Encoding:UTF-8> == #<Encoding:ASCII-8BIT (dummy)> to be truthy but was false
fails "Base64#decode64 returns the Base64-decoded version of the given string with wrong padding" # Expected "]M\u0095¹\u0090\u0081É\u0095¥¹\u0099½É\u008D\u0095µ\u0095¹ÑÌ" == "]M\u0095¹\u0090\u0081ɕ¥¹\u0099½ɍ\u0095µ\u0095¹ÑÌ" to be truthy but was false
fails "Base64#encode64 returns a US_ASCII encoded string" # Expected #<Encoding:UTF-8> == #<Encoding:ASCII-8BIT (dummy)> to be truthy but was false
fails "Base64#strict_decode64 raises ArgumentError when the given string contains an invalid character" # Expected ArgumentError but no exception was raised ("Ü" was returned)
fails "Base64#strict_decode64 raises ArgumentError when the given string has wrong padding" # Expected ArgumentError but no exception was raised ("\u0001M\u0095¹\u0090\u0081É\u0095¥¹\u0099½É\u008D\u0095µ\u0095¹ÑÌ" was returned)
fails "Base64#strict_decode64 returns a binary encoded string" # Expected #<Encoding:UTF-8> == #<Encoding:ASCII-8BIT (dummy)> to be truthy but was false
fails "Base64#strict_encode64 returns a US_ASCII encoded string" # Expected #<Encoding:UTF-8> == #<Encoding:ASCII-8BIT (dummy)> to be truthy but was false
end
4 changes: 0 additions & 4 deletions spec/filters/bugs/basicobject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
fails "BasicObject#instance_eval evaluates string with given filename and linenumber"
fails "BasicObject#instance_eval evaluates string with given filename and negative linenumber" # Expected ["RuntimeError"] to equal ["b_file", "-98"]
fails "BasicObject#instance_eval has access to the caller's local variables" # Expected nil to equal "value"
fails "BasicObject#instance_eval raises a TypeError when defining methods on an immediate"
fails "BasicObject#instance_eval raises a TypeError when defining methods on numerics"
fails "BasicObject#instance_exec binds the block's binding self to the receiver"
fails "BasicObject#instance_exec raises a LocalJumpError unless given a block"
fails "BasicObject#instance_exec raises a TypeError when defining methods on an immediate"
fails "BasicObject#instance_exec raises a TypeError when defining methods on numerics"
fails "BasicObject#method_missing for an instance sets the receiver of the raised NoMethodError"
end
Loading