opal 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +8 -11
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +8 -43
- data/Gemfile +15 -4
- data/Guardfile +77 -0
- data/README.md +15 -9
- data/Rakefile +36 -12
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +10 -13
- data/bin/opal-build +4 -4
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +4 -3
- data/examples/sinatra/Gemfile +1 -1
- data/examples/sinatra/config.ru +3 -3
- data/lib/mspec/opal/main.rb.erb +2 -2
- data/lib/mspec/opal/rake_task.rb +31 -24
- data/lib/mspec/opal/runner.rb +18 -1
- data/lib/mspec/opal/sprockets.js +17 -0
- data/lib/opal.rb +1 -34
- data/lib/opal/builder.rb +92 -58
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +85 -144
- data/lib/opal/cli_options.rb +136 -90
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +35 -16
- data/lib/opal/erb.rb +29 -15
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +1 -0
- data/lib/opal/nodes/call.rb +107 -26
- data/lib/opal/nodes/call_special.rb +31 -6
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +5 -20
- data/lib/opal/nodes/def.rb +4 -4
- data/lib/opal/nodes/defined.rb +3 -3
- data/lib/opal/nodes/definitions.rb +1 -1
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/helpers.rb +2 -2
- data/lib/opal/nodes/iter.rb +3 -3
- data/lib/opal/nodes/literal.rb +10 -2
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +1 -0
- data/lib/opal/nodes/singleton_class.rb +2 -2
- data/lib/opal/nodes/super.rb +2 -2
- data/lib/opal/nodes/top.rb +30 -3
- data/lib/opal/parser.rb +15 -1
- data/lib/opal/parser/grammar.rb +2571 -2452
- data/lib/opal/parser/grammar.y +37 -5
- data/lib/opal/parser/keywords.rb +2 -0
- data/lib/opal/parser/lexer.rb +21 -11
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +32 -15
- data/lib/opal/sprockets/environment.rb +9 -2
- data/lib/opal/sprockets/erb.rb +1 -2
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +40 -39
- data/lib/opal/sprockets/server.rb +47 -33
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +10 -5
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +36 -4
- data/opal/corelib/array/inheritance.rb +6 -6
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/boolean.rb +1 -1
- data/opal/corelib/class.rb +12 -12
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +42 -42
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +3 -3
- data/opal/corelib/io.rb +13 -10
- data/opal/corelib/kernel.rb +44 -68
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +89 -114
- data/opal/corelib/nil_class.rb +1 -1
- data/opal/corelib/numeric.rb +27 -23
- data/opal/corelib/proc.rb +5 -5
- data/opal/corelib/range.rb +8 -4
- data/opal/corelib/regexp.rb +5 -5
- data/opal/corelib/runtime.js +589 -272
- data/opal/corelib/string.rb +52 -37
- data/opal/corelib/string/inheritance.rb +5 -5
- data/opal/corelib/time.rb +102 -52
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal.rb +2 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +0 -6
- data/spec/filters/bugs/language.rb +4 -0
- data/spec/filters/bugs/numeric.rb +7 -6
- data/spec/filters/bugs/opal.rb +2 -0
- data/spec/filters/bugs/regexp.rb +4 -0
- data/spec/filters/bugs/string.rb +0 -7
- data/spec/filters/bugs/stringscanner.rb +4 -1
- data/spec/filters/unsupported/private_methods.rb +2 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/{cli → lib}/cli_spec.rb +60 -5
- data/spec/{cli → lib}/compiler_spec.rb +66 -5
- data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/{cli → lib}/lexer_spec.rb +1 -1
- data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
- data/spec/{cli → lib}/parser/and_spec.rb +1 -1
- data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
- data/spec/{cli → lib}/parser/block_spec.rb +1 -1
- data/spec/{cli → lib}/parser/break_spec.rb +1 -1
- data/spec/{cli → lib}/parser/call_spec.rb +1 -1
- data/spec/{cli → lib}/parser/class_spec.rb +1 -1
- data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
- data/spec/{cli → lib}/parser/def_spec.rb +1 -1
- data/spec/{cli → lib}/parser/if_spec.rb +1 -1
- data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
- data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
- data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
- data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/module_spec.rb +1 -1
- data/spec/{cli → lib}/parser/not_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
- data/spec/{cli → lib}/parser/or_spec.rb +1 -1
- data/spec/{cli → lib}/parser/return_spec.rb +1 -1
- data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
- data/spec/{cli → lib}/parser/string_spec.rb +8 -1
- data/spec/{cli → lib}/parser/super_spec.rb +1 -1
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
- data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
- data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
- data/spec/{cli → lib}/parser/while_spec.rb +1 -1
- data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +11 -11
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
- data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
- data/spec/opal/core/source_map_spec.rb +2 -2
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/rubyspecs +54 -11
- data/spec/spec_helper.rb +18 -3
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
- data/stdlib/README.md +3 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/date.rb +2 -2
- data/stdlib/dir.rb +1 -5
- data/stdlib/file.rb +1 -7
- data/stdlib/json.rb +10 -1
- data/stdlib/native.rb +5 -5
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +12 -4
- data/stdlib/set.rb +27 -0
- data/stdlib/source_map.rb +5 -63
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +77 -101
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/strscan.rb +7 -1
- data/stdlib/template.rb +1 -1
- data/stdlib/thread.rb +147 -7
- metadata +238 -104
- data/lib/mspec/opal/mspec_fixes.rb +0 -87
- data/spec/cli/sprockets/environment_spec.rb +0 -14
- data/spec/filters/bugs/symbol.rb +0 -5
- data/spec/opal/core/kernel/warn_spec.rb +0 -83
- data/spec/opal/core/language/numbers_spec.rb +0 -60
- data/stdlib/opal-source-maps.js.erb +0 -2
- data/stdlib/source_map/generator.rb +0 -251
- data/stdlib/source_map/parser.rb +0 -102
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'source_map/offset'
|
2
|
+
|
3
|
+
module SourceMap
|
4
|
+
class Mapping < Struct.new(:source, :generated, :original, :name)
|
5
|
+
# Public: Get a simple string representation of the mapping.
|
6
|
+
#
|
7
|
+
# Returns a String.
|
8
|
+
def to_s
|
9
|
+
str = "#{generated.line}:#{generated.column}"
|
10
|
+
str << "->#{source}@#{original.line}:#{original.column}"
|
11
|
+
str << "##{name}" if name
|
12
|
+
str
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Get a pretty inspect output for debugging purposes.
|
16
|
+
#
|
17
|
+
# Returns a String.
|
18
|
+
def inspect
|
19
|
+
str = "#<#{self.class} source=#{source.inspect}"
|
20
|
+
str << " generated=#{generated}, original=#{original}"
|
21
|
+
str << " name=#{name.inspect}" if name
|
22
|
+
str << ">"
|
23
|
+
str
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module SourceMap
|
2
|
+
# Public: Offset is an immutable structure representing a position in
|
3
|
+
# a source file.
|
4
|
+
class Offset
|
5
|
+
include Comparable
|
6
|
+
|
7
|
+
# Public: Construct Offset value.
|
8
|
+
#
|
9
|
+
# Returns Offset instance.
|
10
|
+
def self.new(*args)
|
11
|
+
case args.first
|
12
|
+
when Offset
|
13
|
+
args.first
|
14
|
+
when Array
|
15
|
+
super(*args.first)
|
16
|
+
else
|
17
|
+
super(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Public: Initialize an Offset.
|
22
|
+
#
|
23
|
+
# line - Integer line number
|
24
|
+
# column - Integer column number
|
25
|
+
def initialize(line, column)
|
26
|
+
@line, @column = line, column
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Gets Integer line of offset
|
30
|
+
attr_reader :line
|
31
|
+
|
32
|
+
# Public: Get Integer column of offset
|
33
|
+
attr_reader :column
|
34
|
+
|
35
|
+
# Public: Shift the offset by some value.
|
36
|
+
#
|
37
|
+
# other - An Offset to add by its line and column
|
38
|
+
# Or an Integer to add by line
|
39
|
+
#
|
40
|
+
# Returns a new Offset instance.
|
41
|
+
def +(other)
|
42
|
+
case other
|
43
|
+
when Offset
|
44
|
+
Offset.new(self.line + other.line, self.column + other.column)
|
45
|
+
when Integer
|
46
|
+
Offset.new(self.line + other, self.column)
|
47
|
+
else
|
48
|
+
raise ArgumentError, "can't convert #{other} into #{self.class}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Compare Offset to another.
|
53
|
+
#
|
54
|
+
# Useful for determining if a position in a few is between two offsets.
|
55
|
+
#
|
56
|
+
# other - Another Offset
|
57
|
+
#
|
58
|
+
# Returns a negative number when other is smaller and a positive number
|
59
|
+
# when its greater. Implements the Comparable#<=> protocol.
|
60
|
+
def <=>(other)
|
61
|
+
case other
|
62
|
+
when Offset
|
63
|
+
diff = self.line - other.line
|
64
|
+
diff.zero? ? self.column - other.column : diff
|
65
|
+
else
|
66
|
+
raise ArgumentError, "can't convert #{other.class} into #{self.class}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Public: Get a simple string representation of the offset
|
71
|
+
#
|
72
|
+
# Returns a String.
|
73
|
+
def to_s
|
74
|
+
if column == 0
|
75
|
+
"#{line}"
|
76
|
+
else
|
77
|
+
"#{line}:#{column}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Public: Get a pretty inspect output for debugging purposes.
|
82
|
+
#
|
83
|
+
# Returns a String.
|
84
|
+
def inspect
|
85
|
+
"#<#{self.class} line=#{line}, column=#{column}>"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/stdlib/source_map/vlq.rb
CHANGED
@@ -1,122 +1,98 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# described in the spec at:
|
1
|
+
module SourceMap
|
2
|
+
# Public: Base64 VLQ encoding
|
4
3
|
#
|
5
|
-
#
|
4
|
+
# Adopted from ConradIrwin/ruby-source_map
|
5
|
+
# https://github.com/ConradIrwin/ruby-source_map/blob/master/lib/source_map/vlq.rb
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
7
|
+
# Resources
|
8
|
+
#
|
9
|
+
# http://en.wikipedia.org/wiki/Variable-length_quantity
|
10
|
+
# https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
|
11
|
+
# https://github.com/mozilla/source-map/blob/master/lib/source-map/base64-vlq.js
|
9
12
|
#
|
10
13
|
module VLQ
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# continuation bit. The continuation bit tells us whether there are more
|
16
|
-
# digits in this value following this digit.
|
17
|
-
#
|
18
|
-
# Continuation
|
19
|
-
# | Sign
|
20
|
-
# | |
|
21
|
-
# V V
|
22
|
-
# 101011
|
23
|
-
|
24
|
-
VLQ_BASE_SHIFT = 5;
|
25
|
-
|
26
|
-
# binary: 100000
|
27
|
-
VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
28
|
-
|
29
|
-
# binary: 011111
|
30
|
-
VLQ_BASE_MASK = VLQ_BASE - 1;
|
31
|
-
|
32
|
-
# binary: 100000
|
33
|
-
VLQ_CONTINUATION_BIT = VLQ_BASE;
|
14
|
+
VLQ_BASE_SHIFT = 5
|
15
|
+
VLQ_BASE = 1 << VLQ_BASE_SHIFT
|
16
|
+
VLQ_BASE_MASK = VLQ_BASE - 1
|
17
|
+
VLQ_CONTINUATION_BIT = VLQ_BASE
|
34
18
|
|
35
19
|
BASE64_DIGITS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('')
|
36
|
-
BASE64_VALUES = (0
|
37
|
-
|
38
|
-
# Returns the base 64 VLQ encoded value.
|
39
|
-
def self.encode(int)
|
20
|
+
BASE64_VALUES = (0...64).inject({}) { |h, i| h[BASE64_DIGITS[i]] = i; h }
|
40
21
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
22
|
+
# Public: Encode a list of numbers into a compact VLQ string.
|
23
|
+
#
|
24
|
+
# ary - An Array of Integers
|
25
|
+
#
|
26
|
+
# Returns a VLQ String.
|
27
|
+
def self.encode(ary)
|
28
|
+
result = []
|
29
|
+
ary.each do |n|
|
30
|
+
vlq = n < 0 ? ((-n) << 1) + 1 : n << 1
|
31
|
+
begin
|
32
|
+
digit = vlq & VLQ_BASE_MASK
|
33
|
+
vlq >>= VLQ_BASE_SHIFT
|
34
|
+
digit |= VLQ_CONTINUATION_BIT if vlq > 0
|
35
|
+
result << BASE64_DIGITS[digit]
|
36
|
+
end while vlq > 0
|
37
|
+
end
|
38
|
+
result.join
|
52
39
|
end
|
53
40
|
|
54
|
-
#
|
55
|
-
#
|
41
|
+
# Public: Decode a VLQ string.
|
42
|
+
#
|
43
|
+
# str - VLQ encoded String
|
44
|
+
#
|
45
|
+
# Returns an Array of Integers.
|
56
46
|
def self.decode(str)
|
57
|
-
|
58
|
-
vlq = 0
|
59
|
-
shift = 0
|
60
|
-
continue = true
|
47
|
+
result = []
|
61
48
|
chars = str.split('')
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# return them.
|
77
|
-
def self.decode_array(str)
|
78
|
-
output = []
|
79
|
-
while str != ''
|
80
|
-
int, str = decode(str)
|
81
|
-
output << int
|
49
|
+
while chars.any?
|
50
|
+
vlq = 0
|
51
|
+
shift = 0
|
52
|
+
continuation = true
|
53
|
+
while continuation
|
54
|
+
char = chars.shift
|
55
|
+
raise ArgumentError unless char
|
56
|
+
digit = BASE64_VALUES[char]
|
57
|
+
continuation = false if (digit & VLQ_CONTINUATION_BIT) == 0
|
58
|
+
digit &= VLQ_BASE_MASK
|
59
|
+
vlq += digit << shift
|
60
|
+
shift += VLQ_BASE_SHIFT
|
61
|
+
end
|
62
|
+
result << (vlq & 1 == 1 ? -(vlq >> 1) : vlq >> 1)
|
82
63
|
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
protected
|
87
|
-
|
88
|
-
def self.base64_encode(int)
|
89
|
-
BASE64_DIGITS[int] or raise ArgumentError, "#{int} is not a valid base64 digit"
|
64
|
+
result
|
90
65
|
end
|
91
66
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
int << 1
|
105
|
-
end
|
67
|
+
# Public: Encode a mapping array into a compact VLQ string.
|
68
|
+
#
|
69
|
+
# ary - Two dimensional Array of Integers.
|
70
|
+
#
|
71
|
+
# Returns a VLQ encoded String seperated by , and ;.
|
72
|
+
def self.encode_mappings(ary)
|
73
|
+
ary.map { |group|
|
74
|
+
group.map { |segment|
|
75
|
+
encode(segment)
|
76
|
+
}.join(',')
|
77
|
+
}.join(';')
|
106
78
|
end
|
107
79
|
|
108
|
-
#
|
109
|
-
#
|
80
|
+
# Public: Decode a VLQ string into mapping numbers.
|
81
|
+
#
|
82
|
+
# str - VLQ encoded String
|
110
83
|
#
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
84
|
+
# Returns an two dimensional Array of Integers.
|
85
|
+
def self.decode_mappings(str)
|
86
|
+
mappings = []
|
87
|
+
|
88
|
+
str.split(';').each_with_index do |group, index|
|
89
|
+
mappings[index] = []
|
90
|
+
group.split(',').each do |segment|
|
91
|
+
mappings[index] << decode(segment)
|
92
|
+
end
|
118
93
|
end
|
119
|
-
end
|
120
94
|
|
95
|
+
mappings
|
96
|
+
end
|
121
97
|
end
|
122
98
|
end
|
data/stdlib/sourcemap.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'source_map'
|
data/stdlib/strscan.rb
CHANGED
@@ -10,6 +10,8 @@ class StringScanner
|
|
10
10
|
@match = []
|
11
11
|
end
|
12
12
|
|
13
|
+
attr_reader :string
|
14
|
+
|
13
15
|
def bol?
|
14
16
|
`#@pos === 0 || #@string.charAt(#@pos - 1) === "\n"`
|
15
17
|
end
|
@@ -24,7 +26,7 @@ class StringScanner
|
|
24
26
|
}
|
25
27
|
else if (typeof(result) === 'object') {
|
26
28
|
#@prev_pos = #@pos;
|
27
|
-
#@pos
|
29
|
+
#@pos += result[0].length;
|
28
30
|
#@working = #@working.substring(result[0].length);
|
29
31
|
#@matched = result[0];
|
30
32
|
#@match = result;
|
@@ -55,6 +57,10 @@ class StringScanner
|
|
55
57
|
return nil;
|
56
58
|
}
|
57
59
|
|
60
|
+
if (match[idx] == null) {
|
61
|
+
return nil;
|
62
|
+
}
|
63
|
+
|
58
64
|
return match[idx];
|
59
65
|
}
|
60
66
|
end
|
data/stdlib/template.rb
CHANGED
data/stdlib/thread.rb
CHANGED
@@ -1,20 +1,160 @@
|
|
1
|
+
# This shim implementation of Thread is meant to only appease code that tries
|
2
|
+
# to be safe in the presence of threads, but does not actually utilize them,
|
3
|
+
# e.g., uses thread- or fiber-local variables.
|
4
|
+
|
5
|
+
class ThreadError < StandardError
|
6
|
+
end
|
7
|
+
|
1
8
|
class Thread
|
2
9
|
def self.current
|
3
|
-
@current
|
10
|
+
unless @current
|
11
|
+
@current = allocate
|
12
|
+
@current.core_initialize!
|
13
|
+
end
|
14
|
+
|
15
|
+
@current
|
4
16
|
end
|
5
17
|
|
6
|
-
def
|
7
|
-
|
18
|
+
def self.list
|
19
|
+
[current]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Do not allow creation of new instances.
|
23
|
+
def initialize(*args)
|
24
|
+
fail NotImplementedError, "Thread creation not available"
|
8
25
|
end
|
9
26
|
|
27
|
+
# fiber-local attribute access.
|
10
28
|
def [](key)
|
11
|
-
@
|
29
|
+
@fiber_locals[coerce_key_name(key)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def []=(key, value)
|
33
|
+
@fiber_locals[coerce_key_name(key)] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def key?(key)
|
37
|
+
@fiber_locals.key?(coerce_key_name(key))
|
38
|
+
end
|
39
|
+
|
40
|
+
def keys
|
41
|
+
@fiber_locals.keys
|
42
|
+
end
|
43
|
+
|
44
|
+
# thread-local attribute access.
|
45
|
+
def thread_variable_get(key)
|
46
|
+
@thread_locals[coerce_key_name(key)]
|
47
|
+
end
|
48
|
+
|
49
|
+
def thread_variable_set(key, value)
|
50
|
+
@thread_locals[coerce_key_name(key)] = value
|
51
|
+
end
|
52
|
+
|
53
|
+
def thread_variable?(key)
|
54
|
+
@thread_locals.key?(coerce_key_name(key))
|
55
|
+
end
|
56
|
+
|
57
|
+
def thread_variables
|
58
|
+
@thread_locals.keys
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def core_initialize!
|
63
|
+
@thread_locals = {}
|
64
|
+
@fiber_locals = {}
|
65
|
+
end
|
66
|
+
|
67
|
+
def coerce_key_name(key)
|
68
|
+
Opal.coerce_to!(key, String, :to_s)
|
12
69
|
end
|
13
70
|
|
14
|
-
|
15
|
-
|
71
|
+
public
|
72
|
+
class Queue
|
73
|
+
def initialize
|
74
|
+
clear
|
75
|
+
end
|
76
|
+
|
77
|
+
def clear
|
78
|
+
@storage = []
|
79
|
+
end
|
80
|
+
|
81
|
+
def empty?
|
82
|
+
@storage.empty?
|
83
|
+
end
|
84
|
+
|
85
|
+
def size
|
86
|
+
@storage.size
|
87
|
+
end
|
88
|
+
|
89
|
+
alias length size
|
90
|
+
|
91
|
+
def pop(non_block = false)
|
92
|
+
if empty?
|
93
|
+
fail ThreadError, "Queue empty" if non_block
|
94
|
+
fail ThreadError, "Deadlock"
|
95
|
+
end
|
96
|
+
|
97
|
+
@storage.shift
|
98
|
+
end
|
99
|
+
|
100
|
+
alias shift pop
|
101
|
+
alias deq pop
|
102
|
+
|
103
|
+
def push(value)
|
104
|
+
@storage.push(value)
|
105
|
+
end
|
106
|
+
|
107
|
+
alias << push
|
108
|
+
alias enq push
|
16
109
|
end
|
110
|
+
|
17
111
|
end
|
18
112
|
|
19
|
-
|
113
|
+
Queue = Thread::Queue
|
114
|
+
|
115
|
+
class Mutex
|
116
|
+
def initialize
|
117
|
+
# We still keep the @locked state so any logic based on try_lock while
|
118
|
+
# held yields reasonable results.
|
119
|
+
@locked = false
|
120
|
+
end
|
121
|
+
|
122
|
+
def lock
|
123
|
+
fail ThreadError, "Deadlock" if @locked
|
124
|
+
@locked = true
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def locked?
|
129
|
+
@locked
|
130
|
+
end
|
131
|
+
|
132
|
+
def owned?
|
133
|
+
# Being the only "thread", we implicitly own any locked mutex.
|
134
|
+
@locked
|
135
|
+
end
|
136
|
+
|
137
|
+
def try_lock
|
138
|
+
if locked?
|
139
|
+
false
|
140
|
+
else
|
141
|
+
lock
|
142
|
+
true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def unlock
|
147
|
+
fail ThreadError, "Mutex not locked" unless @locked
|
148
|
+
@locked = false
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def synchronize
|
153
|
+
lock
|
154
|
+
begin
|
155
|
+
yield
|
156
|
+
ensure
|
157
|
+
unlock
|
158
|
+
end
|
159
|
+
end
|
20
160
|
end
|