opal-webassembly 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opal/webassembly/version.rb +1 -1
- data/opal/ffi/pointer.rb +4 -0
- data/opal/ffi/struct.rb +4 -0
- data/opal/webassembly.rb +44 -2
- data/opal/webassembly/module.rb +12 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef19397a28e7f064e469b0067f8045dc566ea4434553d60e1a993ed48935d3f5
|
4
|
+
data.tar.gz: 19b73cc8cdc6e01af1e5d54fd5115d44bdebd76b7dbc14e0581791e6d7195cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d3dea5122dbe9e92443b7e2f6b4004265c67468bebdf41eda2c965bf5af0a5289bd527ae0151ca872e39a3a21acfe44252b7d6b588beb34d157053156908681
|
7
|
+
data.tar.gz: eae1bcde9ea11c6f1a752b9d35b3d4c34c52763a907a338d23a24c39d415fd2ddd86f5787e19bfc632dba18a2b5287f1cc25476ddfd8f7c75a5106ce5b280515
|
data/opal/ffi/pointer.rb
CHANGED
data/opal/ffi/struct.rb
CHANGED
data/opal/webassembly.rb
CHANGED
@@ -14,8 +14,21 @@ module WebAssembly
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.load_from_buffer(buffer, name)
|
17
|
-
|
18
|
-
|
17
|
+
begin
|
18
|
+
mod = Module.new(buffer)
|
19
|
+
@libs[name] = Instance.new(mod)
|
20
|
+
loaded(name)
|
21
|
+
rescue CantLoadSyncError
|
22
|
+
# We are in Chromium which disallows loading a module synchronously
|
23
|
+
%x{
|
24
|
+
WebAssembly.instantiate(#{buffer}).then(function(d) {
|
25
|
+
#{
|
26
|
+
@libs[name] = `d.instance`
|
27
|
+
loaded(name)
|
28
|
+
}
|
29
|
+
})
|
30
|
+
}
|
31
|
+
end
|
19
32
|
end
|
20
33
|
|
21
34
|
%x{
|
@@ -62,6 +75,35 @@ module WebAssembly
|
|
62
75
|
self.load_from_buffer(`base64_to_arraybuffer(#{base64})`, name)
|
63
76
|
end
|
64
77
|
|
78
|
+
@waiting_for = []
|
79
|
+
|
80
|
+
def self.wait_for(*libs, &block)
|
81
|
+
prom = nil
|
82
|
+
unless block_given?
|
83
|
+
prom = `new Promise(function(ok, fail) {
|
84
|
+
#{
|
85
|
+
block = `ok`
|
86
|
+
}
|
87
|
+
})`
|
88
|
+
end
|
89
|
+
|
90
|
+
if libs.all? { |lib| @libs[lib] }
|
91
|
+
yield
|
92
|
+
else
|
93
|
+
@waiting_for << [libs, block]
|
94
|
+
end
|
95
|
+
|
96
|
+
prom
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.loaded(lib)
|
100
|
+
@waiting_for.each do |libs, block|
|
101
|
+
if libs.all? { |lib| @libs[lib] }
|
102
|
+
block.()
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
65
107
|
def self.[](name)
|
66
108
|
self.libs[name]
|
67
109
|
end
|
data/opal/webassembly/module.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'native'
|
2
2
|
|
3
3
|
module WebAssembly
|
4
|
+
class CantLoadSyncError < StandardError; end
|
5
|
+
|
4
6
|
class Module < `WebAssembly.Module`
|
5
7
|
def self.new(buffer)
|
6
8
|
buffer = buffer.to_n unless native? buffer
|
7
|
-
|
9
|
+
%x{
|
10
|
+
try {
|
11
|
+
return new WebAssembly.Module(#{buffer});
|
12
|
+
} catch(e) {
|
13
|
+
if (e.name == "RangeError") {
|
14
|
+
#{raise WebAssembly::CantLoadSyncError}
|
15
|
+
}
|
16
|
+
else throw e;
|
17
|
+
}
|
18
|
+
}
|
8
19
|
end
|
9
20
|
end
|
10
21
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-webassembly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-10-05 00:00:00.000000000 Z
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- open.source@ribose.com
|
30
30
|
executables:
|
@@ -82,7 +82,7 @@ metadata:
|
|
82
82
|
homepage_uri: https://github.com/interscript/opal-webassembly
|
83
83
|
source_code_uri: https://github.com/interscript/opal-webassembly
|
84
84
|
changelog_uri: https://github.com/interscript/opal-webassembly/commits/master
|
85
|
-
post_install_message:
|
85
|
+
post_install_message:
|
86
86
|
rdoc_options: []
|
87
87
|
require_paths:
|
88
88
|
- lib
|
@@ -97,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
rubygems_version: 3.
|
101
|
-
signing_key:
|
100
|
+
rubygems_version: 3.1.2
|
101
|
+
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Opal with WebAssembly support
|
104
104
|
test_files: []
|