js 2.4.1.pre.1 → 2.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1baf96cf405625bab777ec6f790f3011e01bd1915b60f8665e9e2c99abc74c1c
4
- data.tar.gz: aaa6c6ae6736c051b3afb2ef1a2e38e4cf45ec96f3d652e7cd1e30686e34c097
3
+ metadata.gz: a1548392e9fe8a5aafc049bf997785e93d3545d77e0cc08db636bc36c14243d6
4
+ data.tar.gz: '028d3bcf94f19c167b244c388f61d964b54d18da67bf631e30cd1bfe2d511ec1'
5
5
  SHA512:
6
- metadata.gz: abc5b8e180d618a5d119b0e76a178a04decb85da0a4e1f1e8f5243698b8f6af73ac88a6ceb00c1ee479a589210b3e3a2e2a915414165f67af9d56d9dcb1f5455
7
- data.tar.gz: a6f02f9211cd6de68be4ff4fe3d8980a78cc7d248f46bf41a7149946265cd5cc11678c108dc4ccbc3ec3feaf0adff3570bea193af44ffb90388ea9ee9551ae3c
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.4.1.pre.1"
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.4.1.pre.1
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-06 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.
@@ -59,11 +59,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ">"
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 1.3.1
64
+ version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.4.1
66
+ rubygems_version: 3.4.19
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: JavaScript bindings for ruby.wasm