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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 777a9c8adbfc32598b84812cd1a761e23237fd8c79555f1ae6e7dc251cf7d73c
4
- data.tar.gz: d2f49898aeffc50769fc5f3cd6c8b038ec771844d49530f568322ada6a8e56df
3
+ metadata.gz: ef19397a28e7f064e469b0067f8045dc566ea4434553d60e1a993ed48935d3f5
4
+ data.tar.gz: 19b73cc8cdc6e01af1e5d54fd5115d44bdebd76b7dbc14e0581791e6d7195cfe
5
5
  SHA512:
6
- metadata.gz: 12db815d8bae8d32335b243d01ff677b47cc49d9dbfc648f0c26b5ad2b99706fc8277dfa5e801d8ee621bc271bfd0353f40867dae89a595675059b02a4866430
7
- data.tar.gz: 364cbc01b4a86e4c82cc66af0f808c6b9dce6dce3f023a28bf154a380fa24af090b6cdd901c2f3c64aa5698df510b6081e9eaf2509172fad8ce98a411461b755
6
+ metadata.gz: 6d3dea5122dbe9e92443b7e2f6b4004265c67468bebdf41eda2c965bf5af0a5289bd527ae0151ca872e39a3a21acfe44252b7d6b588beb34d157053156908681
7
+ data.tar.gz: eae1bcde9ea11c6f1a752b9d35b3d4c34c52763a907a338d23a24c39d415fd2ddd86f5787e19bfc632dba18a2b5287f1cc25476ddfd8f7c75a5106ce5b280515
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module WebAssembly
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -278,6 +278,10 @@ module FFI
278
278
  self.address = FFI.context.realloc(self, new_size).address
279
279
  end
280
280
 
281
+ def free
282
+ FFI.context.free(self)
283
+ end
284
+
281
285
  def inspect
282
286
  out = "#<#{self.class.name}:#{"0x%08x" % self.address} of #{self.type.inspect}>"
283
287
  end
@@ -84,6 +84,10 @@ module FFI
84
84
  end
85
85
  end
86
86
 
87
+ def free
88
+ @pointer.free
89
+ end
90
+
87
91
  def inspect
88
92
  out = ["#<#{self.class.name}:#{"0x%08x" % self.address}: "]
89
93
  out << self.members.keys.map do |key|
@@ -14,8 +14,21 @@ module WebAssembly
14
14
  end
15
15
 
16
16
  def self.load_from_buffer(buffer, name)
17
- mod = Module.new(buffer)
18
- @libs[name] = Instance.new(mod)
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
@@ -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
- `new WebAssembly.Module(#{buffer})`
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.0
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.0.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: []