h8 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/h8/context.rb +24 -2
- data/lib/h8/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14907661c25fc5691c960e9ad0938fbfcb3bffef
|
4
|
+
data.tar.gz: 23f50bbead56e80287a1a2f59ef54bd2badb5eab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d0bd57de89e2b7e9145e5cfc406ed8cf3f55e35db399da8bf6f4b78b815fb5609297513067b64ff0f1fe6d5ef7a377d084b26dc7741b87f2ee8b4128fa75fb1
|
7
|
+
data.tar.gz: 9d8386413a967cf17b17bba3dfd2d804a4d07fcc71a1b0b53fdeead2c3cc48eb82fe4519121ef09043a4ed4795b8fc7ca2a070e11d6c671184043e25163443a4
|
data/lib/h8/context.rb
CHANGED
@@ -5,16 +5,19 @@ require 'ostruct'
|
|
5
5
|
require 'hashie'
|
6
6
|
|
7
7
|
class Array
|
8
|
-
|
8
|
+
# JS select() implementation
|
9
|
+
def __js_select callable
|
9
10
|
select { |item|
|
10
11
|
callable.call item
|
11
12
|
}
|
12
13
|
end
|
13
14
|
|
15
|
+
# JS indexOf implementation
|
14
16
|
def indexOf item
|
15
17
|
index(item) || -1
|
16
18
|
end
|
17
19
|
|
20
|
+
# JS splice() implementation
|
18
21
|
def splice(start, len, *replace)
|
19
22
|
ret = self[start, len]
|
20
23
|
self[start, len] = replace
|
@@ -23,6 +26,7 @@ class Array
|
|
23
26
|
end
|
24
27
|
|
25
28
|
class String
|
29
|
+
# JS compatibility
|
26
30
|
def indexOf item
|
27
31
|
index(item) || -1
|
28
32
|
end
|
@@ -52,14 +56,23 @@ def Hashie::Mash
|
|
52
56
|
end
|
53
57
|
|
54
58
|
class Object
|
59
|
+
# Integration with JSON.stringify in JS. Method should return valid
|
60
|
+
# JSON _string representation_. Works using standard ruby JSON or Rails
|
61
|
+
# ties. Usually you do not override it but implement #to_json or, in Rails,
|
62
|
+
# #as_json *args. But in some cases you might need to implement it directly
|
55
63
|
def __to_json
|
56
64
|
JSON.unparse self
|
57
65
|
end
|
58
66
|
|
67
|
+
# JS hasOwnProperty() implementation
|
59
68
|
def __js_has_property name
|
60
69
|
__js_enumerate.include?(name)
|
61
70
|
end
|
62
71
|
|
72
|
+
# Enumerate _own properties_ to access from JS code. Think about calling super
|
73
|
+
# when overriding it.
|
74
|
+
#
|
75
|
+
# @return [Array[String]] list all own properties.
|
63
76
|
def __js_enumerate
|
64
77
|
if respond_to?(:keys)
|
65
78
|
self.keys.map(&:to_s)
|
@@ -72,6 +85,12 @@ end
|
|
72
85
|
|
73
86
|
module H8
|
74
87
|
|
88
|
+
# Context is an environment where javscripts and coffeescripts can be executed. Context holds
|
89
|
+
# its state between execution and can therefore consume large amount of memory if called
|
90
|
+
# repeatedly for a long time. You can release some of its memory by setting to null its
|
91
|
+
# global level variables, but the best is to allocate new Context as need leaving old
|
92
|
+
# instances fo GC. Please note that Context can not be GC'd if any of it objects is gated
|
93
|
+
# and held by ruby somewhere.
|
75
94
|
class Context
|
76
95
|
# Create new context optionally providing variables hash
|
77
96
|
def initialize noglobals: false, **kwargs
|
@@ -144,7 +163,7 @@ module H8
|
|
144
163
|
def self.secure_call instance, method, args=nil
|
145
164
|
# p [:sc, instance, method, args]
|
146
165
|
if instance.is_a?(Array)
|
147
|
-
method == 'select' and method = '
|
166
|
+
method == 'select' and method = '__js_select'
|
148
167
|
end
|
149
168
|
immediate_call = if method[0] == '!'
|
150
169
|
method = method[1..-1]
|
@@ -186,6 +205,9 @@ module H8
|
|
186
205
|
end
|
187
206
|
rescue NameError
|
188
207
|
# It means there is no [] or []=, e.g. undefined
|
208
|
+
rescue TypeError
|
209
|
+
raise unless $!.to_s =~ /no implicit conversion of String into Integer/
|
210
|
+
# This also means that property is not found
|
189
211
|
end
|
190
212
|
end
|
191
213
|
H8::Undefined
|
data/lib/h8/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: h8
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|