/rust/registry/src/index.crates.io-6f17d22bba15001f/v8-0.44.3/src/value.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use std::num::NonZeroI32; |
2 | | |
3 | | use crate::support::int; |
4 | | use crate::support::Maybe; |
5 | | use crate::BigInt; |
6 | | use crate::Boolean; |
7 | | use crate::Context; |
8 | | use crate::HandleScope; |
9 | | use crate::Int32; |
10 | | use crate::Integer; |
11 | | use crate::Isolate; |
12 | | use crate::Local; |
13 | | use crate::Number; |
14 | | use crate::Object; |
15 | | use crate::String; |
16 | | use crate::Uint32; |
17 | | use crate::Value; |
18 | | |
19 | | extern "C" { |
20 | | fn v8__Value__IsUndefined(this: *const Value) -> bool; |
21 | | fn v8__Value__IsNull(this: *const Value) -> bool; |
22 | | fn v8__Value__IsNullOrUndefined(this: *const Value) -> bool; |
23 | | fn v8__Value__IsTrue(this: *const Value) -> bool; |
24 | | fn v8__Value__IsFalse(this: *const Value) -> bool; |
25 | | fn v8__Value__IsName(this: *const Value) -> bool; |
26 | | fn v8__Value__IsString(this: *const Value) -> bool; |
27 | | fn v8__Value__IsSymbol(this: *const Value) -> bool; |
28 | | fn v8__Value__IsFunction(this: *const Value) -> bool; |
29 | | fn v8__Value__IsArray(this: *const Value) -> bool; |
30 | | fn v8__Value__IsObject(this: *const Value) -> bool; |
31 | | fn v8__Value__IsBigInt(this: *const Value) -> bool; |
32 | | fn v8__Value__IsBoolean(this: *const Value) -> bool; |
33 | | fn v8__Value__IsNumber(this: *const Value) -> bool; |
34 | | fn v8__Value__IsExternal(this: *const Value) -> bool; |
35 | | fn v8__Value__IsInt32(this: *const Value) -> bool; |
36 | | fn v8__Value__IsUint32(this: *const Value) -> bool; |
37 | | fn v8__Value__IsDate(this: *const Value) -> bool; |
38 | | fn v8__Value__IsArgumentsObject(this: *const Value) -> bool; |
39 | | fn v8__Value__IsBigIntObject(this: *const Value) -> bool; |
40 | | fn v8__Value__IsBooleanObject(this: *const Value) -> bool; |
41 | | fn v8__Value__IsNumberObject(this: *const Value) -> bool; |
42 | | fn v8__Value__IsStringObject(this: *const Value) -> bool; |
43 | | fn v8__Value__IsSymbolObject(this: *const Value) -> bool; |
44 | | fn v8__Value__IsNativeError(this: *const Value) -> bool; |
45 | | fn v8__Value__IsRegExp(this: *const Value) -> bool; |
46 | | fn v8__Value__IsAsyncFunction(this: *const Value) -> bool; |
47 | | fn v8__Value__IsGeneratorFunction(this: *const Value) -> bool; |
48 | | #[allow(dead_code)] |
49 | | fn v8__Value__IsGeneratorObject(this: *const Value) -> bool; |
50 | | fn v8__Value__IsPromise(this: *const Value) -> bool; |
51 | | fn v8__Value__IsMap(this: *const Value) -> bool; |
52 | | fn v8__Value__IsSet(this: *const Value) -> bool; |
53 | | fn v8__Value__IsMapIterator(this: *const Value) -> bool; |
54 | | fn v8__Value__IsSetIterator(this: *const Value) -> bool; |
55 | | fn v8__Value__IsWeakMap(this: *const Value) -> bool; |
56 | | fn v8__Value__IsWeakSet(this: *const Value) -> bool; |
57 | | fn v8__Value__IsArrayBuffer(this: *const Value) -> bool; |
58 | | fn v8__Value__IsArrayBufferView(this: *const Value) -> bool; |
59 | | fn v8__Value__IsTypedArray(this: *const Value) -> bool; |
60 | | fn v8__Value__IsUint8Array(this: *const Value) -> bool; |
61 | | fn v8__Value__IsUint8ClampedArray(this: *const Value) -> bool; |
62 | | fn v8__Value__IsInt8Array(this: *const Value) -> bool; |
63 | | fn v8__Value__IsUint16Array(this: *const Value) -> bool; |
64 | | fn v8__Value__IsInt16Array(this: *const Value) -> bool; |
65 | | fn v8__Value__IsUint32Array(this: *const Value) -> bool; |
66 | | fn v8__Value__IsInt32Array(this: *const Value) -> bool; |
67 | | fn v8__Value__IsFloat32Array(this: *const Value) -> bool; |
68 | | fn v8__Value__IsFloat64Array(this: *const Value) -> bool; |
69 | | fn v8__Value__IsBigInt64Array(this: *const Value) -> bool; |
70 | | fn v8__Value__IsBigUint64Array(this: *const Value) -> bool; |
71 | | fn v8__Value__IsDataView(this: *const Value) -> bool; |
72 | | fn v8__Value__IsSharedArrayBuffer(this: *const Value) -> bool; |
73 | | fn v8__Value__IsProxy(this: *const Value) -> bool; |
74 | | fn v8__Value__IsWasmMemoryObject(this: *const Value) -> bool; |
75 | | fn v8__Value__IsWasmModuleObject(this: *const Value) -> bool; |
76 | | fn v8__Value__IsModuleNamespaceObject(this: *const Value) -> bool; |
77 | | fn v8__Value__StrictEquals(this: *const Value, that: *const Value) -> bool; |
78 | | fn v8__Value__SameValue(this: *const Value, that: *const Value) -> bool; |
79 | | fn v8__Value__InstanceOf( |
80 | | this: *const Value, |
81 | | context: *const Context, |
82 | | object: *const Object, |
83 | | out: *mut Maybe<bool>, |
84 | | ); |
85 | | fn v8__Value__ToBigInt( |
86 | | this: *const Value, |
87 | | context: *const Context, |
88 | | ) -> *const BigInt; |
89 | | fn v8__Value__ToNumber( |
90 | | this: *const Value, |
91 | | context: *const Context, |
92 | | ) -> *const Number; |
93 | | fn v8__Value__ToString( |
94 | | this: *const Value, |
95 | | context: *const Context, |
96 | | ) -> *const String; |
97 | | fn v8__Value__ToDetailString( |
98 | | this: *const Value, |
99 | | context: *const Context, |
100 | | ) -> *const String; |
101 | | fn v8__Value__ToObject( |
102 | | this: *const Value, |
103 | | context: *const Context, |
104 | | ) -> *const Object; |
105 | | fn v8__Value__ToInteger( |
106 | | this: *const Value, |
107 | | context: *const Context, |
108 | | ) -> *const Integer; |
109 | | fn v8__Value__ToUint32( |
110 | | this: *const Value, |
111 | | context: *const Context, |
112 | | ) -> *const Uint32; |
113 | | fn v8__Value__ToInt32( |
114 | | this: *const Value, |
115 | | context: *const Context, |
116 | | ) -> *const Int32; |
117 | | fn v8__Value__ToBoolean( |
118 | | this: *const Value, |
119 | | isolate: *mut Isolate, |
120 | | ) -> *const Boolean; |
121 | | |
122 | | fn v8__Value__NumberValue( |
123 | | this: *const Value, |
124 | | context: *const Context, |
125 | | out: *mut Maybe<f64>, |
126 | | ); |
127 | | fn v8__Value__IntegerValue( |
128 | | this: *const Value, |
129 | | context: *const Context, |
130 | | out: *mut Maybe<i64>, |
131 | | ); |
132 | | fn v8__Value__Uint32Value( |
133 | | this: *const Value, |
134 | | context: *const Context, |
135 | | out: *mut Maybe<u32>, |
136 | | ); |
137 | | fn v8__Value__Int32Value( |
138 | | this: *const Value, |
139 | | context: *const Context, |
140 | | out: *mut Maybe<i32>, |
141 | | ); |
142 | | fn v8__Value__BooleanValue(this: *const Value, isolate: *mut Isolate) |
143 | | -> bool; |
144 | | fn v8__Value__GetHash(this: *const Value) -> int; |
145 | | } |
146 | | |
147 | | impl Value { |
148 | | /// Returns true if this value is the undefined value. See ECMA-262 4.3.10. |
149 | 1.08k | pub fn is_undefined(&self) -> bool { |
150 | 1.08k | unsafe { v8__Value__IsUndefined(self) } |
151 | 1.08k | } |
152 | | |
153 | | /// Returns true if this value is the null value. See ECMA-262 4.3.11. |
154 | 0 | pub fn is_null(&self) -> bool { |
155 | 0 | unsafe { v8__Value__IsNull(self) } |
156 | 0 | } |
157 | | |
158 | | /// Returns true if this value is either the null or the undefined value. |
159 | | /// See ECMA-262 4.3.11. and 4.3.12 |
160 | 0 | pub fn is_null_or_undefined(&self) -> bool { |
161 | 0 | unsafe { v8__Value__IsNullOrUndefined(self) } |
162 | 0 | } |
163 | | |
164 | | /// Returns true if this value is true. |
165 | | /// This is not the same as `BooleanValue()`. The latter performs a |
166 | | /// conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas |
167 | | /// this checks `value === true`. |
168 | 0 | pub fn is_true(&self) -> bool { |
169 | 0 | unsafe { v8__Value__IsTrue(self) } |
170 | 0 | } |
171 | | |
172 | | /// Returns true if this value is false. |
173 | | /// This is not the same as `!BooleanValue()`. The latter performs a |
174 | | /// conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas |
175 | | /// this checks `value === false`. |
176 | 0 | pub fn is_false(&self) -> bool { |
177 | 0 | unsafe { v8__Value__IsFalse(self) } |
178 | 0 | } |
179 | | |
180 | | /// Returns true if this value is a symbol or a string. |
181 | | /// This is equivalent to |
182 | | /// `typeof value === 'string' || typeof value === 'symbol'` in JS. |
183 | 0 | pub fn is_name(&self) -> bool { |
184 | 0 | unsafe { v8__Value__IsName(self) } |
185 | 0 | } |
186 | | |
187 | | /// Returns true if this value is an instance of the String type. |
188 | | /// See ECMA-262 8.4. |
189 | 0 | pub fn is_string(&self) -> bool { |
190 | 0 | unsafe { v8__Value__IsString(self) } |
191 | 0 | } |
192 | | |
193 | | /// Returns true if this value is a symbol. |
194 | | /// This is equivalent to `typeof value === 'symbol'` in JS. |
195 | 0 | pub fn is_symbol(&self) -> bool { |
196 | 0 | unsafe { v8__Value__IsSymbol(self) } |
197 | 0 | } |
198 | | |
199 | | /// Returns true if this value is a function. |
200 | 0 | pub fn is_function(&self) -> bool { |
201 | 0 | unsafe { v8__Value__IsFunction(self) } |
202 | 0 | } |
203 | | |
204 | | /// Returns true if this value is an array. Note that it will return false for |
205 | | /// an Proxy for an array. |
206 | 1.82k | pub fn is_array(&self) -> bool { |
207 | 1.82k | unsafe { v8__Value__IsArray(self) } |
208 | 1.82k | } |
209 | | |
210 | | /// Returns true if this value is an object. |
211 | 0 | pub fn is_object(&self) -> bool { |
212 | 0 | unsafe { v8__Value__IsObject(self) } |
213 | 0 | } |
214 | | |
215 | | /// Returns true if this value is a bigint. |
216 | | /// This is equivalent to `typeof value === 'bigint'` in JS. |
217 | 0 | pub fn is_big_int(&self) -> bool { |
218 | 0 | unsafe { v8__Value__IsBigInt(self) } |
219 | 0 | } |
220 | | |
221 | | /// Returns true if this value is boolean. |
222 | | /// This is equivalent to `typeof value === 'boolean'` in JS. |
223 | 0 | pub fn is_boolean(&self) -> bool { |
224 | 0 | unsafe { v8__Value__IsBoolean(self) } |
225 | 0 | } |
226 | | |
227 | | /// Returns true if this value is a number. |
228 | 0 | pub fn is_number(&self) -> bool { |
229 | 0 | unsafe { v8__Value__IsNumber(self) } |
230 | 0 | } |
231 | | |
232 | | /// Returns true if this value is an `External` object. |
233 | 0 | pub fn is_external(&self) -> bool { |
234 | 0 | unsafe { v8__Value__IsExternal(self) } |
235 | 0 | } |
236 | | |
237 | | /// Returns true if this value is a 32-bit signed integer. |
238 | 0 | pub fn is_int32(&self) -> bool { |
239 | 0 | unsafe { v8__Value__IsInt32(self) } |
240 | 0 | } |
241 | | |
242 | | /// Returns true if this value is a 32-bit unsigned integer. |
243 | 0 | pub fn is_uint32(&self) -> bool { |
244 | 0 | unsafe { v8__Value__IsUint32(self) } |
245 | 0 | } |
246 | | |
247 | | /// Returns true if this value is a Date. |
248 | 0 | pub fn is_date(&self) -> bool { |
249 | 0 | unsafe { v8__Value__IsDate(self) } |
250 | 0 | } |
251 | | |
252 | | /// Returns true if this value is an Arguments object. |
253 | 0 | pub fn is_arguments_object(&self) -> bool { |
254 | 0 | unsafe { v8__Value__IsArgumentsObject(self) } |
255 | 0 | } |
256 | | |
257 | | /// Returns true if this value is a BigInt object. |
258 | 0 | pub fn is_big_int_object(&self) -> bool { |
259 | 0 | unsafe { v8__Value__IsBigIntObject(self) } |
260 | 0 | } |
261 | | |
262 | | /// Returns true if this value is a Boolean object. |
263 | 0 | pub fn is_boolean_object(&self) -> bool { |
264 | 0 | unsafe { v8__Value__IsBooleanObject(self) } |
265 | 0 | } |
266 | | |
267 | | /// Returns true if this value is a Number object. |
268 | 0 | pub fn is_number_object(&self) -> bool { |
269 | 0 | unsafe { v8__Value__IsNumberObject(self) } |
270 | 0 | } |
271 | | |
272 | | /// Returns true if this value is a String object. |
273 | 0 | pub fn is_string_object(&self) -> bool { |
274 | 0 | unsafe { v8__Value__IsStringObject(self) } |
275 | 0 | } |
276 | | |
277 | | /// Returns true if this value is a Symbol object. |
278 | 0 | pub fn is_symbol_object(&self) -> bool { |
279 | 0 | unsafe { v8__Value__IsSymbolObject(self) } |
280 | 0 | } |
281 | | |
282 | | /// Returns true if this value is a NativeError. |
283 | 0 | pub fn is_native_error(&self) -> bool { |
284 | 0 | unsafe { v8__Value__IsNativeError(self) } |
285 | 0 | } |
286 | | |
287 | | /// Returns true if this value is a RegExp. |
288 | 0 | pub fn is_reg_exp(&self) -> bool { |
289 | 0 | unsafe { v8__Value__IsRegExp(self) } |
290 | 0 | } |
291 | | |
292 | | /// Returns true if this value is an async function. |
293 | 0 | pub fn is_async_function(&self) -> bool { |
294 | 0 | unsafe { v8__Value__IsAsyncFunction(self) } |
295 | 0 | } |
296 | | |
297 | | /// Returns true if this value is a Generator function. |
298 | 0 | pub fn is_generator_function(&self) -> bool { |
299 | 0 | unsafe { v8__Value__IsGeneratorFunction(self) } |
300 | 0 | } |
301 | | |
302 | | /// Returns true if this value is a Promise. |
303 | 0 | pub fn is_promise(&self) -> bool { |
304 | 0 | unsafe { v8__Value__IsPromise(self) } |
305 | 0 | } |
306 | | |
307 | | /// Returns true if this value is a Map. |
308 | 0 | pub fn is_map(&self) -> bool { |
309 | 0 | unsafe { v8__Value__IsMap(self) } |
310 | 0 | } |
311 | | |
312 | | /// Returns true if this value is a Set. |
313 | 0 | pub fn is_set(&self) -> bool { |
314 | 0 | unsafe { v8__Value__IsSet(self) } |
315 | 0 | } |
316 | | |
317 | | /// Returns true if this value is a Map Iterator. |
318 | 0 | pub fn is_map_iterator(&self) -> bool { |
319 | 0 | unsafe { v8__Value__IsMapIterator(self) } |
320 | 0 | } |
321 | | |
322 | | /// Returns true if this value is a Set Iterator. |
323 | 0 | pub fn is_set_iterator(&self) -> bool { |
324 | 0 | unsafe { v8__Value__IsSetIterator(self) } |
325 | 0 | } |
326 | | |
327 | | /// Returns true if this value is a WeakMap. |
328 | 0 | pub fn is_weak_map(&self) -> bool { |
329 | 0 | unsafe { v8__Value__IsWeakMap(self) } |
330 | 0 | } |
331 | | |
332 | | /// Returns true if this value is a WeakSet. |
333 | 0 | pub fn is_weak_set(&self) -> bool { |
334 | 0 | unsafe { v8__Value__IsWeakSet(self) } |
335 | 0 | } |
336 | | |
337 | | /// Returns true if this value is an ArrayBuffer. |
338 | 5.26k | pub fn is_array_buffer(&self) -> bool { |
339 | 5.26k | unsafe { v8__Value__IsArrayBuffer(self) } |
340 | 5.26k | } |
341 | | |
342 | | /// Returns true if this value is an ArrayBufferView. |
343 | 0 | pub fn is_array_buffer_view(&self) -> bool { |
344 | 0 | unsafe { v8__Value__IsArrayBufferView(self) } |
345 | 0 | } |
346 | | |
347 | | /// Returns true if this value is one of TypedArrays. |
348 | 0 | pub fn is_typed_array(&self) -> bool { |
349 | 0 | unsafe { v8__Value__IsTypedArray(self) } |
350 | 0 | } |
351 | | |
352 | | /// Returns true if this value is an Uint8Array. |
353 | 0 | pub fn is_uint8_array(&self) -> bool { |
354 | 0 | unsafe { v8__Value__IsUint8Array(self) } |
355 | 0 | } |
356 | | |
357 | | /// Returns true if this value is an Uint8ClampedArray. |
358 | 0 | pub fn is_uint8_clamped_array(&self) -> bool { |
359 | 0 | unsafe { v8__Value__IsUint8ClampedArray(self) } |
360 | 0 | } |
361 | | |
362 | | /// Returns true if this value is an Int8Array. |
363 | 0 | pub fn is_int8_array(&self) -> bool { |
364 | 0 | unsafe { v8__Value__IsInt8Array(self) } |
365 | 0 | } |
366 | | |
367 | | /// Returns true if this value is an Uint16Array. |
368 | 0 | pub fn is_uint16_array(&self) -> bool { |
369 | 0 | unsafe { v8__Value__IsUint16Array(self) } |
370 | 0 | } |
371 | | |
372 | | /// Returns true if this value is an Int16Array. |
373 | 0 | pub fn is_int16_array(&self) -> bool { |
374 | 0 | unsafe { v8__Value__IsInt16Array(self) } |
375 | 0 | } |
376 | | |
377 | | /// Returns true if this value is an Uint32Array. |
378 | 0 | pub fn is_uint32_array(&self) -> bool { |
379 | 0 | unsafe { v8__Value__IsUint32Array(self) } |
380 | 0 | } |
381 | | |
382 | | /// Returns true if this value is an Int32Array. |
383 | 0 | pub fn is_int32_array(&self) -> bool { |
384 | 0 | unsafe { v8__Value__IsInt32Array(self) } |
385 | 0 | } |
386 | | |
387 | | /// Returns true if this value is a Float32Array. |
388 | 0 | pub fn is_float32_array(&self) -> bool { |
389 | 0 | unsafe { v8__Value__IsFloat32Array(self) } |
390 | 0 | } |
391 | | |
392 | | /// Returns true if this value is a Float64Array. |
393 | 0 | pub fn is_float64_array(&self) -> bool { |
394 | 0 | unsafe { v8__Value__IsFloat64Array(self) } |
395 | 0 | } |
396 | | |
397 | | /// Returns true if this value is a BigInt64Array. |
398 | 0 | pub fn is_big_int64_array(&self) -> bool { |
399 | 0 | unsafe { v8__Value__IsBigInt64Array(self) } |
400 | 0 | } |
401 | | |
402 | | /// Returns true if this value is a BigUint64Array. |
403 | 0 | pub fn is_big_uint64_array(&self) -> bool { |
404 | 0 | unsafe { v8__Value__IsBigUint64Array(self) } |
405 | 0 | } |
406 | | |
407 | | /// Returns true if this value is a DataView. |
408 | 0 | pub fn is_data_view(&self) -> bool { |
409 | 0 | unsafe { v8__Value__IsDataView(self) } |
410 | 0 | } |
411 | | |
412 | | /// Returns true if this value is a SharedArrayBuffer. |
413 | | /// This is an experimental feature. |
414 | 395 | pub fn is_shared_array_buffer(&self) -> bool { |
415 | 395 | unsafe { v8__Value__IsSharedArrayBuffer(self) } |
416 | 395 | } |
417 | | |
418 | | /// Returns true if this value is a JavaScript Proxy. |
419 | 0 | pub fn is_proxy(&self) -> bool { |
420 | 0 | unsafe { v8__Value__IsProxy(self) } |
421 | 0 | } |
422 | | |
423 | | /// Returns true if this value is a WasmMemoryObject. |
424 | 0 | pub fn is_wasm_memory_object(&self) -> bool { |
425 | 0 | unsafe { v8__Value__IsWasmMemoryObject(self) } |
426 | 0 | } |
427 | | |
428 | | /// Returns true if this value is a WasmModuleObject. |
429 | 0 | pub fn is_wasm_module_object(&self) -> bool { |
430 | 0 | unsafe { v8__Value__IsWasmModuleObject(self) } |
431 | 0 | } |
432 | | |
433 | | /// Returns true if the value is a Module Namespace Object. |
434 | 0 | pub fn is_module_namespace_object(&self) -> bool { |
435 | 0 | unsafe { v8__Value__IsModuleNamespaceObject(self) } |
436 | 0 | } |
437 | | |
438 | 0 | pub fn strict_equals(&self, that: Local<Value>) -> bool { |
439 | 0 | unsafe { v8__Value__StrictEquals(self, &*that) } |
440 | 0 | } |
441 | | |
442 | 0 | pub fn same_value(&self, that: Local<Value>) -> bool { |
443 | 0 | unsafe { v8__Value__SameValue(self, &*that) } |
444 | 0 | } |
445 | | |
446 | | /// Implements the the abstract operation `SameValueZero`, which is defined in |
447 | | /// ECMA-262 6th edition ยง 7.2.10 |
448 | | /// (http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero). |
449 | | /// |
450 | | /// This operation is used to compare values for the purpose of insertion into |
451 | | /// a `Set`, or determining whether `Map` keys are equivalent. Its semantics |
452 | | /// are almost the same as `strict_equals()` and `same_value()`, with the |
453 | | /// following important distinctions: |
454 | | /// - It considers `NaN` equal to `NaN` (unlike `strict_equals()`). |
455 | | /// - It considers `-0` equal to `0` (unlike `same_value()`). |
456 | 0 | pub fn same_value_zero(&self, that: Local<Value>) -> bool { |
457 | 0 | // The SMI representation of zero is also zero. In debug builds, double |
458 | 0 | // check this, so in the unlikely event that V8 changes its internal |
459 | 0 | // representation of SMIs such that this invariant no longer holds, we'd |
460 | 0 | // catch it. |
461 | 0 | self.same_value(that) || { |
462 | 0 | let zero = Integer::zero().into(); |
463 | 0 | self.strict_equals(zero) && that.strict_equals(zero) |
464 | | } |
465 | 0 | } |
466 | | |
467 | 3.70k | pub fn to_big_int<'s>( |
468 | 3.70k | &self, |
469 | 3.70k | scope: &mut HandleScope<'s>, |
470 | 3.70k | ) -> Option<Local<'s, BigInt>> { |
471 | 3.70k | unsafe { |
472 | 3.70k | scope |
473 | 3.70k | .cast_local(|sd| v8__Value__ToBigInt(self, &*sd.get_current_context())) |
474 | 3.70k | } |
475 | 3.70k | } |
476 | | |
477 | 24.7k | pub fn to_number<'s>( |
478 | 24.7k | &self, |
479 | 24.7k | scope: &mut HandleScope<'s>, |
480 | 24.7k | ) -> Option<Local<'s, Number>> { |
481 | 24.7k | unsafe { |
482 | 24.7k | scope |
483 | 24.7k | .cast_local(|sd| v8__Value__ToNumber(self, &*sd.get_current_context())) |
484 | 24.7k | } |
485 | 24.7k | } |
486 | | |
487 | 0 | pub fn to_string<'s>( |
488 | 0 | &self, |
489 | 0 | scope: &mut HandleScope<'s>, |
490 | 0 | ) -> Option<Local<'s, String>> { |
491 | 0 | unsafe { |
492 | 0 | scope |
493 | 0 | .cast_local(|sd| v8__Value__ToString(self, &*sd.get_current_context())) |
494 | 0 | } |
495 | 0 | } |
496 | | |
497 | | /// Convenience function not present in the original V8 API. |
498 | 0 | pub fn to_rust_string_lossy<'s>( |
499 | 0 | &self, |
500 | 0 | scope: &mut HandleScope<'s>, |
501 | 0 | ) -> std::string::String { |
502 | 0 | self |
503 | 0 | .to_string(scope) |
504 | 0 | .map_or_else(std::string::String::new, |s| s.to_rust_string_lossy(scope)) |
505 | 0 | } |
506 | | |
507 | 0 | pub fn to_detail_string<'s>( |
508 | 0 | &self, |
509 | 0 | scope: &mut HandleScope<'s>, |
510 | 0 | ) -> Option<Local<'s, String>> { |
511 | 0 | unsafe { |
512 | 0 | scope.cast_local(|sd| { |
513 | 0 | v8__Value__ToDetailString(self, &*sd.get_current_context()) |
514 | 0 | }) |
515 | 0 | } |
516 | 0 | } |
517 | | |
518 | 0 | pub fn to_object<'s>( |
519 | 0 | &self, |
520 | 0 | scope: &mut HandleScope<'s>, |
521 | 0 | ) -> Option<Local<'s, Object>> { |
522 | 0 | unsafe { |
523 | 0 | scope |
524 | 0 | .cast_local(|sd| v8__Value__ToObject(self, &*sd.get_current_context())) |
525 | 0 | } |
526 | 0 | } |
527 | | |
528 | 0 | pub fn to_integer<'s>( |
529 | 0 | &self, |
530 | 0 | scope: &mut HandleScope<'s>, |
531 | 0 | ) -> Option<Local<'s, Integer>> { |
532 | 0 | unsafe { |
533 | 0 | scope |
534 | 0 | .cast_local(|sd| v8__Value__ToInteger(self, &*sd.get_current_context())) |
535 | 0 | } |
536 | 0 | } |
537 | | |
538 | 0 | pub fn to_uint32<'s>( |
539 | 0 | &self, |
540 | 0 | scope: &mut HandleScope<'s>, |
541 | 0 | ) -> Option<Local<'s, Uint32>> { |
542 | 0 | unsafe { |
543 | 0 | scope |
544 | 0 | .cast_local(|sd| v8__Value__ToUint32(self, &*sd.get_current_context())) |
545 | 0 | } |
546 | 0 | } |
547 | | |
548 | 9.95k | pub fn to_int32<'s>( |
549 | 9.95k | &self, |
550 | 9.95k | scope: &mut HandleScope<'s>, |
551 | 9.95k | ) -> Option<Local<'s, Int32>> { |
552 | 9.95k | unsafe { |
553 | 9.95k | scope |
554 | 9.95k | .cast_local(|sd| v8__Value__ToInt32(self, &*sd.get_current_context())) |
555 | 9.95k | } |
556 | 9.95k | } |
557 | | |
558 | | /// Perform the equivalent of Boolean(value) in JS. This can never fail. |
559 | 0 | pub fn to_boolean<'s>( |
560 | 0 | &self, |
561 | 0 | scope: &mut HandleScope<'s, ()>, |
562 | 0 | ) -> Local<'s, Boolean> { |
563 | 0 | unsafe { |
564 | 0 | scope.cast_local(|sd| v8__Value__ToBoolean(self, sd.get_isolate_ptr())) |
565 | 0 | } |
566 | 0 | .unwrap() |
567 | 0 | } |
568 | | |
569 | 0 | pub fn instance_of<'s>( |
570 | 0 | &self, |
571 | 0 | scope: &mut HandleScope<'s>, |
572 | 0 | object: Local<Object>, |
573 | 0 | ) -> Option<bool> { |
574 | 0 | let mut out = Maybe::<bool>::default(); |
575 | 0 | unsafe { |
576 | 0 | v8__Value__InstanceOf( |
577 | 0 | self, |
578 | 0 | &*scope.get_current_context(), |
579 | 0 | &*object, |
580 | 0 | &mut out, |
581 | 0 | ); |
582 | 0 | } |
583 | 0 | out.into() |
584 | 0 | } |
585 | | |
586 | 0 | pub fn number_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<f64> { |
587 | 0 | let mut out = Maybe::<f64>::default(); |
588 | 0 | unsafe { |
589 | 0 | v8__Value__NumberValue(self, &*scope.get_current_context(), &mut out) |
590 | 0 | }; |
591 | 0 | out.into() |
592 | 0 | } |
593 | | |
594 | 0 | pub fn integer_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i64> { |
595 | 0 | let mut out = Maybe::<i64>::default(); |
596 | 0 | unsafe { |
597 | 0 | v8__Value__IntegerValue(self, &*scope.get_current_context(), &mut out) |
598 | 0 | }; |
599 | 0 | out.into() |
600 | 0 | } |
601 | | |
602 | 0 | pub fn uint32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<u32> { |
603 | 0 | let mut out = Maybe::<u32>::default(); |
604 | 0 | unsafe { |
605 | 0 | v8__Value__Uint32Value(self, &*scope.get_current_context(), &mut out) |
606 | 0 | }; |
607 | 0 | out.into() |
608 | 0 | } |
609 | | |
610 | 0 | pub fn int32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i32> { |
611 | 0 | let mut out = Maybe::<i32>::default(); |
612 | 0 | unsafe { |
613 | 0 | v8__Value__Int32Value(self, &*scope.get_current_context(), &mut out) |
614 | 0 | }; |
615 | 0 | out.into() |
616 | 0 | } |
617 | | |
618 | 0 | pub fn boolean_value<'s>(&self, scope: &mut HandleScope<'s, ()>) -> bool { |
619 | 0 | unsafe { v8__Value__BooleanValue(self, scope.get_isolate_ptr()) } |
620 | 0 | } |
621 | | |
622 | | /// Returns the V8 hash value for this value. The current implementation |
623 | | /// uses a hidden property to store the identity hash on some object types. |
624 | | /// |
625 | | /// The return value will never be 0. Also, it is not guaranteed to be |
626 | | /// unique. |
627 | 0 | pub fn get_hash(&self) -> NonZeroI32 { |
628 | 0 | unsafe { NonZeroI32::new_unchecked(v8__Value__GetHash(self)) } |
629 | 0 | } |
630 | | } |