js 2.5.0 → 2.5.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: c8db8331e9b5af21a79ef8c5f7136ac86f2dd5960805fb666e7b29a76ab5a8df
4
- data.tar.gz: 90393c06028f76007dd4e6f186d75e5556abf619a631a34934c93e2425455a21
3
+ metadata.gz: a1548392e9fe8a5aafc049bf997785e93d3545d77e0cc08db636bc36c14243d6
4
+ data.tar.gz: '028d3bcf94f19c167b244c388f61d964b54d18da67bf631e30cd1bfe2d511ec1'
5
5
  SHA512:
6
- metadata.gz: f091babf60c93c329efd3ccc3ffc798312551a93deeef2bea3a01fc98d70b4b9ef739f1c2c02e4d0d29eb8544b541ae29ab2b3b3239044e2e66290f8838bea35
7
- data.tar.gz: 67bfb90975cc2ae66b6e713eb64fb5f7521599059779e17ffaa741a39b636366dc24a6dfb97c17ae082eaee3f50e2f99a07f66ef0b0061c827a5820a09f31b72
6
+ metadata.gz: 370c149ec326bcf0f9fbbfb6dfbb8d92b27ecfc99933a1c58af35669923aeb439ad2f5719b2da12b1ae5bf016b9bfaf8f0fba73ddd9ea73d9101dc7df2f5a9b8
7
+ data.tar.gz: a702e7859689f537d4bed57fd85b537556cdf30336cf1155031aae13c057dcf6e2826f9b616fae21a4ab1ceca58d7b07386a2431334eef4e833a39a821f6ac92
data/ext/js/js-core.c CHANGED
@@ -200,6 +200,11 @@ static VALUE _rb_js_obj_aref(VALUE obj, VALUE key) {
200
200
  static VALUE _rb_js_obj_aset(VALUE obj, VALUE key, VALUE val) {
201
201
  struct jsvalue *p = check_jsvalue(obj);
202
202
  VALUE rv = _rb_js_try_convert(rb_mJS, val);
203
+ if (rv == Qnil) {
204
+ rb_raise(rb_eTypeError,
205
+ "wrong argument type %s (expected JS::Object like object)",
206
+ rb_class2name(rb_obj_class(val)));
207
+ }
203
208
  struct jsvalue *v = check_jsvalue(rv);
204
209
  rb_js_abi_host_string_t key_abi_str;
205
210
  key = rb_obj_as_string(key);
@@ -235,8 +240,14 @@ static VALUE _rb_js_obj_strictly_eql(VALUE obj, VALUE other) {
235
240
  * Performs "==" comparison, a.k.a the "Abstract Equality Comparison"
236
241
  * algorithm defined in the ECMAScript.
237
242
  * https://262.ecma-international.org/11.0/#sec-abstract-equality-comparison
243
+ * If the given other object is not a JS::Object, try to convert it to a
244
+ * JS::Object using JS.try_convert. If the conversion fails, returns false.
238
245
  */
239
246
  static VALUE _rb_js_obj_eql(VALUE obj, VALUE other) {
247
+ other = _rb_js_try_convert(rb_mJS, other);
248
+ if (other == Qnil) {
249
+ return Qfalse;
250
+ }
240
251
  struct jsvalue *lhs = check_jsvalue(obj);
241
252
  struct jsvalue *rhs = check_jsvalue(other);
242
253
  bool result = rb_js_abi_host_js_value_equal(lhs->abi, rhs->abi);
data/ext/witapi/depend CHANGED
@@ -8,4 +8,4 @@ witapi-core.o: $(srcdir)/bindgen/rb-abi-guest.h
8
8
 
9
9
  bindgen/%.o: $(srcdir)/bindgen/%.c
10
10
  @mkdir -p "$(@D)"
11
- $(CC) -c -I$(srcdir)/bindgen -o $@ $<
11
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$< -I$(srcdir)/bindgen
data/lib/js/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JS
2
- VERSION = "2.5.0"
2
+ VERSION = "2.5.1"
3
3
  end
data/lib/js.rb CHANGED
@@ -79,8 +79,8 @@ module JS
79
79
  current = Fiber.current
80
80
  promise.call(
81
81
  :then,
82
- ->(value) { current.transfer(value, :success) },
83
- ->(value) { current.transfer(value, :failure) }
82
+ ->(value) { current.transfer(value, :success); nil },
83
+ ->(value) { current.transfer(value, :failure); nil }
84
84
  )
85
85
  if @loop == current
86
86
  raise (
@@ -137,8 +137,10 @@ class JS::Object
137
137
  # JS.global[:Date].new(2020, 1, 1)
138
138
  # JS.global[:Error].new("error message")
139
139
  # JS.global[:URLSearchParams].new(JS.global[:location][:search])
140
+ # JS.global[:Promise].new ->(resolve, reject) { resolve.call(42) }
140
141
  #
141
- def new(*args)
142
+ def new(*args, &block)
143
+ args = args + [block] if block
142
144
  JS.global[:Reflect].construct(self, args.to_js)
143
145
  end
144
146
 
@@ -189,6 +191,20 @@ class JS::Object
189
191
  self[sym].typeof == "function"
190
192
  end
191
193
 
194
+ # Call the receiver (a JavaScript function) with `undefined` as its receiver context.
195
+ # This method is similar to JS::Object#call, but it is used to call a function that is not
196
+ # a method of an object.
197
+ #
198
+ # floor = JS.global[:Math][:floor]
199
+ # floor.apply(3.14) # => 3
200
+ # JS.global[:Promise].new do |resolve, reject|
201
+ # resolve.apply(42)
202
+ # end.await # => 42
203
+ def apply(*args, &block)
204
+ args = args + [block] if block
205
+ JS.global[:Reflect].call(:apply, self, JS::Undefined, args.to_js)
206
+ end
207
+
192
208
  # Await a JavaScript Promise like `await` in JavaScript.
193
209
  # This method looks like a synchronous method, but it actually runs asynchronously using fibers.
194
210
  # In other words, the next line to the `await` call at Ruby source will be executed after the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Saito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-28 00:00:00.000000000 Z
11
+ date: 2024-04-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: JavaScript bindings for ruby.wasm. This gem provides a way to use JavaScript
14
14
  functionalities from Ruby through WebAssembly.
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.5.3
66
+ rubygems_version: 3.4.19
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: JavaScript bindings for ruby.wasm