opal 1.3.2 → 1.4.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/workflows/build.yml +0 -3
- data/.rubocop.yml +5 -1
- data/UNRELEASED.md +66 -2
- data/benchmark-ips/bm_truthy.rb +30 -0
- data/bin/opal-mspec +1 -3
- data/bin/opal-repl +1 -2
- data/bin/remove-filters +1 -4
- data/docs/compiled_ruby.md +10 -6
- data/exe/opal-repl +1 -3
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +9 -2
- data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
- data/lib/opal/cli_runners/source-map-support-node.js +80 -216
- data/lib/opal/cli_runners/source-map-support.js +5 -1
- data/lib/opal/cli_runners/system_runner.rb +10 -4
- data/lib/opal/compiler.rb +3 -5
- data/lib/opal/fragment.rb +5 -1
- data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
- data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
- data/lib/opal/nodes/args/extract_optarg.rb +1 -3
- data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
- data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
- data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
- data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
- data/lib/opal/nodes/base.rb +3 -2
- data/lib/opal/nodes/call.rb +20 -9
- data/lib/opal/nodes/call_special.rb +50 -0
- data/lib/opal/nodes/class.rb +24 -15
- data/lib/opal/nodes/constants.rb +23 -5
- data/lib/opal/nodes/def.rb +20 -23
- data/lib/opal/nodes/defined.rb +5 -5
- data/lib/opal/nodes/definitions.rb +2 -2
- data/lib/opal/nodes/defs.rb +2 -5
- data/lib/opal/nodes/helpers.rb +48 -18
- data/lib/opal/nodes/if.rb +109 -8
- data/lib/opal/nodes/iter.rb +23 -16
- data/lib/opal/nodes/literal.rb +18 -4
- data/lib/opal/nodes/logic.rb +2 -1
- data/lib/opal/nodes/masgn.rb +4 -9
- data/lib/opal/nodes/module.rb +29 -19
- data/lib/opal/nodes/node_with_args.rb +1 -7
- data/lib/opal/nodes/scope.rb +54 -15
- data/lib/opal/nodes/singleton_class.rb +5 -3
- data/lib/opal/nodes/super.rb +3 -3
- data/lib/opal/nodes/top.rb +34 -31
- data/lib/opal/nodes/variables.rb +2 -2
- data/lib/opal/nodes/x_string.rb +3 -0
- data/lib/opal/nodes.rb +0 -1
- data/lib/opal/parser/patch.rb +75 -0
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/regexp_anchors.rb +7 -7
- data/lib/opal/requires.rb +19 -0
- data/lib/opal/rewriters/pattern_matching.rb +1 -1
- data/lib/opal/rewriters/returnable_logic.rb +102 -4
- data/lib/opal/util.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/lib/opal.rb +1 -17
- data/opal/corelib/array/pack.rb +11 -11
- data/opal/corelib/array.rb +193 -152
- data/opal/corelib/basic_object.rb +14 -14
- data/opal/corelib/binding.rb +7 -7
- data/opal/corelib/boolean.rb +12 -15
- data/opal/corelib/class.rb +23 -1
- data/opal/corelib/comparable.rb +8 -8
- data/opal/corelib/complex/base.rb +2 -2
- data/opal/corelib/complex.rb +79 -88
- data/opal/corelib/constants.rb +9 -9
- data/opal/corelib/dir.rb +4 -3
- data/opal/corelib/enumerable.rb +140 -127
- data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
- data/opal/corelib/enumerator/chain.rb +42 -0
- data/opal/corelib/enumerator/generator.rb +35 -0
- data/opal/corelib/enumerator/lazy.rb +243 -0
- data/opal/corelib/enumerator/yielder.rb +36 -0
- data/opal/corelib/enumerator.rb +45 -300
- data/opal/corelib/error/errno.rb +47 -0
- data/opal/corelib/error.rb +62 -60
- data/opal/corelib/file.rb +26 -12
- data/opal/corelib/hash.rb +98 -107
- data/opal/corelib/helpers.rb +62 -13
- data/opal/corelib/io.rb +47 -34
- data/opal/corelib/kernel/format.rb +29 -29
- data/opal/corelib/kernel.rb +86 -83
- data/opal/corelib/main.rb +14 -12
- data/opal/corelib/marshal/read_buffer.rb +15 -15
- data/opal/corelib/marshal/write_buffer.rb +45 -44
- data/opal/corelib/marshal.rb +3 -3
- data/opal/corelib/math.rb +50 -50
- data/opal/corelib/method.rb +12 -8
- data/opal/corelib/module.rb +96 -79
- data/opal/corelib/nil.rb +9 -11
- data/opal/corelib/number.rb +113 -118
- data/opal/corelib/numeric.rb +37 -33
- data/opal/corelib/object_space.rb +11 -10
- data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
- data/opal/corelib/pattern_matching/base.rb +7 -7
- data/opal/corelib/pattern_matching.rb +1 -1
- data/opal/corelib/proc.rb +15 -16
- data/opal/corelib/process/base.rb +2 -2
- data/opal/corelib/process/status.rb +21 -0
- data/opal/corelib/process.rb +5 -5
- data/opal/corelib/random/formatter.rb +11 -11
- data/opal/corelib/random/math_random.js.rb +1 -1
- data/opal/corelib/random/mersenne_twister.rb +3 -3
- data/opal/corelib/random/seedrandom.js.rb +3 -3
- data/opal/corelib/random.rb +17 -17
- data/opal/corelib/range.rb +51 -35
- data/opal/corelib/rational/base.rb +4 -4
- data/opal/corelib/rational.rb +61 -62
- data/opal/corelib/regexp.rb +47 -38
- data/opal/corelib/runtime.js +245 -139
- data/opal/corelib/string/encoding.rb +21 -21
- data/opal/corelib/string/unpack.rb +19 -14
- data/opal/corelib/string.rb +135 -128
- data/opal/corelib/struct.rb +59 -46
- data/opal/corelib/time.rb +47 -57
- data/opal/corelib/trace_point.rb +2 -2
- data/opal/corelib/unsupported.rb +31 -120
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal/base.rb +9 -8
- data/opal/opal/full.rb +8 -8
- data/opal/opal/mini.rb +17 -17
- data/opal/opal.rb +17 -18
- data/opal.gemspec +1 -1
- data/spec/filters/bugs/array.rb +4 -24
- data/spec/filters/bugs/bigdecimal.rb +0 -23
- data/spec/filters/bugs/binding.rb +0 -1
- data/spec/filters/bugs/boolean.rb +3 -0
- data/spec/filters/bugs/class.rb +2 -0
- data/spec/filters/bugs/date.rb +0 -5
- data/spec/filters/bugs/encoding.rb +8 -50
- data/spec/filters/bugs/enumerable.rb +4 -1
- data/spec/filters/bugs/enumerator.rb +3 -36
- data/spec/filters/bugs/exception.rb +0 -2
- data/spec/filters/bugs/file.rb +0 -2
- data/spec/filters/bugs/float.rb +0 -3
- data/spec/filters/bugs/hash.rb +5 -3
- data/spec/filters/bugs/integer.rb +2 -3
- data/spec/filters/bugs/kernel.rb +2 -31
- data/spec/filters/bugs/language.rb +29 -49
- data/spec/filters/bugs/main.rb +0 -2
- data/spec/filters/bugs/marshal.rb +2 -3
- data/spec/filters/bugs/matrix.rb +0 -36
- data/spec/filters/bugs/module.rb +7 -61
- data/spec/filters/bugs/numeric.rb +0 -7
- data/spec/filters/bugs/objectspace.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +0 -4
- data/spec/filters/bugs/proc.rb +0 -9
- data/spec/filters/bugs/random.rb +0 -5
- data/spec/filters/bugs/range.rb +1 -6
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +8 -1
- data/spec/filters/bugs/string.rb +9 -34
- data/spec/filters/bugs/stringscanner.rb +8 -7
- data/spec/filters/bugs/struct.rb +2 -3
- data/spec/filters/bugs/symbol.rb +0 -1
- data/spec/filters/bugs/time.rb +0 -8
- data/spec/filters/bugs/unboundmethod.rb +0 -8
- data/spec/filters/bugs/warnings.rb +1 -7
- data/spec/filters/unsupported/freeze.rb +24 -0
- data/spec/filters/unsupported/integer.rb +1 -0
- data/spec/filters/unsupported/kernel.rb +12 -0
- data/spec/filters/unsupported/privacy.rb +3 -0
- data/spec/filters/unsupported/string.rb +2 -0
- data/spec/lib/builder_spec.rb +2 -2
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/compiler_spec.rb +37 -37
- data/spec/lib/simple_server_spec.rb +2 -2
- data/spec/lib/source_map/file_spec.rb +1 -1
- data/spec/opal/compiler/irb_spec.rb +2 -2
- data/spec/opal/core/kernel/puts_spec.rb +90 -0
- data/spec/opal/core/language/super_spec.rb +24 -0
- data/spec/ruby_specs +4 -2
- data/spec/support/rewriters_helper.rb +1 -1
- data/stdlib/bigdecimal.rb +7 -11
- data/stdlib/buffer/view.rb +2 -2
- data/stdlib/buffer.rb +2 -2
- data/stdlib/date.rb +5 -6
- data/stdlib/erb.rb +1 -0
- data/stdlib/js.rb +2 -1
- data/stdlib/native.rb +7 -8
- data/stdlib/nodejs/argf.rb +4 -4
- data/stdlib/nodejs/base.rb +29 -0
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/env.rb +6 -9
- data/stdlib/nodejs/file.rb +23 -17
- data/stdlib/nodejs/fileutils.rb +3 -3
- data/stdlib/nodejs/io.rb +2 -20
- data/stdlib/nodejs/irb.rb +0 -0
- data/stdlib/nodejs/kernel.rb +2 -37
- data/stdlib/nodejs.rb +1 -3
- data/stdlib/opal/miniracer.rb +2 -0
- data/stdlib/opal/platform.rb +6 -13
- data/stdlib/opal/replutils.rb +16 -5
- data/stdlib/opal-parser.rb +2 -2
- data/stdlib/optparse/ac.rb +54 -0
- data/stdlib/optparse/date.rb +14 -0
- data/stdlib/optparse/kwargs.rb +22 -0
- data/stdlib/optparse/shellwords.rb +7 -0
- data/stdlib/optparse/time.rb +15 -0
- data/stdlib/optparse/uri.rb +7 -0
- data/stdlib/optparse/version.rb +69 -0
- data/stdlib/optparse.rb +2279 -0
- data/stdlib/pathname.rb +5 -6
- data/stdlib/pp.rb +18 -2
- data/stdlib/promise/v2.rb +18 -22
- data/stdlib/promise.rb +15 -21
- data/stdlib/set.rb +32 -32
- data/stdlib/shellwords.rb +240 -0
- data/stdlib/stringio.rb +3 -6
- data/stdlib/strscan.rb +5 -8
- data/stdlib/template.rb +2 -2
- data/stdlib/thread.rb +7 -9
- data/tasks/performance.rake +5 -2
- data/tasks/testing/mspec_special_calls.rb +0 -12
- data/tasks/testing.rake +55 -37
- data/test/nodejs/test_file.rb +11 -0
- metadata +55 -10
- data/lib/opal/nodes/case.rb +0 -114
data/opal/corelib/struct.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'corelib/enumerable'
|
2
2
|
|
3
|
-
class Struct
|
4
|
-
include Enumerable
|
3
|
+
class ::Struct
|
4
|
+
include ::Enumerable
|
5
5
|
|
6
6
|
def self.new(const_name, *args, keyword_init: false, &block)
|
7
7
|
if const_name
|
8
|
-
if const_name.class == String && const_name[0].upcase != const_name[0]
|
8
|
+
if const_name.class == ::String && const_name[0].upcase != const_name[0]
|
9
9
|
# Fast track so that we skip needlessly going thru exceptions
|
10
10
|
# in most cases.
|
11
11
|
args.unshift(const_name)
|
12
12
|
const_name = nil
|
13
13
|
else
|
14
14
|
begin
|
15
|
-
const_name = Opal.const_name!(const_name)
|
16
|
-
rescue TypeError, NameError
|
15
|
+
const_name = ::Opal.const_name!(const_name)
|
16
|
+
rescue ::TypeError, ::NameError
|
17
17
|
args.unshift(const_name)
|
18
18
|
const_name = nil
|
19
19
|
end
|
@@ -21,10 +21,10 @@ class Struct
|
|
21
21
|
end
|
22
22
|
|
23
23
|
args.map do |arg|
|
24
|
-
Opal.coerce_to!(arg, String, :to_str)
|
24
|
+
::Opal.coerce_to!(arg, ::String, :to_str)
|
25
25
|
end
|
26
26
|
|
27
|
-
klass = Class.new(self) do
|
27
|
+
klass = ::Class.new(self) do
|
28
28
|
args.each { |arg| define_struct_attribute(arg) }
|
29
29
|
|
30
30
|
class << self
|
@@ -43,15 +43,15 @@ class Struct
|
|
43
43
|
`klass.$$keyword_init = keyword_init`
|
44
44
|
|
45
45
|
if const_name
|
46
|
-
Struct.const_set(const_name, klass)
|
46
|
+
::Struct.const_set(const_name, klass)
|
47
47
|
end
|
48
48
|
|
49
49
|
klass
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.define_struct_attribute(name)
|
53
|
-
if self == Struct
|
54
|
-
raise ArgumentError, 'you cannot define attributes to the Struct class'
|
53
|
+
if self == ::Struct
|
54
|
+
::Kernel.raise ::ArgumentError, 'you cannot define attributes to the Struct class'
|
55
55
|
end
|
56
56
|
|
57
57
|
members << name
|
@@ -66,8 +66,8 @@ class Struct
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.members
|
69
|
-
if self == Struct
|
70
|
-
raise ArgumentError, 'the Struct class has no members'
|
69
|
+
if self == ::Struct
|
70
|
+
::Kernel.raise ::ArgumentError, 'the Struct class has no members'
|
71
71
|
end
|
72
72
|
|
73
73
|
@members ||= []
|
@@ -86,12 +86,12 @@ class Struct
|
|
86
86
|
kwargs = args.last || {}
|
87
87
|
|
88
88
|
if args.length > 1 || `(args.length === 1 && !kwargs.$$is_hash)`
|
89
|
-
raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0)"
|
89
|
+
::Kernel.raise ::ArgumentError, "wrong number of arguments (given #{args.length}, expected 0)"
|
90
90
|
end
|
91
91
|
|
92
92
|
extra = kwargs.keys - self.class.members
|
93
93
|
if extra.any?
|
94
|
-
raise ArgumentError, "unknown keywords: #{extra.join(', ')}"
|
94
|
+
::Kernel.raise ::ArgumentError, "unknown keywords: #{extra.join(', ')}"
|
95
95
|
end
|
96
96
|
|
97
97
|
self.class.members.each do |name|
|
@@ -99,7 +99,7 @@ class Struct
|
|
99
99
|
end
|
100
100
|
else
|
101
101
|
if args.length > self.class.members.length
|
102
|
-
raise ArgumentError, 'struct size differs'
|
102
|
+
::Kernel.raise ::ArgumentError, 'struct size differs'
|
103
103
|
end
|
104
104
|
|
105
105
|
self.class.members.each_with_index do |name, index|
|
@@ -119,6 +119,10 @@ class Struct
|
|
119
119
|
}
|
120
120
|
end
|
121
121
|
|
122
|
+
def self.keyword_init?
|
123
|
+
`self.$$keyword_init`
|
124
|
+
end
|
125
|
+
|
122
126
|
def members
|
123
127
|
self.class.members
|
124
128
|
end
|
@@ -128,38 +132,38 @@ class Struct
|
|
128
132
|
end
|
129
133
|
|
130
134
|
def [](name)
|
131
|
-
if Integer === name
|
132
|
-
raise IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
133
|
-
raise IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
135
|
+
if ::Integer === name
|
136
|
+
::Kernel.raise ::IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
137
|
+
::Kernel.raise ::IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
134
138
|
|
135
139
|
name = self.class.members[name]
|
136
|
-
elsif String === name
|
140
|
+
elsif ::String === name
|
137
141
|
%x{
|
138
142
|
if(!self.$$data.hasOwnProperty(name)) {
|
139
|
-
#{raise NameError.new("no member '#{name}' in struct", name)}
|
143
|
+
#{::Kernel.raise ::NameError.new("no member '#{name}' in struct", name)}
|
140
144
|
}
|
141
145
|
}
|
142
146
|
else
|
143
|
-
raise TypeError, "no implicit conversion of #{name.class} into Integer"
|
147
|
+
::Kernel.raise ::TypeError, "no implicit conversion of #{name.class} into Integer"
|
144
148
|
end
|
145
149
|
|
146
|
-
name = Opal.coerce_to!(name, String, :to_str)
|
150
|
+
name = ::Opal.coerce_to!(name, ::String, :to_str)
|
147
151
|
`self.$$data[name]`
|
148
152
|
end
|
149
153
|
|
150
154
|
def []=(name, value)
|
151
|
-
if Integer === name
|
152
|
-
raise IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
153
|
-
raise IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
155
|
+
if ::Integer === name
|
156
|
+
::Kernel.raise ::IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
157
|
+
::Kernel.raise ::IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
154
158
|
|
155
159
|
name = self.class.members[name]
|
156
|
-
elsif String === name
|
157
|
-
raise NameError.new("no member '#{name}' in struct", name) unless self.class.members.include?(name.to_sym)
|
160
|
+
elsif ::String === name
|
161
|
+
::Kernel.raise ::NameError.new("no member '#{name}' in struct", name) unless self.class.members.include?(name.to_sym)
|
158
162
|
else
|
159
|
-
raise TypeError, "no implicit conversion of #{name.class} into Integer"
|
163
|
+
::Kernel.raise ::TypeError, "no implicit conversion of #{name.class} into Integer"
|
160
164
|
end
|
161
165
|
|
162
|
-
name = Opal.coerce_to!(name, String, :to_str)
|
166
|
+
name = ::Opal.coerce_to!(name, ::String, :to_str)
|
163
167
|
`self.$$data[name] = value`
|
164
168
|
end
|
165
169
|
|
@@ -179,7 +183,7 @@ class Struct
|
|
179
183
|
a = struct.$$data[key];
|
180
184
|
b = other.$$data[key];
|
181
185
|
|
182
|
-
if (#{Struct === `a`}) {
|
186
|
+
if (#{::Struct === `a`}) {
|
183
187
|
if (!recursed1.hasOwnProperty(#{`a`.__id__}) || !recursed2.hasOwnProperty(#{`b`.__id__})) {
|
184
188
|
if (!_eqeq(a, b)) {
|
185
189
|
return false;
|
@@ -215,7 +219,7 @@ class Struct
|
|
215
219
|
a = struct.$$data[key];
|
216
220
|
b = other.$$data[key];
|
217
221
|
|
218
|
-
if (#{Struct === `a`}) {
|
222
|
+
if (#{::Struct === `a`}) {
|
219
223
|
if (!recursed1.hasOwnProperty(#{`a`.__id__}) || !recursed2.hasOwnProperty(#{`b`.__id__})) {
|
220
224
|
if (!_eqeq(a, b)) {
|
221
225
|
return false;
|
@@ -253,32 +257,37 @@ class Struct
|
|
253
257
|
self.class.members.length
|
254
258
|
end
|
255
259
|
|
256
|
-
alias size length
|
257
|
-
|
258
260
|
def to_a
|
259
261
|
self.class.members.map { |name| self[name] }
|
260
262
|
end
|
261
263
|
|
262
|
-
|
264
|
+
`var inspect_stack = []`
|
263
265
|
|
264
266
|
def inspect
|
265
267
|
result = '#<struct '
|
266
268
|
|
267
|
-
if
|
268
|
-
result
|
269
|
-
|
269
|
+
if `inspect_stack`.include? __id__
|
270
|
+
result + ':...>'
|
271
|
+
else
|
272
|
+
`inspect_stack` << __id__
|
273
|
+
pushed = true
|
274
|
+
|
275
|
+
if ::Struct === self && self.class.name
|
276
|
+
result += "#{self.class} "
|
277
|
+
end
|
270
278
|
|
271
|
-
|
272
|
-
|
273
|
-
|
279
|
+
result += each_pair.map do |name, value|
|
280
|
+
"#{name}=#{Opal.inspect(value)}"
|
281
|
+
end.join ', '
|
274
282
|
|
275
|
-
|
283
|
+
result += '>'
|
276
284
|
|
277
|
-
|
285
|
+
result
|
286
|
+
end
|
287
|
+
ensure
|
288
|
+
`inspect_stack.pop()` if pushed
|
278
289
|
end
|
279
290
|
|
280
|
-
alias to_s inspect
|
281
|
-
|
282
291
|
def to_h(&block)
|
283
292
|
return map(&block).to_h(*args) if block_given?
|
284
293
|
|
@@ -291,7 +300,7 @@ class Struct
|
|
291
300
|
var result = [];
|
292
301
|
for (var i = 0, len = args.length; i < len; i++) {
|
293
302
|
if (!args[i].$$is_number) {
|
294
|
-
#{raise TypeError, "no implicit conversion of #{`args[i]`.class} into Integer"}
|
303
|
+
#{::Kernel.raise ::TypeError, "no implicit conversion of #{`args[i]`.class} into Integer"}
|
295
304
|
}
|
296
305
|
result.push(#{self[`args[i]`]});
|
297
306
|
}
|
@@ -311,9 +320,13 @@ class Struct
|
|
311
320
|
}
|
312
321
|
|
313
322
|
unless item.respond_to?(:dig)
|
314
|
-
raise TypeError, "#{item.class} does not have #dig method"
|
323
|
+
::Kernel.raise ::TypeError, "#{item.class} does not have #dig method"
|
315
324
|
end
|
316
325
|
|
317
326
|
item.dig(*keys)
|
318
327
|
end
|
328
|
+
|
329
|
+
alias size length
|
330
|
+
alias to_s inspect
|
331
|
+
alias values to_a
|
319
332
|
end
|
data/opal/corelib/time.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'corelib/comparable'
|
4
4
|
|
5
|
-
class Time < `Date`
|
6
|
-
include Comparable
|
5
|
+
class ::Time < `Date`
|
6
|
+
include ::Comparable
|
7
7
|
|
8
8
|
%x{
|
9
9
|
var days_of_week = #{%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday]},
|
@@ -16,9 +16,9 @@ class Time < `Date`
|
|
16
16
|
%x{
|
17
17
|
var result;
|
18
18
|
|
19
|
-
if (#{Time === seconds}) {
|
19
|
+
if (#{::Time === seconds}) {
|
20
20
|
if (frac !== undefined) {
|
21
|
-
#{raise TypeError, "can't convert Time into an exact number"}
|
21
|
+
#{::Kernel.raise ::TypeError, "can't convert Time into an exact number"}
|
22
22
|
}
|
23
23
|
result = new Date(seconds.getTime());
|
24
24
|
result.is_utc = seconds.is_utc;
|
@@ -26,7 +26,7 @@ class Time < `Date`
|
|
26
26
|
}
|
27
27
|
|
28
28
|
if (!seconds.$$is_number) {
|
29
|
-
seconds = #{Opal.coerce_to!(seconds, Integer, :to_int)};
|
29
|
+
seconds = #{::Opal.coerce_to!(seconds, ::Integer, :to_int)};
|
30
30
|
}
|
31
31
|
|
32
32
|
if (frac === undefined) {
|
@@ -34,7 +34,7 @@ class Time < `Date`
|
|
34
34
|
}
|
35
35
|
|
36
36
|
if (!frac.$$is_number) {
|
37
|
-
frac = #{Opal.coerce_to!(frac, Integer, :to_int)};
|
37
|
+
frac = #{::Opal.coerce_to!(frac, ::Integer, :to_int)};
|
38
38
|
}
|
39
39
|
|
40
40
|
return new Date(seconds * 1000 + (frac / 1000));
|
@@ -46,7 +46,7 @@ class Time < `Date`
|
|
46
46
|
if (year.$$is_string) {
|
47
47
|
year = parseInt(year, 10);
|
48
48
|
} else {
|
49
|
-
year = #{Opal.coerce_to!(`year`, Integer, :to_int)};
|
49
|
+
year = #{::Opal.coerce_to!(`year`, ::Integer, :to_int)};
|
50
50
|
}
|
51
51
|
|
52
52
|
if (month === nil) {
|
@@ -70,12 +70,12 @@ class Time < `Date`
|
|
70
70
|
default: month = #{`month`.to_i};
|
71
71
|
}
|
72
72
|
} else {
|
73
|
-
month = #{Opal.coerce_to!(`month`, Integer, :to_int)};
|
73
|
+
month = #{::Opal.coerce_to!(`month`, ::Integer, :to_int)};
|
74
74
|
}
|
75
75
|
}
|
76
76
|
|
77
77
|
if (month < 1 || month > 12) {
|
78
|
-
#{raise ArgumentError, "month out of range: #{`month`}"}
|
78
|
+
#{::Kernel.raise ::ArgumentError, "month out of range: #{`month`}"}
|
79
79
|
}
|
80
80
|
month = month - 1;
|
81
81
|
|
@@ -84,11 +84,11 @@ class Time < `Date`
|
|
84
84
|
} else if (day.$$is_string) {
|
85
85
|
day = parseInt(day, 10);
|
86
86
|
} else {
|
87
|
-
day = #{Opal.coerce_to!(`day`, Integer, :to_int)};
|
87
|
+
day = #{::Opal.coerce_to!(`day`, ::Integer, :to_int)};
|
88
88
|
}
|
89
89
|
|
90
90
|
if (day < 1 || day > 31) {
|
91
|
-
#{raise ArgumentError, "day out of range: #{`day`}"}
|
91
|
+
#{::Kernel.raise ::ArgumentError, "day out of range: #{`day`}"}
|
92
92
|
}
|
93
93
|
|
94
94
|
if (hour === nil) {
|
@@ -96,11 +96,11 @@ class Time < `Date`
|
|
96
96
|
} else if (hour.$$is_string) {
|
97
97
|
hour = parseInt(hour, 10);
|
98
98
|
} else {
|
99
|
-
hour = #{Opal.coerce_to!(`hour`, Integer, :to_int)};
|
99
|
+
hour = #{::Opal.coerce_to!(`hour`, ::Integer, :to_int)};
|
100
100
|
}
|
101
101
|
|
102
102
|
if (hour < 0 || hour > 24) {
|
103
|
-
#{raise ArgumentError, "hour out of range: #{`hour`}"}
|
103
|
+
#{::Kernel.raise ::ArgumentError, "hour out of range: #{`hour`}"}
|
104
104
|
}
|
105
105
|
|
106
106
|
if (min === nil) {
|
@@ -108,11 +108,11 @@ class Time < `Date`
|
|
108
108
|
} else if (min.$$is_string) {
|
109
109
|
min = parseInt(min, 10);
|
110
110
|
} else {
|
111
|
-
min = #{Opal.coerce_to!(`min`, Integer, :to_int)};
|
111
|
+
min = #{::Opal.coerce_to!(`min`, ::Integer, :to_int)};
|
112
112
|
}
|
113
113
|
|
114
114
|
if (min < 0 || min > 59) {
|
115
|
-
#{raise ArgumentError, "min out of range: #{`min`}"}
|
115
|
+
#{::Kernel.raise ::ArgumentError, "min out of range: #{`min`}"}
|
116
116
|
}
|
117
117
|
|
118
118
|
if (sec === nil) {
|
@@ -121,12 +121,12 @@ class Time < `Date`
|
|
121
121
|
if (sec.$$is_string) {
|
122
122
|
sec = parseInt(sec, 10);
|
123
123
|
} else {
|
124
|
-
sec = #{Opal.coerce_to!(`sec`, Integer, :to_int)};
|
124
|
+
sec = #{::Opal.coerce_to!(`sec`, ::Integer, :to_int)};
|
125
125
|
}
|
126
126
|
}
|
127
127
|
|
128
128
|
if (sec < 0 || sec > 60) {
|
129
|
-
#{raise ArgumentError, "sec out of range: #{`sec`}"}
|
129
|
+
#{::Kernel.raise ::ArgumentError, "sec out of range: #{`sec`}"}
|
130
130
|
}
|
131
131
|
|
132
132
|
return [year, month, day, hour, min, sec];
|
@@ -142,7 +142,7 @@ class Time < `Date`
|
|
142
142
|
}
|
143
143
|
|
144
144
|
if (utc_offset !== nil) {
|
145
|
-
#{raise ArgumentError, 'Opal does not support explicitly specifying UTC offset for Time'}
|
145
|
+
#{::Kernel.raise ::ArgumentError, 'Opal does not support explicitly specifying UTC offset for Time'}
|
146
146
|
}
|
147
147
|
|
148
148
|
args = time_params(year, month, day, hour, min, sec);
|
@@ -224,23 +224,18 @@ class Time < `Date`
|
|
224
224
|
}
|
225
225
|
end
|
226
226
|
|
227
|
-
class << self
|
228
|
-
alias mktime local
|
229
|
-
alias utc gm
|
230
|
-
end
|
231
|
-
|
232
227
|
def self.now
|
233
228
|
new
|
234
229
|
end
|
235
230
|
|
236
231
|
def +(other)
|
237
|
-
if Time === other
|
238
|
-
raise TypeError, 'time + time?'
|
232
|
+
if ::Time === other
|
233
|
+
::Kernel.raise ::TypeError, 'time + time?'
|
239
234
|
end
|
240
235
|
|
241
236
|
%x{
|
242
237
|
if (!other.$$is_number) {
|
243
|
-
other = #{Opal.coerce_to!(other, Integer, :to_int)};
|
238
|
+
other = #{::Opal.coerce_to!(other, ::Integer, :to_int)};
|
244
239
|
}
|
245
240
|
var result = new Date(self.getTime() + (other * 1000));
|
246
241
|
result.is_utc = self.is_utc;
|
@@ -249,13 +244,13 @@ class Time < `Date`
|
|
249
244
|
end
|
250
245
|
|
251
246
|
def -(other)
|
252
|
-
if Time === other
|
247
|
+
if ::Time === other
|
253
248
|
return `(self.getTime() - other.getTime()) / 1000`
|
254
249
|
end
|
255
250
|
|
256
251
|
%x{
|
257
252
|
if (!other.$$is_number) {
|
258
|
-
other = #{Opal.coerce_to!(other, Integer, :to_int)};
|
253
|
+
other = #{::Opal.coerce_to!(other, ::Integer, :to_int)};
|
259
254
|
}
|
260
255
|
var result = new Date(self.getTime() - (other * 1000));
|
261
256
|
result.is_utc = self.is_utc;
|
@@ -264,7 +259,7 @@ class Time < `Date`
|
|
264
259
|
end
|
265
260
|
|
266
261
|
def <=>(other)
|
267
|
-
if Time === other
|
262
|
+
if ::Time === other
|
268
263
|
to_f <=> other.to_f
|
269
264
|
else
|
270
265
|
r = other <=> self
|
@@ -281,15 +276,13 @@ class Time < `Date`
|
|
281
276
|
end
|
282
277
|
|
283
278
|
def ==(other)
|
284
|
-
Time === other && `#{to_f} === #{other.to_f}`
|
279
|
+
::Time === other && `#{to_f} === #{other.to_f}`
|
285
280
|
end
|
286
281
|
|
287
282
|
def asctime
|
288
283
|
strftime '%a %b %e %H:%M:%S %Y'
|
289
284
|
end
|
290
285
|
|
291
|
-
alias ctime asctime
|
292
|
-
|
293
286
|
def day
|
294
287
|
`self.is_utc ? self.getUTCDate() : self.getDate()`
|
295
288
|
end
|
@@ -313,8 +306,6 @@ class Time < `Date`
|
|
313
306
|
}
|
314
307
|
end
|
315
308
|
|
316
|
-
alias dst? isdst
|
317
|
-
|
318
309
|
def dup
|
319
310
|
copy = `new Date(self.getTime())`
|
320
311
|
|
@@ -325,7 +316,7 @@ class Time < `Date`
|
|
325
316
|
end
|
326
317
|
|
327
318
|
def eql?(other)
|
328
|
-
other.is_a?(Time) && (self <=> other).zero?
|
319
|
+
other.is_a?(::Time) && (self <=> other).zero?
|
329
320
|
end
|
330
321
|
|
331
322
|
def friday?
|
@@ -348,8 +339,6 @@ class Time < `Date`
|
|
348
339
|
end
|
349
340
|
end
|
350
341
|
|
351
|
-
alias mday day
|
352
|
-
|
353
342
|
def min
|
354
343
|
`self.is_utc ? self.getUTCMinutes() : self.getMinutes()`
|
355
344
|
end
|
@@ -362,8 +351,6 @@ class Time < `Date`
|
|
362
351
|
`#{wday} == 1`
|
363
352
|
end
|
364
353
|
|
365
|
-
alias month mon
|
366
|
-
|
367
354
|
def saturday?
|
368
355
|
`#{wday} == 6`
|
369
356
|
end
|
@@ -413,8 +400,6 @@ class Time < `Date`
|
|
413
400
|
}
|
414
401
|
end
|
415
402
|
|
416
|
-
alias getutc getgm
|
417
|
-
|
418
403
|
def gmtime
|
419
404
|
%x{
|
420
405
|
self.is_utc = true;
|
@@ -422,8 +407,6 @@ class Time < `Date`
|
|
422
407
|
}
|
423
408
|
end
|
424
409
|
|
425
|
-
alias utc gmtime
|
426
|
-
|
427
410
|
def gmt?
|
428
411
|
`self.is_utc === true`
|
429
412
|
end
|
@@ -692,21 +675,10 @@ class Time < `Date`
|
|
692
675
|
`parseInt(self.getTime() / 1000, 10)`
|
693
676
|
end
|
694
677
|
|
695
|
-
alias to_s inspect
|
696
|
-
|
697
678
|
def tuesday?
|
698
679
|
`#{wday} == 2`
|
699
680
|
end
|
700
681
|
|
701
|
-
alias tv_sec to_i
|
702
|
-
|
703
|
-
alias tv_usec usec
|
704
|
-
|
705
|
-
alias utc? gmt?
|
706
|
-
|
707
|
-
alias gmtoff gmt_offset
|
708
|
-
alias utc_offset gmt_offset
|
709
|
-
|
710
682
|
def wday
|
711
683
|
`self.is_utc ? self.getUTCDay() : self.getDay()`
|
712
684
|
end
|
@@ -720,7 +692,7 @@ class Time < `Date`
|
|
720
692
|
end
|
721
693
|
|
722
694
|
def cweek_cyear
|
723
|
-
jan01 = Time.new(year, 1, 1)
|
695
|
+
jan01 = ::Time.new(year, 1, 1)
|
724
696
|
jan01_wday = jan01.wday
|
725
697
|
first_monday = 0
|
726
698
|
year = self.year
|
@@ -737,10 +709,10 @@ class Time < `Date`
|
|
737
709
|
|
738
710
|
if week <= 0
|
739
711
|
# Get the last week of the previous year
|
740
|
-
return Time.new(self.year - 1, 12, 31).cweek_cyear
|
712
|
+
return ::Time.new(self.year - 1, 12, 31).cweek_cyear
|
741
713
|
elsif week == 53
|
742
714
|
# Find out whether this is actually week 53 or already week 01 of the following year
|
743
|
-
dec31 = Time.new(self.year, 12, 31)
|
715
|
+
dec31 = ::Time.new(self.year, 12, 31)
|
744
716
|
dec31_wday = dec31.wday
|
745
717
|
if dec31_wday <= 3 && dec31_wday != 0
|
746
718
|
week = 1
|
@@ -750,4 +722,22 @@ class Time < `Date`
|
|
750
722
|
|
751
723
|
[week, year]
|
752
724
|
end
|
725
|
+
|
726
|
+
class << self
|
727
|
+
alias mktime local
|
728
|
+
alias utc gm
|
729
|
+
end
|
730
|
+
|
731
|
+
alias ctime asctime
|
732
|
+
alias dst? isdst
|
733
|
+
alias getutc getgm
|
734
|
+
alias gmtoff gmt_offset
|
735
|
+
alias mday day
|
736
|
+
alias month mon
|
737
|
+
alias to_s inspect
|
738
|
+
alias tv_sec to_i
|
739
|
+
alias tv_usec usec
|
740
|
+
alias utc gmtime
|
741
|
+
alias utc? gmt?
|
742
|
+
alias utc_offset gmt_offset
|
753
743
|
end
|
data/opal/corelib/trace_point.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class TracePoint
|
1
|
+
class ::TracePoint
|
2
2
|
# partial implementation of TracePoint
|
3
3
|
# for the moment only supports the :class event
|
4
4
|
def self.trace(event, &block)
|
@@ -8,7 +8,7 @@ class TracePoint
|
|
8
8
|
attr_reader :event
|
9
9
|
|
10
10
|
def initialize(event, &block)
|
11
|
-
raise 'Only the :class event is supported' unless event == :class
|
11
|
+
::Kernel.raise 'Only the :class event is supported' unless event == :class
|
12
12
|
@event = event
|
13
13
|
@block = block
|
14
14
|
@trace_object = nil
|