1/*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003-2019 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "JSExportMacros.h"
26#include "PureNaN.h"
27#include <functional>
28#include <math.h>
29#include <stddef.h>
30#include <stdint.h>
31#include <wtf/Assertions.h>
32#include <wtf/Forward.h>
33#include <wtf/HashMap.h>
34#include <wtf/HashTraits.h>
35#include <wtf/MathExtras.h>
36#include <wtf/MediaTime.h>
37#include <wtf/StdLibExtras.h>
38#include <wtf/TriState.h>
39
40namespace JSC {
41
42class AssemblyHelpers;
43class JSBigInt;
44class ExecState;
45class JSCell;
46class JSValueSource;
47class VM;
48class JSGlobalObject;
49class JSObject;
50class JSString;
51class Identifier;
52class PropertyName;
53class PropertySlot;
54class PutPropertySlot;
55class Structure;
56#if ENABLE(DFG_JIT)
57namespace DFG {
58class JITCompiler;
59class OSRExitCompiler;
60class SpeculativeJIT;
61}
62#endif
63#if ENABLE(C_LOOP)
64namespace LLInt {
65class CLoop;
66}
67#endif
68
69struct ClassInfo;
70struct DumpContext;
71struct Instruction;
72struct MethodTable;
73enum class Unknown { };
74
75template <class T, typename Traits> class WriteBarrierBase;
76template<class T>
77using WriteBarrierTraitsSelect = typename std::conditional<std::is_same<T, Unknown>::value,
78 DumbValueTraits<T>, DumbPtrTraits<T>
79>::type;
80
81enum PreferredPrimitiveType { NoPreference, PreferNumber, PreferString };
82enum ECMAMode { StrictMode, NotStrictMode };
83
84enum class CallType : unsigned;
85struct CallData;
86enum class ConstructType : unsigned;
87struct ConstructData;
88
89typedef int64_t EncodedJSValue;
90
91union EncodedValueDescriptor {
92 int64_t asInt64;
93#if USE(JSVALUE32_64)
94 double asDouble;
95#elif USE(JSVALUE64)
96 JSCell* ptr;
97#endif
98
99#if CPU(BIG_ENDIAN)
100 struct {
101 int32_t tag;
102 int32_t payload;
103 } asBits;
104#else
105 struct {
106 int32_t payload;
107 int32_t tag;
108 } asBits;
109#endif
110};
111
112#define TagOffset (offsetof(EncodedValueDescriptor, asBits.tag))
113#define PayloadOffset (offsetof(EncodedValueDescriptor, asBits.payload))
114
115#if USE(JSVALUE64)
116#define CellPayloadOffset 0
117#else
118#define CellPayloadOffset PayloadOffset
119#endif
120
121enum WhichValueWord {
122 TagWord,
123 PayloadWord
124};
125
126int64_t tryConvertToInt52(double);
127bool isInt52(double);
128
129enum class SourceCodeRepresentation : uint8_t {
130 Other,
131 Integer,
132 Double
133};
134
135class JSValue {
136 friend struct EncodedJSValueHashTraits;
137 friend struct EncodedJSValueWithRepresentationHashTraits;
138 friend class AssemblyHelpers;
139 friend class JIT;
140 friend class JITSlowPathCall;
141 friend class JITStubs;
142 friend class JITStubCall;
143 friend class JSInterfaceJIT;
144 friend class JSValueSource;
145 friend class SpecializedThunkJIT;
146#if ENABLE(DFG_JIT)
147 friend class DFG::JITCompiler;
148 friend class DFG::OSRExitCompiler;
149 friend class DFG::SpeculativeJIT;
150#endif
151#if ENABLE(C_LOOP)
152 friend class LLInt::CLoop;
153#endif
154
155public:
156#if USE(JSVALUE32_64)
157 enum { Int32Tag = 0xffffffff };
158 enum { BooleanTag = 0xfffffffe };
159 enum { NullTag = 0xfffffffd };
160 enum { UndefinedTag = 0xfffffffc };
161 enum { CellTag = 0xfffffffb };
162 enum { EmptyValueTag = 0xfffffffa };
163 enum { DeletedValueTag = 0xfffffff9 };
164
165 enum { LowestTag = DeletedValueTag };
166
167#endif
168
169 static EncodedJSValue encode(JSValue);
170 static JSValue decode(EncodedJSValue);
171
172 enum JSNullTag { JSNull };
173 enum JSUndefinedTag { JSUndefined };
174 enum JSTrueTag { JSTrue };
175 enum JSFalseTag { JSFalse };
176 enum JSCellTag { JSCellType };
177 enum EncodeAsDoubleTag { EncodeAsDouble };
178
179 JSValue();
180 JSValue(JSNullTag);
181 JSValue(JSUndefinedTag);
182 JSValue(JSTrueTag);
183 JSValue(JSFalseTag);
184 JSValue(JSCell* ptr);
185 JSValue(const JSCell* ptr);
186
187 // Numbers
188 JSValue(EncodeAsDoubleTag, double);
189 explicit JSValue(double);
190 explicit JSValue(char);
191 explicit JSValue(unsigned char);
192 explicit JSValue(short);
193 explicit JSValue(unsigned short);
194 explicit JSValue(int);
195 explicit JSValue(unsigned);
196 explicit JSValue(long);
197 explicit JSValue(unsigned long);
198 explicit JSValue(long long);
199 explicit JSValue(unsigned long long);
200
201 explicit operator bool() const;
202 bool operator==(const JSValue& other) const;
203 bool operator!=(const JSValue& other) const;
204
205 bool isInt32() const;
206 bool isUInt32() const;
207 bool isDouble() const;
208 bool isTrue() const;
209 bool isFalse() const;
210
211 int32_t asInt32() const;
212 uint32_t asUInt32() const;
213 int64_t asAnyInt() const;
214 double asDouble() const;
215 bool asBoolean() const;
216 double asNumber() const;
217
218 int32_t asInt32ForArithmetic() const; // Boolean becomes an int, but otherwise like asInt32().
219
220 // Querying the type.
221 bool isEmpty() const;
222 bool isFunction(VM&) const;
223 bool isCallable(VM&, CallType&, CallData&) const;
224 bool isConstructor(VM&) const;
225 bool isConstructor(VM&, ConstructType&, ConstructData&) const;
226 bool isUndefined() const;
227 bool isNull() const;
228 bool isUndefinedOrNull() const;
229 bool isBoolean() const;
230 bool isAnyInt() const;
231 bool isNumber() const;
232 bool isString() const;
233 bool isBigInt() const;
234 bool isSymbol() const;
235 bool isPrimitive() const;
236 bool isGetterSetter() const;
237 bool isCustomGetterSetter() const;
238 bool isObject() const;
239 bool inherits(VM&, const ClassInfo*) const;
240 template<typename Target> bool inherits(VM&) const;
241 const ClassInfo* classInfoOrNull(VM&) const;
242
243 // Extracting the value.
244 bool getString(ExecState*, WTF::String&) const;
245 WTF::String getString(ExecState*) const; // null string if not a string
246 JSObject* getObject() const; // 0 if not an object
247
248 // Extracting integer values.
249 bool getUInt32(uint32_t&) const;
250
251 // Basic conversions.
252 JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
253 bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
254
255 bool toBoolean(ExecState*) const;
256 TriState pureToBoolean() const;
257
258 // toNumber conversion is expected to be side effect free if an exception has
259 // been set in the ExecState already.
260 double toNumber(ExecState*) const;
261
262 Variant<JSBigInt*, double> toNumeric(ExecState*) const;
263 Variant<JSBigInt*, int32_t> toBigIntOrInt32(ExecState*) const;
264
265 // toNumber conversion if it can be done without side effects.
266 Optional<double> toNumberFromPrimitive() const;
267
268 JSString* toString(ExecState*) const; // On exception, this returns the empty string.
269 JSString* toStringOrNull(ExecState*) const; // On exception, this returns null, to make exception checks faster.
270 Identifier toPropertyKey(ExecState*) const;
271 WTF::String toWTFString(ExecState*) const;
272 JSObject* toObject(ExecState*) const;
273 JSObject* toObject(ExecState*, JSGlobalObject*) const;
274
275 // Integer conversions.
276 JS_EXPORT_PRIVATE double toInteger(ExecState*) const;
277 JS_EXPORT_PRIVATE double toIntegerPreserveNaN(ExecState*) const;
278 int32_t toInt32(ExecState*) const;
279 uint32_t toUInt32(ExecState*) const;
280 uint32_t toIndex(ExecState*, const char* errorName) const;
281 double toLength(ExecState*) const;
282
283 // Floating point conversions (this is a convenience function for WebCore;
284 // single precision float is not a representation used in JS or JSC).
285 float toFloat(ExecState* exec) const { return static_cast<float>(toNumber(exec)); }
286
287 // Object operations, with the toObject operation included.
288 JSValue get(ExecState*, PropertyName) const;
289 JSValue get(ExecState*, PropertyName, PropertySlot&) const;
290 JSValue get(ExecState*, unsigned propertyName) const;
291 JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const;
292 JSValue get(ExecState*, uint64_t propertyName) const;
293
294 bool getPropertySlot(ExecState*, PropertyName, PropertySlot&) const;
295 template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, CallbackWhenNoException) const;
296 template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, PropertySlot&, CallbackWhenNoException) const;
297
298 bool getOwnPropertySlot(ExecState*, PropertyName, PropertySlot&) const;
299
300 bool put(ExecState*, PropertyName, JSValue, PutPropertySlot&);
301 bool putInline(ExecState*, PropertyName, JSValue, PutPropertySlot&);
302 JS_EXPORT_PRIVATE bool putToPrimitive(ExecState*, PropertyName, JSValue, PutPropertySlot&);
303 JS_EXPORT_PRIVATE bool putToPrimitiveByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
304 bool putByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
305
306 JSValue toThis(ExecState*, ECMAMode) const;
307
308 static bool equal(ExecState*, JSValue v1, JSValue v2);
309 static bool equalSlowCase(ExecState*, JSValue v1, JSValue v2);
310 static bool equalSlowCaseInline(ExecState*, JSValue v1, JSValue v2);
311 static bool strictEqual(ExecState*, JSValue v1, JSValue v2);
312 static bool strictEqualSlowCase(ExecState*, JSValue v1, JSValue v2);
313 static bool strictEqualSlowCaseInline(ExecState*, JSValue v1, JSValue v2);
314 static TriState pureStrictEqual(JSValue v1, JSValue v2);
315
316 bool isCell() const;
317 JSCell* asCell() const;
318 JS_EXPORT_PRIVATE bool isValidCallee();
319
320 Structure* structureOrNull() const;
321 JSValue structureOrUndefined() const;
322
323 JS_EXPORT_PRIVATE void dump(PrintStream&) const;
324 void dumpInContext(PrintStream&, DumpContext*) const;
325 void dumpInContextAssumingStructure(PrintStream&, DumpContext*, Structure*) const;
326 void dumpForBacktrace(PrintStream&) const;
327
328 JS_EXPORT_PRIVATE JSObject* synthesizePrototype(ExecState*) const;
329 bool requireObjectCoercible(ExecState*) const;
330
331 // Constants used for Int52. Int52 isn't part of JSValue right now, but JSValues may be
332 // converted to Int52s and back again.
333 static constexpr const unsigned numberOfInt52Bits = 52;
334 static constexpr const int64_t notInt52 = static_cast<int64_t>(1) << numberOfInt52Bits;
335 static constexpr const unsigned int52ShiftAmount = 12;
336
337 static ptrdiff_t offsetOfPayload() { return OBJECT_OFFSETOF(JSValue, u.asBits.payload); }
338 static ptrdiff_t offsetOfTag() { return OBJECT_OFFSETOF(JSValue, u.asBits.tag); }
339
340#if USE(JSVALUE32_64)
341 /*
342 * On 32-bit platforms USE(JSVALUE32_64) should be defined, and we use a NaN-encoded
343 * form for immediates.
344 *
345 * The encoding makes use of unused NaN space in the IEEE754 representation. Any value
346 * with the top 13 bits set represents a QNaN (with the sign bit set). QNaN values
347 * can encode a 51-bit payload. Hardware produced and C-library payloads typically
348 * have a payload of zero. We assume that non-zero payloads are available to encode
349 * pointer and integer values. Since any 64-bit bit pattern where the top 15 bits are
350 * all set represents a NaN with a non-zero payload, we can use this space in the NaN
351 * ranges to encode other values (however there are also other ranges of NaN space that
352 * could have been selected).
353 *
354 * For JSValues that do not contain a double value, the high 32 bits contain the tag
355 * values listed in the enums below, which all correspond to NaN-space. In the case of
356 * cell, integer and bool values the lower 32 bits (the 'payload') contain the pointer
357 * integer or boolean value; in the case of all other tags the payload is 0.
358 */
359 uint32_t tag() const;
360 int32_t payload() const;
361
362 // This should only be used by the LLInt C Loop interpreter and OSRExit code who needs
363 // synthesize JSValue from its "register"s holding tag and payload values.
364 explicit JSValue(int32_t tag, int32_t payload);
365
366#elif USE(JSVALUE64)
367 /*
368 * On 64-bit platforms USE(JSVALUE64) should be defined, and we use a NaN-encoded
369 * form for immediates.
370 *
371 * The encoding makes use of unused NaN space in the IEEE754 representation. Any value
372 * with the top 13 bits set represents a QNaN (with the sign bit set). QNaN values
373 * can encode a 51-bit payload. Hardware produced and C-library payloads typically
374 * have a payload of zero. We assume that non-zero payloads are available to encode
375 * pointer and integer values. Since any 64-bit bit pattern where the top 15 bits are
376 * all set represents a NaN with a non-zero payload, we can use this space in the NaN
377 * ranges to encode other values (however there are also other ranges of NaN space that
378 * could have been selected).
379 *
380 * This range of NaN space is represented by 64-bit numbers begining with the 16-bit
381 * hex patterns 0xFFFE and 0xFFFF - we rely on the fact that no valid double-precision
382 * numbers will fall in these ranges.
383 *
384 * The top 16-bits denote the type of the encoded JSValue:
385 *
386 * Pointer { 0000:PPPP:PPPP:PPPP
387 * / 0001:****:****:****
388 * Double { ...
389 * \ FFFE:****:****:****
390 * Integer { FFFF:0000:IIII:IIII
391 *
392 * The scheme we have implemented encodes double precision values by performing a
393 * 64-bit integer addition of the value 2^48 to the number. After this manipulation
394 * no encoded double-precision value will begin with the pattern 0x0000 or 0xFFFF.
395 * Values must be decoded by reversing this operation before subsequent floating point
396 * operations may be peformed.
397 *
398 * 32-bit signed integers are marked with the 16-bit tag 0xFFFF.
399 *
400 * The tag 0x0000 denotes a pointer, or another form of tagged immediate. Boolean,
401 * null and undefined values are represented by specific, invalid pointer values:
402 *
403 * False: 0x06
404 * True: 0x07
405 * Undefined: 0x0a
406 * Null: 0x02
407 *
408 * These values have the following properties:
409 * - Bit 1 (TagBitTypeOther) is set for all four values, allowing real pointers to be
410 * quickly distinguished from all immediate values, including these invalid pointers.
411 * - With bit 3 is masked out (TagBitUndefined) Undefined and Null share the
412 * same value, allowing null & undefined to be quickly detected.
413 *
414 * No valid JSValue will have the bit pattern 0x0, this is used to represent array
415 * holes, and as a C++ 'no value' result (e.g. JSValue() has an internal value of 0).
416 */
417
418 // These values are #defines since using static const integers here is a ~1% regression!
419
420 // This value is 2^48, used to encode doubles such that the encoded value will begin
421 // with a 16-bit pattern within the range 0x0001..0xFFFE.
422 #define DoubleEncodeOffset 0x1000000000000ll
423 // If all bits in the mask are set, this indicates an integer number,
424 // if any but not all are set this value is a double precision number.
425 #define TagTypeNumber 0xffff000000000000ll
426
427 // All non-numeric (bool, null, undefined) immediates have bit 2 set.
428 #define TagBitTypeOther 0x2ll
429 #define TagBitBool 0x4ll
430 #define TagBitUndefined 0x8ll
431 // Combined integer value for non-numeric immediates.
432 #define ValueFalse (TagBitTypeOther | TagBitBool | false)
433 #define ValueTrue (TagBitTypeOther | TagBitBool | true)
434 #define ValueUndefined (TagBitTypeOther | TagBitUndefined)
435 #define ValueNull (TagBitTypeOther)
436
437 // TagMask is used to check for all types of immediate values (either number or 'other').
438 #define TagMask (TagTypeNumber | TagBitTypeOther)
439
440 // These special values are never visible to JavaScript code; Empty is used to represent
441 // Array holes, and for uninitialized JSValues. Deleted is used in hash table code.
442 // These values would map to cell types in the JSValue encoding, but not valid GC cell
443 // pointer should have either of these values (Empty is null, deleted is at an invalid
444 // alignment for a GC cell, and in the zero page).
445 #define ValueEmpty 0x0ll
446 #define ValueDeleted 0x4ll
447
448 #define TagBitsWasm (TagBitTypeOther | 0x1)
449 #define TagWasmMask (TagTypeNumber | 0x7)
450 // We tag Wasm non-JSCell pointers with a 3 at the bottom. We can test if a 64-bit JSValue pattern
451 // is a Wasm callee by masking the upper 16 bits and the lower 3 bits, and seeing if
452 // the resulting value is 3. The full test is: x & TagWasmMask == TagBitsWasm
453 // This works because the lower 3 bits of the non-number immediate values are as follows:
454 // undefined: 0b010
455 // null: 0b010
456 // true: 0b111
457 // false: 0b110
458 // The test rejects all of these because none have just the value 3 in their lower 3 bits.
459 // The test rejects all numbers because they have non-zero upper 16 bits.
460 // The test also rejects normal cells because they won't have the number 3 as
461 // their lower 3 bits. Note, this bit pattern also allows the normal JSValue isCell(), etc,
462 // predicates to work on a Wasm::Callee because the various tests will fail if you
463 // bit casted a boxed Wasm::Callee* to a JSValue. isCell() would fail since it sees
464 // TagBitTypeOther. The other tests also trivially fail, since it won't be a number,
465 // and it won't be equal to null, undefined, true, or false. The isBoolean() predicate
466 // will fail because we won't have TagBitBool set.
467#endif
468
469private:
470 template <class T> JSValue(WriteBarrierBase<T, WriteBarrierTraitsSelect<T>>);
471
472 enum HashTableDeletedValueTag { HashTableDeletedValue };
473 JSValue(HashTableDeletedValueTag);
474
475 inline const JSValue asValue() const { return *this; }
476 JS_EXPORT_PRIVATE double toNumberSlowCase(ExecState*) const;
477 JS_EXPORT_PRIVATE JSString* toStringSlowCase(ExecState*, bool returnEmptyStringOnError) const;
478 JS_EXPORT_PRIVATE WTF::String toWTFStringSlowCase(ExecState*) const;
479 JS_EXPORT_PRIVATE JSObject* toObjectSlowCase(ExecState*, JSGlobalObject*) const;
480 JS_EXPORT_PRIVATE JSValue toThisSlowCase(ExecState*, ECMAMode) const;
481
482 EncodedValueDescriptor u;
483};
484
485typedef IntHash<EncodedJSValue> EncodedJSValueHash;
486
487#if USE(JSVALUE32_64)
488struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
489 static const bool emptyValueIsZero = false;
490 static EncodedJSValue emptyValue() { return JSValue::encode(JSValue()); }
491 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
492 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
493};
494#else
495struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
496 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
497 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
498};
499#endif
500
501typedef std::pair<EncodedJSValue, SourceCodeRepresentation> EncodedJSValueWithRepresentation;
502
503struct EncodedJSValueWithRepresentationHashTraits : HashTraits<EncodedJSValueWithRepresentation> {
504 static const bool emptyValueIsZero = false;
505 static EncodedJSValueWithRepresentation emptyValue() { return std::make_pair(JSValue::encode(JSValue()), SourceCodeRepresentation::Other); }
506 static void constructDeletedValue(EncodedJSValueWithRepresentation& slot) { slot = std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); }
507 static bool isDeletedValue(EncodedJSValueWithRepresentation value) { return value == std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); }
508};
509
510struct EncodedJSValueWithRepresentationHash {
511 static unsigned hash(const EncodedJSValueWithRepresentation& value)
512 {
513 return WTF::pairIntHash(EncodedJSValueHash::hash(value.first), IntHash<SourceCodeRepresentation>::hash(value.second));
514 }
515 static bool equal(const EncodedJSValueWithRepresentation& a, const EncodedJSValueWithRepresentation& b)
516 {
517 return a == b;
518 }
519 static const bool safeToCompareToEmptyOrDeleted = true;
520};
521
522// Stand-alone helper functions.
523inline JSValue jsNull()
524{
525 return JSValue(JSValue::JSNull);
526}
527
528inline JSValue jsUndefined()
529{
530 return JSValue(JSValue::JSUndefined);
531}
532
533inline JSValue jsTDZValue()
534{
535 return JSValue();
536}
537
538inline JSValue jsBoolean(bool b)
539{
540 return b ? JSValue(JSValue::JSTrue) : JSValue(JSValue::JSFalse);
541}
542
543ALWAYS_INLINE JSValue jsDoubleNumber(double d)
544{
545 ASSERT(JSValue(JSValue::EncodeAsDouble, d).isNumber());
546 return JSValue(JSValue::EncodeAsDouble, d);
547}
548
549ALWAYS_INLINE JSValue jsNumber(double d)
550{
551 ASSERT(JSValue(d).isNumber());
552 ASSERT(!isImpureNaN(d));
553 return JSValue(d);
554}
555
556ALWAYS_INLINE JSValue jsNumber(const MediaTime& t)
557{
558 return jsNumber(t.toDouble());
559}
560
561ALWAYS_INLINE JSValue jsNumber(char i)
562{
563 return JSValue(i);
564}
565
566ALWAYS_INLINE JSValue jsNumber(unsigned char i)
567{
568 return JSValue(i);
569}
570
571ALWAYS_INLINE JSValue jsNumber(short i)
572{
573 return JSValue(i);
574}
575
576ALWAYS_INLINE JSValue jsNumber(unsigned short i)
577{
578 return JSValue(i);
579}
580
581ALWAYS_INLINE JSValue jsNumber(int i)
582{
583 return JSValue(i);
584}
585
586ALWAYS_INLINE JSValue jsNumber(unsigned i)
587{
588 return JSValue(i);
589}
590
591ALWAYS_INLINE JSValue jsNumber(long i)
592{
593 return JSValue(i);
594}
595
596ALWAYS_INLINE JSValue jsNumber(unsigned long i)
597{
598 return JSValue(i);
599}
600
601ALWAYS_INLINE JSValue jsNumber(long long i)
602{
603 return JSValue(i);
604}
605
606ALWAYS_INLINE JSValue jsNumber(unsigned long long i)
607{
608 return JSValue(i);
609}
610
611ALWAYS_INLINE EncodedJSValue encodedJSUndefined()
612{
613 return JSValue::encode(jsUndefined());
614}
615
616ALWAYS_INLINE EncodedJSValue encodedJSValue()
617{
618 return JSValue::encode(JSValue());
619}
620
621inline bool operator==(const JSValue a, const JSCell* b) { return a == JSValue(b); }
622inline bool operator==(const JSCell* a, const JSValue b) { return JSValue(a) == b; }
623
624inline bool operator!=(const JSValue a, const JSCell* b) { return a != JSValue(b); }
625inline bool operator!=(const JSCell* a, const JSValue b) { return JSValue(a) != b; }
626
627
628bool isThisValueAltered(const PutPropertySlot&, JSObject* baseObject);
629
630// See section 7.2.9: https://tc39.github.io/ecma262/#sec-samevalue
631bool sameValue(ExecState*, JSValue a, JSValue b);
632
633} // namespace JSC
634