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 uint32_t asUInt32AsAnyInt() const;
215 int32_t asInt32AsAnyInt() const;
216 double asDouble() const;
217 bool asBoolean() const;
218 double asNumber() const;
219
220 int32_t asInt32ForArithmetic() const; // Boolean becomes an int, but otherwise like asInt32().
221
222 // Querying the type.
223 bool isEmpty() const;
224 bool isFunction(VM&) const;
225 bool isCallable(VM&, CallType&, CallData&) const;
226 bool isConstructor(VM&) const;
227 bool isConstructor(VM&, ConstructType&, ConstructData&) const;
228 bool isUndefined() const;
229 bool isNull() const;
230 bool isUndefinedOrNull() const;
231 bool isBoolean() const;
232 bool isAnyInt() const;
233 bool isUInt32AsAnyInt() const;
234 bool isInt32AsAnyInt() const;
235 bool isNumber() const;
236 bool isString() const;
237 bool isBigInt() const;
238 bool isSymbol() const;
239 bool isPrimitive() const;
240 bool isGetterSetter() const;
241 bool isCustomGetterSetter() const;
242 bool isObject() const;
243 bool inherits(VM&, const ClassInfo*) const;
244 template<typename Target> bool inherits(VM&) const;
245 const ClassInfo* classInfoOrNull(VM&) const;
246
247 // Extracting the value.
248 bool getString(ExecState*, WTF::String&) const;
249 WTF::String getString(ExecState*) const; // null string if not a string
250 JSObject* getObject() const; // 0 if not an object
251
252 // Extracting integer values.
253 bool getUInt32(uint32_t&) const;
254
255 // Basic conversions.
256 JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
257 bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
258
259 bool toBoolean(ExecState*) const;
260 TriState pureToBoolean() const;
261
262 // toNumber conversion is expected to be side effect free if an exception has
263 // been set in the ExecState already.
264 double toNumber(ExecState*) const;
265
266 Variant<JSBigInt*, double> toNumeric(ExecState*) const;
267 Variant<JSBigInt*, int32_t> toBigIntOrInt32(ExecState*) const;
268
269 // toNumber conversion if it can be done without side effects.
270 Optional<double> toNumberFromPrimitive() const;
271
272 JSString* toString(ExecState*) const; // On exception, this returns the empty string.
273 JSString* toStringOrNull(ExecState*) const; // On exception, this returns null, to make exception checks faster.
274 Identifier toPropertyKey(ExecState*) const;
275 WTF::String toWTFString(ExecState*) const;
276 JSObject* toObject(ExecState*) const;
277 JSObject* toObject(ExecState*, JSGlobalObject*) const;
278
279 // Integer conversions.
280 JS_EXPORT_PRIVATE double toInteger(ExecState*) const;
281 JS_EXPORT_PRIVATE double toIntegerPreserveNaN(ExecState*) const;
282 int32_t toInt32(ExecState*) const;
283 uint32_t toUInt32(ExecState*) const;
284 uint32_t toIndex(ExecState*, const char* errorName) const;
285 double toLength(ExecState*) const;
286
287 // Floating point conversions (this is a convenience function for WebCore;
288 // single precision float is not a representation used in JS or JSC).
289 float toFloat(ExecState* exec) const { return static_cast<float>(toNumber(exec)); }
290
291 // Object operations, with the toObject operation included.
292 JSValue get(ExecState*, PropertyName) const;
293 JSValue get(ExecState*, PropertyName, PropertySlot&) const;
294 JSValue get(ExecState*, unsigned propertyName) const;
295 JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const;
296 JSValue get(ExecState*, uint64_t propertyName) const;
297
298 bool getPropertySlot(ExecState*, PropertyName, PropertySlot&) const;
299 template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, CallbackWhenNoException) const;
300 template<typename CallbackWhenNoException> typename std::result_of<CallbackWhenNoException(bool, PropertySlot&)>::type getPropertySlot(ExecState*, PropertyName, PropertySlot&, CallbackWhenNoException) const;
301
302 bool getOwnPropertySlot(ExecState*, PropertyName, PropertySlot&) const;
303
304 bool put(ExecState*, PropertyName, JSValue, PutPropertySlot&);
305 bool putInline(ExecState*, PropertyName, JSValue, PutPropertySlot&);
306 JS_EXPORT_PRIVATE bool putToPrimitive(ExecState*, PropertyName, JSValue, PutPropertySlot&);
307 JS_EXPORT_PRIVATE bool putToPrimitiveByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
308 bool putByIndex(ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
309
310 JSValue toThis(ExecState*, ECMAMode) const;
311
312 static bool equal(ExecState*, JSValue v1, JSValue v2);
313 static bool equalSlowCase(ExecState*, JSValue v1, JSValue v2);
314 static bool equalSlowCaseInline(ExecState*, JSValue v1, JSValue v2);
315 static bool strictEqual(ExecState*, JSValue v1, JSValue v2);
316 static bool strictEqualSlowCase(ExecState*, JSValue v1, JSValue v2);
317 static bool strictEqualSlowCaseInline(ExecState*, JSValue v1, JSValue v2);
318 static TriState pureStrictEqual(JSValue v1, JSValue v2);
319
320 bool isCell() const;
321 JSCell* asCell() const;
322 JS_EXPORT_PRIVATE bool isValidCallee();
323
324 Structure* structureOrNull() const;
325 JSValue structureOrUndefined() const;
326
327 JS_EXPORT_PRIVATE void dump(PrintStream&) const;
328 void dumpInContext(PrintStream&, DumpContext*) const;
329 void dumpInContextAssumingStructure(PrintStream&, DumpContext*, Structure*) const;
330 void dumpForBacktrace(PrintStream&) const;
331
332 JS_EXPORT_PRIVATE JSObject* synthesizePrototype(ExecState*) const;
333 bool requireObjectCoercible(ExecState*) const;
334
335 // Constants used for Int52. Int52 isn't part of JSValue right now, but JSValues may be
336 // converted to Int52s and back again.
337 static constexpr const unsigned numberOfInt52Bits = 52;
338 static constexpr const int64_t notInt52 = static_cast<int64_t>(1) << numberOfInt52Bits;
339 static constexpr const unsigned int52ShiftAmount = 12;
340
341 static ptrdiff_t offsetOfPayload() { return OBJECT_OFFSETOF(JSValue, u.asBits.payload); }
342 static ptrdiff_t offsetOfTag() { return OBJECT_OFFSETOF(JSValue, u.asBits.tag); }
343
344#if USE(JSVALUE32_64)
345 /*
346 * On 32-bit platforms USE(JSVALUE32_64) should be defined, and we use a NaN-encoded
347 * form for immediates.
348 *
349 * The encoding makes use of unused NaN space in the IEEE754 representation. Any value
350 * with the top 13 bits set represents a QNaN (with the sign bit set). QNaN values
351 * can encode a 51-bit payload. Hardware produced and C-library payloads typically
352 * have a payload of zero. We assume that non-zero payloads are available to encode
353 * pointer and integer values. Since any 64-bit bit pattern where the top 15 bits are
354 * all set represents a NaN with a non-zero payload, we can use this space in the NaN
355 * ranges to encode other values (however there are also other ranges of NaN space that
356 * could have been selected).
357 *
358 * For JSValues that do not contain a double value, the high 32 bits contain the tag
359 * values listed in the enums below, which all correspond to NaN-space. In the case of
360 * cell, integer and bool values the lower 32 bits (the 'payload') contain the pointer
361 * integer or boolean value; in the case of all other tags the payload is 0.
362 */
363 uint32_t tag() const;
364 int32_t payload() const;
365
366 // This should only be used by the LLInt C Loop interpreter and OSRExit code who needs
367 // synthesize JSValue from its "register"s holding tag and payload values.
368 explicit JSValue(int32_t tag, int32_t payload);
369
370#elif USE(JSVALUE64)
371 /*
372 * On 64-bit platforms USE(JSVALUE64) should be defined, and we use a NaN-encoded
373 * form for immediates.
374 *
375 * The encoding makes use of unused NaN space in the IEEE754 representation. Any value
376 * with the top 13 bits set represents a QNaN (with the sign bit set). QNaN values
377 * can encode a 51-bit payload. Hardware produced and C-library payloads typically
378 * have a payload of zero. We assume that non-zero payloads are available to encode
379 * pointer and integer values. Since any 64-bit bit pattern where the top 15 bits are
380 * all set represents a NaN with a non-zero payload, we can use this space in the NaN
381 * ranges to encode other values (however there are also other ranges of NaN space that
382 * could have been selected).
383 *
384 * This range of NaN space is represented by 64-bit numbers begining with the 16-bit
385 * hex patterns 0xFFFE and 0xFFFF - we rely on the fact that no valid double-precision
386 * numbers will fall in these ranges.
387 *
388 * The top 16-bits denote the type of the encoded JSValue:
389 *
390 * Pointer { 0000:PPPP:PPPP:PPPP
391 * / 0001:****:****:****
392 * Double { ...
393 * \ FFFE:****:****:****
394 * Integer { FFFF:0000:IIII:IIII
395 *
396 * The scheme we have implemented encodes double precision values by performing a
397 * 64-bit integer addition of the value 2^48 to the number. After this manipulation
398 * no encoded double-precision value will begin with the pattern 0x0000 or 0xFFFF.
399 * Values must be decoded by reversing this operation before subsequent floating point
400 * operations may be peformed.
401 *
402 * 32-bit signed integers are marked with the 16-bit tag 0xFFFF.
403 *
404 * The tag 0x0000 denotes a pointer, or another form of tagged immediate. Boolean,
405 * null and undefined values are represented by specific, invalid pointer values:
406 *
407 * False: 0x06
408 * True: 0x07
409 * Undefined: 0x0a
410 * Null: 0x02
411 *
412 * These values have the following properties:
413 * - Bit 1 (TagBitTypeOther) is set for all four values, allowing real pointers to be
414 * quickly distinguished from all immediate values, including these invalid pointers.
415 * - With bit 3 is masked out (TagBitUndefined) Undefined and Null share the
416 * same value, allowing null & undefined to be quickly detected.
417 *
418 * No valid JSValue will have the bit pattern 0x0, this is used to represent array
419 * holes, and as a C++ 'no value' result (e.g. JSValue() has an internal value of 0).
420 */
421
422 // These values are #defines since using static const integers here is a ~1% regression!
423
424 // This value is 2^48, used to encode doubles such that the encoded value will begin
425 // with a 16-bit pattern within the range 0x0001..0xFFFE.
426 #define DoubleEncodeOffset 0x1000000000000ll
427 // If all bits in the mask are set, this indicates an integer number,
428 // if any but not all are set this value is a double precision number.
429 #define TagTypeNumber 0xffff000000000000ll
430
431 // All non-numeric (bool, null, undefined) immediates have bit 2 set.
432 #define TagBitTypeOther 0x2ll
433 #define TagBitBool 0x4ll
434 #define TagBitUndefined 0x8ll
435 // Combined integer value for non-numeric immediates.
436 #define ValueFalse (TagBitTypeOther | TagBitBool | false)
437 #define ValueTrue (TagBitTypeOther | TagBitBool | true)
438 #define ValueUndefined (TagBitTypeOther | TagBitUndefined)
439 #define ValueNull (TagBitTypeOther)
440
441 // TagMask is used to check for all types of immediate values (either number or 'other').
442 #define TagMask (TagTypeNumber | TagBitTypeOther)
443
444 // These special values are never visible to JavaScript code; Empty is used to represent
445 // Array holes, and for uninitialized JSValues. Deleted is used in hash table code.
446 // These values would map to cell types in the JSValue encoding, but not valid GC cell
447 // pointer should have either of these values (Empty is null, deleted is at an invalid
448 // alignment for a GC cell, and in the zero page).
449 #define ValueEmpty 0x0ll
450 #define ValueDeleted 0x4ll
451
452 #define TagBitsWasm (TagBitTypeOther | 0x1)
453 #define TagWasmMask (TagTypeNumber | 0x7)
454 // We tag Wasm non-JSCell pointers with a 3 at the bottom. We can test if a 64-bit JSValue pattern
455 // is a Wasm callee by masking the upper 16 bits and the lower 3 bits, and seeing if
456 // the resulting value is 3. The full test is: x & TagWasmMask == TagBitsWasm
457 // This works because the lower 3 bits of the non-number immediate values are as follows:
458 // undefined: 0b010
459 // null: 0b010
460 // true: 0b111
461 // false: 0b110
462 // The test rejects all of these because none have just the value 3 in their lower 3 bits.
463 // The test rejects all numbers because they have non-zero upper 16 bits.
464 // The test also rejects normal cells because they won't have the number 3 as
465 // their lower 3 bits. Note, this bit pattern also allows the normal JSValue isCell(), etc,
466 // predicates to work on a Wasm::Callee because the various tests will fail if you
467 // bit casted a boxed Wasm::Callee* to a JSValue. isCell() would fail since it sees
468 // TagBitTypeOther. The other tests also trivially fail, since it won't be a number,
469 // and it won't be equal to null, undefined, true, or false. The isBoolean() predicate
470 // will fail because we won't have TagBitBool set.
471#endif
472
473private:
474 template <class T> JSValue(WriteBarrierBase<T, WriteBarrierTraitsSelect<T>>);
475
476 enum HashTableDeletedValueTag { HashTableDeletedValue };
477 JSValue(HashTableDeletedValueTag);
478
479 inline const JSValue asValue() const { return *this; }
480 JS_EXPORT_PRIVATE double toNumberSlowCase(ExecState*) const;
481 JS_EXPORT_PRIVATE JSString* toStringSlowCase(ExecState*, bool returnEmptyStringOnError) const;
482 JS_EXPORT_PRIVATE WTF::String toWTFStringSlowCase(ExecState*) const;
483 JS_EXPORT_PRIVATE JSObject* toObjectSlowCase(ExecState*, JSGlobalObject*) const;
484 JS_EXPORT_PRIVATE JSValue toThisSlowCase(ExecState*, ECMAMode) const;
485
486 EncodedValueDescriptor u;
487};
488
489typedef IntHash<EncodedJSValue> EncodedJSValueHash;
490
491#if USE(JSVALUE32_64)
492struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
493 static const bool emptyValueIsZero = false;
494 static EncodedJSValue emptyValue() { return JSValue::encode(JSValue()); }
495 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
496 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
497};
498#else
499struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
500 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
501 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
502};
503#endif
504
505typedef std::pair<EncodedJSValue, SourceCodeRepresentation> EncodedJSValueWithRepresentation;
506
507struct EncodedJSValueWithRepresentationHashTraits : HashTraits<EncodedJSValueWithRepresentation> {
508 static const bool emptyValueIsZero = false;
509 static EncodedJSValueWithRepresentation emptyValue() { return std::make_pair(JSValue::encode(JSValue()), SourceCodeRepresentation::Other); }
510 static void constructDeletedValue(EncodedJSValueWithRepresentation& slot) { slot = std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); }
511 static bool isDeletedValue(EncodedJSValueWithRepresentation value) { return value == std::make_pair(JSValue::encode(JSValue(JSValue::HashTableDeletedValue)), SourceCodeRepresentation::Other); }
512};
513
514struct EncodedJSValueWithRepresentationHash {
515 static unsigned hash(const EncodedJSValueWithRepresentation& value)
516 {
517 return WTF::pairIntHash(EncodedJSValueHash::hash(value.first), IntHash<SourceCodeRepresentation>::hash(value.second));
518 }
519 static bool equal(const EncodedJSValueWithRepresentation& a, const EncodedJSValueWithRepresentation& b)
520 {
521 return a == b;
522 }
523 static const bool safeToCompareToEmptyOrDeleted = true;
524};
525
526// Stand-alone helper functions.
527inline JSValue jsNull()
528{
529 return JSValue(JSValue::JSNull);
530}
531
532inline JSValue jsUndefined()
533{
534 return JSValue(JSValue::JSUndefined);
535}
536
537inline JSValue jsTDZValue()
538{
539 return JSValue();
540}
541
542inline JSValue jsBoolean(bool b)
543{
544 return b ? JSValue(JSValue::JSTrue) : JSValue(JSValue::JSFalse);
545}
546
547ALWAYS_INLINE JSValue jsDoubleNumber(double d)
548{
549 ASSERT(JSValue(JSValue::EncodeAsDouble, d).isNumber());
550 return JSValue(JSValue::EncodeAsDouble, d);
551}
552
553ALWAYS_INLINE JSValue jsNumber(double d)
554{
555 ASSERT(JSValue(d).isNumber());
556 ASSERT(!isImpureNaN(d));
557 return JSValue(d);
558}
559
560ALWAYS_INLINE JSValue jsNumber(const MediaTime& t)
561{
562 return jsNumber(t.toDouble());
563}
564
565ALWAYS_INLINE JSValue jsNumber(char i)
566{
567 return JSValue(i);
568}
569
570ALWAYS_INLINE JSValue jsNumber(unsigned char i)
571{
572 return JSValue(i);
573}
574
575ALWAYS_INLINE JSValue jsNumber(short i)
576{
577 return JSValue(i);
578}
579
580ALWAYS_INLINE JSValue jsNumber(unsigned short i)
581{
582 return JSValue(i);
583}
584
585ALWAYS_INLINE JSValue jsNumber(int i)
586{
587 return JSValue(i);
588}
589
590ALWAYS_INLINE JSValue jsNumber(unsigned i)
591{
592 return JSValue(i);
593}
594
595ALWAYS_INLINE JSValue jsNumber(long i)
596{
597 return JSValue(i);
598}
599
600ALWAYS_INLINE JSValue jsNumber(unsigned long i)
601{
602 return JSValue(i);
603}
604
605ALWAYS_INLINE JSValue jsNumber(long long i)
606{
607 return JSValue(i);
608}
609
610ALWAYS_INLINE JSValue jsNumber(unsigned long long i)
611{
612 return JSValue(i);
613}
614
615ALWAYS_INLINE EncodedJSValue encodedJSUndefined()
616{
617 return JSValue::encode(jsUndefined());
618}
619
620ALWAYS_INLINE EncodedJSValue encodedJSValue()
621{
622 return JSValue::encode(JSValue());
623}
624
625inline bool operator==(const JSValue a, const JSCell* b) { return a == JSValue(b); }
626inline bool operator==(const JSCell* a, const JSValue b) { return JSValue(a) == b; }
627
628inline bool operator!=(const JSValue a, const JSCell* b) { return a != JSValue(b); }
629inline bool operator!=(const JSCell* a, const JSValue b) { return JSValue(a) != b; }
630
631
632bool isThisValueAltered(const PutPropertySlot&, JSObject* baseObject);
633
634// See section 7.2.9: https://tc39.github.io/ecma262/#sec-samevalue
635bool sameValue(ExecState*, JSValue a, JSValue b);
636
637} // namespace JSC
638