opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/stdlib/buffer.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'buffer/array'
|
2
|
+
require 'buffer/view'
|
3
|
+
|
4
|
+
class Buffer
|
5
|
+
include Native::Base
|
6
|
+
|
7
|
+
def self.supported?
|
8
|
+
not $$[:ArrayBuffer].nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.name_for(bits, type)
|
12
|
+
"#{case type
|
13
|
+
when :unsigned then 'Uint'
|
14
|
+
when :signed then 'Int'
|
15
|
+
when :float then 'Float'
|
16
|
+
end}#{bits}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(size, bits = 8)
|
20
|
+
if native?(size)
|
21
|
+
super(size)
|
22
|
+
else
|
23
|
+
super(`new ArrayBuffer(size * (bits / 8))`)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
`#@native.byteLength`
|
29
|
+
end
|
30
|
+
|
31
|
+
alias size length
|
32
|
+
|
33
|
+
def to_a(bits = 8, type = :unsigned)
|
34
|
+
Array.new(self, bits, type)
|
35
|
+
end
|
36
|
+
|
37
|
+
def view(offset = nil, length = nil)
|
38
|
+
View.new(self, offset, length)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Buffer < Native
|
2
|
+
|
3
|
+
class Array < Native
|
4
|
+
def self.for(bits, type)
|
5
|
+
$$["#{Buffer.name_for bits, type}Array"]
|
6
|
+
end
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
attr_reader :buffer, :type
|
11
|
+
|
12
|
+
def initialize(buffer, bits = nil, type = nil)
|
13
|
+
if Native == buffer
|
14
|
+
super(buffer)
|
15
|
+
else
|
16
|
+
%x{
|
17
|
+
var klass = #{Array.for(bits, type)};
|
18
|
+
|
19
|
+
#{super(`new klass(#{buffer.to_n})`)}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
@buffer = buffer
|
24
|
+
@type = type
|
25
|
+
end
|
26
|
+
|
27
|
+
def bits
|
28
|
+
`#@native.BYTES_PER_ELEMENT * 8`
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index, offset = nil)
|
32
|
+
offset ? `#@native.subarray(index, offset)` : `#@native[index]`
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, value)
|
36
|
+
`#@native[index] = value`
|
37
|
+
end
|
38
|
+
|
39
|
+
def bytesize
|
40
|
+
`#@native.byteLength`
|
41
|
+
end
|
42
|
+
|
43
|
+
def each
|
44
|
+
return enum_for :each unless block_given?
|
45
|
+
|
46
|
+
%x{
|
47
|
+
for (var i = 0, length = #@native.length; i < length; i++) {
|
48
|
+
#{yield `#@native[i]`}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def length
|
56
|
+
`#@native.length`
|
57
|
+
end
|
58
|
+
|
59
|
+
def merge!(other, offset = undefined)
|
60
|
+
`#@native.set(#{other.to_n}, offset)`
|
61
|
+
end
|
62
|
+
|
63
|
+
alias size length
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Buffer
|
2
|
+
|
3
|
+
class View
|
4
|
+
include Native::Base
|
5
|
+
|
6
|
+
def self.supported?
|
7
|
+
not $$[:DataView].nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :buffer, :offset
|
11
|
+
|
12
|
+
def initialize(buffer, offset = nil, length = nil)
|
13
|
+
if native?(buffer)
|
14
|
+
super(buffer)
|
15
|
+
elsif offset && length
|
16
|
+
super(`new DataView(#{buffer.to_n}, #{offset.to_n}, #{length.to_n})`)
|
17
|
+
elsif offset
|
18
|
+
super(`new DataView(#{buffer.to_n}, #{offset.to_n})`)
|
19
|
+
else
|
20
|
+
super(`new DataView(#{buffer.to_n})`)
|
21
|
+
end
|
22
|
+
|
23
|
+
@buffer = buffer
|
24
|
+
@offset = offset
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
`#@native.byteLength`
|
29
|
+
end
|
30
|
+
|
31
|
+
alias size length
|
32
|
+
|
33
|
+
def get(offset, bits = 8, type = :unsigned, little = false)
|
34
|
+
`#@native["get" + #{Buffer.name_for bits, type}](offset, little)`
|
35
|
+
end
|
36
|
+
|
37
|
+
alias [] get
|
38
|
+
|
39
|
+
def set(offset, value, bits = 8, type = :unsigned, little = false)
|
40
|
+
`#@native["set" + #{Buffer.name_for bits, type}](offset, value, little)`
|
41
|
+
end
|
42
|
+
|
43
|
+
alias []= set
|
44
|
+
|
45
|
+
def get_int8(offset, little = false); `#@native.getInt8(offset, little)`; end
|
46
|
+
def set_int8(offset, value, little = false); `#@native.setInt8(offset, value, little)`; end
|
47
|
+
|
48
|
+
def get_uint8(offset, little = false); `#@native.getUint8(offset, little)`; end
|
49
|
+
def set_uint8(offset, value, little = false); `#@native.setUint8(offset, value, little)`; end
|
50
|
+
|
51
|
+
def get_int16(offset, little = false); `#@native.getInt16(offset, little)`; end
|
52
|
+
def set_int16(offset, value, little = false); `#@native.setInt16(offset, value, little)`; end
|
53
|
+
|
54
|
+
def get_uint16(offset, little = false); `#@native.getUint16(offset, little)`; end
|
55
|
+
def set_uint16(offset, value, little = false); `#@native.setUint16(offset, value, little)`; end
|
56
|
+
|
57
|
+
def get_int32(offset, little = false); `#@native.getInt32(offset, little)`; end
|
58
|
+
def set_int32(offset, value, little = false); `#@native.setInt32(offset, value, little)`; end
|
59
|
+
|
60
|
+
def get_uint32(offset, little = false); `#@native.getUint32(offset, little)`; end
|
61
|
+
def set_uint32(offset, value, little = false); `#@native.setUint32(offset, value, little)`; end
|
62
|
+
|
63
|
+
def get_float32(offset, little = false); `#@native.getFloat32(offset, little)`; end
|
64
|
+
def set_float32(offset, value, little = false); `#@native.setFloat32(offset, value, little)`; end
|
65
|
+
|
66
|
+
def get_float64(offset, little = false); `#@native.getFloat64(offset, little)`; end
|
67
|
+
def set_float64(offset, value, little = false); `#@native.setFloat64(offset, value, little)`; end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/stdlib/erb.rb
CHANGED
@@ -1,26 +1,17 @@
|
|
1
|
-
|
2
|
-
@_cache = {}
|
3
|
-
def self.[](name)
|
4
|
-
@_cache[name]
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.[]=(name, instance)
|
8
|
-
@_cache[name] = instance
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require 'template'
|
11
2
|
|
12
3
|
class ERB
|
13
|
-
|
14
|
-
@body = body
|
15
|
-
@name = name
|
16
|
-
Template[name] = self
|
17
|
-
end
|
4
|
+
module Util
|
18
5
|
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
`var escapes = { '&': '&', '<': '<', '>': '>', '"': '"', "'": '''};`
|
7
|
+
`var escape_regexp = /[&<>"']/g;`
|
8
|
+
|
9
|
+
def html_escape(str)
|
10
|
+
`return ("" + str).replace(escape_regexp, function (m) { return escapes[m] });`
|
11
|
+
end
|
22
12
|
|
23
|
-
|
24
|
-
|
13
|
+
alias h html_escape
|
14
|
+
module_function :h
|
15
|
+
module_function :html_escape
|
25
16
|
end
|
26
17
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Forwardable
|
2
|
+
def instance_delegate(hash)
|
3
|
+
hash.each {|methods, accessor|
|
4
|
+
methods = [methods] unless methods.respond_to? :each
|
5
|
+
|
6
|
+
methods.each {|method|
|
7
|
+
def_instance_delegator(accessor, method)
|
8
|
+
}
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def def_instance_delegators(accessor, *methods)
|
13
|
+
methods.each {|method|
|
14
|
+
next if %w[__send__ __id__].include?(method)
|
15
|
+
|
16
|
+
def_instance_delegator(accessor, method)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def def_instance_delegator(accessor, method, ali = method)
|
21
|
+
if accessor.to_s.start_with? ?@
|
22
|
+
define_method ali do |*args, &block|
|
23
|
+
instance_variable_get(accessor).__send__(method, *args, &block)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
define_method ali do |*args, &block|
|
27
|
+
__send__(accessor).__send__(method, *args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
alias delegate instance_delegate
|
33
|
+
alias def_delegators def_instance_delegators
|
34
|
+
alias def_delegator def_instance_delegator
|
35
|
+
end
|
36
|
+
|
37
|
+
module SingleForwardable
|
38
|
+
def single_delegate(hash)
|
39
|
+
hash.each {|methods, accessor|
|
40
|
+
methods = [methods] unless methods.respond_to? :each
|
41
|
+
|
42
|
+
methods.each {|method|
|
43
|
+
def_single_delegator(accessor, method)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def def_single_delegators(accessor, *methods)
|
49
|
+
methods.each {|method|
|
50
|
+
next if %w[__send__ __id__].include? method
|
51
|
+
|
52
|
+
def_single_delegator(accessor, method)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def def_single_delegator(accessor, method, ali = method)
|
57
|
+
if accessor.to_s.start_with? ?@
|
58
|
+
define_singleton_method ali do |*args, &block|
|
59
|
+
instance_variable_get(accessor).__send__(method, *args, &block)
|
60
|
+
end
|
61
|
+
else
|
62
|
+
define_singleton_method ali do |*args, &block|
|
63
|
+
__send__(accessor).__send__(method, *args, &block)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
alias delegate single_delegate
|
69
|
+
alias def_delegators def_single_delegators
|
70
|
+
alias def_delegator def_single_delegator
|
71
|
+
end
|
data/stdlib/json.rb
CHANGED
@@ -54,3 +54,81 @@ module JSON
|
|
54
54
|
};
|
55
55
|
}
|
56
56
|
end
|
57
|
+
|
58
|
+
module Kernel
|
59
|
+
def to_json
|
60
|
+
to_s.to_json
|
61
|
+
end
|
62
|
+
|
63
|
+
def as_json
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Array
|
69
|
+
def to_json
|
70
|
+
%x{
|
71
|
+
var result = [];
|
72
|
+
|
73
|
+
for (var i = 0, length = #{self}.length; i < length; i++) {
|
74
|
+
result.push(#{ `#{self}[i]`.to_json });
|
75
|
+
}
|
76
|
+
|
77
|
+
return '[' + result.join(', ') + ']';
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
class Boolean
|
84
|
+
def as_json
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_json
|
89
|
+
`(#{self} == true) ? 'true' : 'false'`
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Hash
|
94
|
+
def to_json
|
95
|
+
%x{
|
96
|
+
var inspect = [], keys = #{self}.keys, map = #{self}.map;
|
97
|
+
|
98
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
99
|
+
var key = keys[i];
|
100
|
+
inspect.push(#{`key`.to_json} + ': ' + #{`map[key]`.to_json});
|
101
|
+
}
|
102
|
+
|
103
|
+
return '{' + inspect.join(', ') + '}';
|
104
|
+
}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class NilClass
|
109
|
+
def as_json
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_json
|
114
|
+
'null'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Numeric
|
119
|
+
def as_json
|
120
|
+
self
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_json
|
124
|
+
`#{self}.toString()`
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class String
|
129
|
+
def as_json
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
alias to_json inspect
|
134
|
+
end
|
data/stdlib/ostruct.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
class OpenStruct
|
2
|
+
def initialize(hash = nil)
|
3
|
+
@table = {}
|
4
|
+
|
5
|
+
hash.each_pair {|key, value|
|
6
|
+
@table[key.to_sym] = value
|
7
|
+
} if hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](name)
|
11
|
+
@table[name.to_sym]
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(name, value)
|
15
|
+
@table[name.to_sym] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(name, *args)
|
19
|
+
if name.end_with? '='
|
20
|
+
@table[name[0 .. -2].to_sym] = args[0]
|
21
|
+
else
|
22
|
+
@table[name.to_sym]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_pair
|
27
|
+
return enum_for :each_pair unless block_given?
|
28
|
+
|
29
|
+
@table.each_pair {|pair|
|
30
|
+
yield pair
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def ==(other)
|
35
|
+
return false unless other.is_a?(OpenStruct)
|
36
|
+
|
37
|
+
@table == other.instance_variable_get(:@table)
|
38
|
+
end
|
39
|
+
|
40
|
+
def ===(other)
|
41
|
+
return false unless other.is_a?(OpenStruct)
|
42
|
+
|
43
|
+
@table === other.instance_variable_get(:@table)
|
44
|
+
end
|
45
|
+
|
46
|
+
def eql?(other)
|
47
|
+
return false unless other.is_a?(OpenStruct)
|
48
|
+
|
49
|
+
@table.eql? other.instance_variable_get(:@table)
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_h
|
53
|
+
@table.dup
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_n
|
57
|
+
@table.to_n
|
58
|
+
end
|
59
|
+
|
60
|
+
def hash
|
61
|
+
@table.hash
|
62
|
+
end
|
63
|
+
|
64
|
+
def inspect
|
65
|
+
"#<#{self.class}: #{each_pair.map {|name, value|
|
66
|
+
"#{name}=#{self[name].inspect}"
|
67
|
+
}.join(" ")}>"
|
68
|
+
end
|
69
|
+
end
|
data/stdlib/rbconfig.rb
CHANGED