source: webkit/trunk/JavaScriptCore/runtime/JSValue.h@ 50704

Last change on this file since 50704 was 49734, checked in by [email protected], 16 years ago

Rolled back in r49717 with the build maybe working now?

  • Property svn:eol-style set to native
File size: 22.2 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 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#ifndef JSValue_h
24#define JSValue_h
25
26#include "CallData.h"
27#include "ConstructData.h"
28#include <math.h>
29#include <stddef.h> // for size_t
30#include <stdint.h>
31#include <wtf/AlwaysInline.h>
32#include <wtf/Assertions.h>
33#include <wtf/HashTraits.h>
34#include <wtf/MathExtras.h>
35
36namespace JSC {
37
38 class Identifier;
39 class JSCell;
40 class JSGlobalData;
41 class JSImmediate;
42 class JSObject;
43 class JSString;
44 class PropertySlot;
45 class PutPropertySlot;
46 class UString;
47
48 struct ClassInfo;
49 struct Instruction;
50
51 enum PreferredPrimitiveType { NoPreference, PreferNumber, PreferString };
52
53#if USE(JSVALUE32_64)
54 typedef int64_t EncodedJSValue;
55#else
56 typedef void* EncodedJSValue;
57#endif
58
59 double nonInlineNaN();
60 int32_t toInt32SlowCase(double, bool& ok);
61 uint32_t toUInt32SlowCase(double, bool& ok);
62
63 class JSValue {
64 friend class JSImmediate;
65 friend struct EncodedJSValueHashTraits;
66 friend class JIT;
67 friend class JITStubs;
68 friend class JITStubCall;
69
70 public:
71 static EncodedJSValue encode(JSValue value);
72 static JSValue decode(EncodedJSValue ptr);
73#if !USE(JSVALUE32_64)
74 private:
75 static JSValue makeImmediate(intptr_t value);
76 intptr_t immediateValue();
77 public:
78#endif
79 enum JSNullTag { JSNull };
80 enum JSUndefinedTag { JSUndefined };
81 enum JSTrueTag { JSTrue };
82 enum JSFalseTag { JSFalse };
83
84 JSValue();
85 JSValue(JSNullTag);
86 JSValue(JSUndefinedTag);
87 JSValue(JSTrueTag);
88 JSValue(JSFalseTag);
89 JSValue(JSCell* ptr);
90 JSValue(const JSCell* ptr);
91
92 // Numbers
93 JSValue(ExecState*, double);
94 JSValue(ExecState*, char);
95 JSValue(ExecState*, unsigned char);
96 JSValue(ExecState*, short);
97 JSValue(ExecState*, unsigned short);
98 JSValue(ExecState*, int);
99 JSValue(ExecState*, unsigned);
100 JSValue(ExecState*, long);
101 JSValue(ExecState*, unsigned long);
102 JSValue(ExecState*, long long);
103 JSValue(ExecState*, unsigned long long);
104 JSValue(JSGlobalData*, double);
105 JSValue(JSGlobalData*, int);
106 JSValue(JSGlobalData*, unsigned);
107
108 operator bool() const;
109 bool operator==(const JSValue& other) const;
110 bool operator!=(const JSValue& other) const;
111
112 bool isInt32() const;
113 bool isUInt32() const;
114 bool isDouble() const;
115 bool isTrue() const;
116 bool isFalse() const;
117
118 int32_t asInt32() const;
119 uint32_t asUInt32() const;
120 double asDouble() const;
121
122 // Querying the type.
123 bool isUndefined() const;
124 bool isNull() const;
125 bool isUndefinedOrNull() const;
126 bool isBoolean() const;
127 bool isNumber() const;
128 bool isString() const;
129 bool isGetterSetter() const;
130 bool isObject() const;
131 bool inherits(const ClassInfo*) const;
132
133 // Extracting the value.
134 bool getBoolean(bool&) const;
135 bool getBoolean() const; // false if not a boolean
136 bool getNumber(double&) const;
137 double uncheckedGetNumber() const;
138 bool getString(UString&) const;
139 UString getString() const; // null string if not a string
140 JSObject* getObject() const; // 0 if not an object
141
142 CallType getCallData(CallData&);
143 ConstructType getConstructData(ConstructData&);
144
145 // Extracting integer values.
146 bool getUInt32(uint32_t&) const;
147
148 // Basic conversions.
149 JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
150 bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
151
152 bool toBoolean(ExecState*) const;
153
154 // toNumber conversion is expected to be side effect free if an exception has
155 // been set in the ExecState already.
156 double toNumber(ExecState*) const;
157 JSValue toJSNumber(ExecState*) const; // Fast path for when you expect that the value is an immediate number.
158 UString toString(ExecState*) const;
159 JSObject* toObject(ExecState*) const;
160
161 // Integer conversions.
162 double toInteger(ExecState*) const;
163 double toIntegerPreserveNaN(ExecState*) const;
164 int32_t toInt32(ExecState*) const;
165 int32_t toInt32(ExecState*, bool& ok) const;
166 uint32_t toUInt32(ExecState*) const;
167 uint32_t toUInt32(ExecState*, bool& ok) const;
168
169 // Floating point conversions (this is a convenience method for webcore;
170 // signle precision float is not a representation used in JS or JSC).
171 float toFloat(ExecState* exec) const { return static_cast<float>(toNumber(exec)); }
172
173 // Object operations, with the toObject operation included.
174 JSValue get(ExecState*, const Identifier& propertyName) const;
175 JSValue get(ExecState*, const Identifier& propertyName, PropertySlot&) const;
176 JSValue get(ExecState*, unsigned propertyName) const;
177 JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const;
178 void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
179 void put(ExecState*, unsigned propertyName, JSValue);
180
181 bool needsThisConversion() const;
182 JSObject* toThisObject(ExecState*) const;
183 UString toThisString(ExecState*) const;
184 JSString* toThisJSString(ExecState*);
185
186 static bool equal(ExecState* exec, JSValue v1, JSValue v2);
187 static bool equalSlowCase(ExecState* exec, JSValue v1, JSValue v2);
188 static bool equalSlowCaseInline(ExecState* exec, JSValue v1, JSValue v2);
189 static bool strictEqual(JSValue v1, JSValue v2);
190 static bool strictEqualSlowCase(JSValue v1, JSValue v2);
191 static bool strictEqualSlowCaseInline(JSValue v1, JSValue v2);
192
193 JSValue getJSNumber(); // JSValue() if this is not a JSNumber or number object
194
195 bool isCell() const;
196 JSCell* asCell() const;
197
198#ifndef NDEBUG
199 char* description();
200#endif
201
202 private:
203 enum HashTableDeletedValueTag { HashTableDeletedValue };
204 JSValue(HashTableDeletedValueTag);
205
206 inline const JSValue asValue() const { return *this; }
207 JSObject* toObjectSlowCase(ExecState*) const;
208 JSObject* toThisObjectSlowCase(ExecState*) const;
209
210 enum { Int32Tag = 0xffffffff };
211 enum { CellTag = 0xfffffffe };
212 enum { TrueTag = 0xfffffffd };
213 enum { FalseTag = 0xfffffffc };
214 enum { NullTag = 0xfffffffb };
215 enum { UndefinedTag = 0xfffffffa };
216 enum { EmptyValueTag = 0xfffffff9 };
217 enum { DeletedValueTag = 0xfffffff8 };
218
219 enum { LowestTag = DeletedValueTag };
220
221 uint32_t tag() const;
222 int32_t payload() const;
223
224 JSObject* synthesizePrototype(ExecState*) const;
225 JSObject* synthesizeObject(ExecState*) const;
226
227#if USE(JSVALUE32_64)
228 union {
229 EncodedJSValue asEncodedJSValue;
230 double asDouble;
231#if PLATFORM(BIG_ENDIAN)
232 struct {
233 int32_t tag;
234 int32_t payload;
235 } asBits;
236#else
237 struct {
238 int32_t payload;
239 int32_t tag;
240 } asBits;
241#endif
242 } u;
243#else // USE(JSVALUE32_64)
244 JSCell* m_ptr;
245#endif // USE(JSVALUE32_64)
246 };
247
248#if USE(JSVALUE32_64)
249 typedef IntHash<EncodedJSValue> EncodedJSValueHash;
250
251 struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
252 static const bool emptyValueIsZero = false;
253 static EncodedJSValue emptyValue() { return JSValue::encode(JSValue()); }
254 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
255 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
256 };
257#else
258 typedef PtrHash<EncodedJSValue> EncodedJSValueHash;
259
260 struct EncodedJSValueHashTraits : HashTraits<EncodedJSValue> {
261 static void constructDeletedValue(EncodedJSValue& slot) { slot = JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
262 static bool isDeletedValue(EncodedJSValue value) { return value == JSValue::encode(JSValue(JSValue::HashTableDeletedValue)); }
263 };
264#endif
265
266 // Stand-alone helper functions.
267 inline JSValue jsNull()
268 {
269 return JSValue(JSValue::JSNull);
270 }
271
272 inline JSValue jsUndefined()
273 {
274 return JSValue(JSValue::JSUndefined);
275 }
276
277 inline JSValue jsBoolean(bool b)
278 {
279 return b ? JSValue(JSValue::JSTrue) : JSValue(JSValue::JSFalse);
280 }
281
282 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, double d)
283 {
284 return JSValue(exec, d);
285 }
286
287 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, char i)
288 {
289 return JSValue(exec, i);
290 }
291
292 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, unsigned char i)
293 {
294 return JSValue(exec, i);
295 }
296
297 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, short i)
298 {
299 return JSValue(exec, i);
300 }
301
302 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, unsigned short i)
303 {
304 return JSValue(exec, i);
305 }
306
307 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, int i)
308 {
309 return JSValue(exec, i);
310 }
311
312 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, unsigned i)
313 {
314 return JSValue(exec, i);
315 }
316
317 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, long i)
318 {
319 return JSValue(exec, i);
320 }
321
322 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, unsigned long i)
323 {
324 return JSValue(exec, i);
325 }
326
327 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, long long i)
328 {
329 return JSValue(exec, i);
330 }
331
332 ALWAYS_INLINE JSValue jsNumber(ExecState* exec, unsigned long long i)
333 {
334 return JSValue(exec, i);
335 }
336
337 ALWAYS_INLINE JSValue jsNumber(JSGlobalData* globalData, double d)
338 {
339 return JSValue(globalData, d);
340 }
341
342 ALWAYS_INLINE JSValue jsNumber(JSGlobalData* globalData, int i)
343 {
344 return JSValue(globalData, i);
345 }
346
347 ALWAYS_INLINE JSValue jsNumber(JSGlobalData* globalData, unsigned i)
348 {
349 return JSValue(globalData, i);
350 }
351
352 inline bool operator==(const JSValue a, const JSCell* b) { return a == JSValue(b); }
353 inline bool operator==(const JSCell* a, const JSValue b) { return JSValue(a) == b; }
354
355 inline bool operator!=(const JSValue a, const JSCell* b) { return a != JSValue(b); }
356 inline bool operator!=(const JSCell* a, const JSValue b) { return JSValue(a) != b; }
357
358 inline int32_t toInt32(double val)
359 {
360 if (!(val >= -2147483648.0 && val < 2147483648.0)) {
361 bool ignored;
362 return toInt32SlowCase(val, ignored);
363 }
364 return static_cast<int32_t>(val);
365 }
366
367 inline uint32_t toUInt32(double val)
368 {
369 if (!(val >= 0.0 && val < 4294967296.0)) {
370 bool ignored;
371 return toUInt32SlowCase(val, ignored);
372 }
373 return static_cast<uint32_t>(val);
374 }
375
376 // FIXME: We should deprecate this and just use JSValue::asCell() instead.
377 JSCell* asCell(JSValue);
378
379 inline JSCell* asCell(JSValue value)
380 {
381 return value.asCell();
382 }
383
384 ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const
385 {
386 if (isInt32())
387 return asInt32();
388 bool ignored;
389 return toInt32SlowCase(toNumber(exec), ignored);
390 }
391
392 inline uint32_t JSValue::toUInt32(ExecState* exec) const
393 {
394 if (isUInt32())
395 return asInt32();
396 bool ignored;
397 return toUInt32SlowCase(toNumber(exec), ignored);
398 }
399
400 inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const
401 {
402 if (isInt32()) {
403 ok = true;
404 return asInt32();
405 }
406 return toInt32SlowCase(toNumber(exec), ok);
407 }
408
409 inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const
410 {
411 if (isUInt32()) {
412 ok = true;
413 return asInt32();
414 }
415 return toUInt32SlowCase(toNumber(exec), ok);
416 }
417
418#if USE(JSVALUE32_64)
419 inline JSValue jsNaN(ExecState* exec)
420 {
421 return JSValue(exec, nonInlineNaN());
422 }
423
424 // JSValue member functions.
425 inline EncodedJSValue JSValue::encode(JSValue value)
426 {
427 return value.u.asEncodedJSValue;
428 }
429
430 inline JSValue JSValue::decode(EncodedJSValue encodedJSValue)
431 {
432 JSValue v;
433 v.u.asEncodedJSValue = encodedJSValue;
434 return v;
435 }
436
437 inline JSValue::JSValue()
438 {
439 u.asBits.tag = EmptyValueTag;
440 u.asBits.payload = 0;
441 }
442
443 inline JSValue::JSValue(JSNullTag)
444 {
445 u.asBits.tag = NullTag;
446 u.asBits.payload = 0;
447 }
448
449 inline JSValue::JSValue(JSUndefinedTag)
450 {
451 u.asBits.tag = UndefinedTag;
452 u.asBits.payload = 0;
453 }
454
455 inline JSValue::JSValue(JSTrueTag)
456 {
457 u.asBits.tag = TrueTag;
458 u.asBits.payload = 0;
459 }
460
461 inline JSValue::JSValue(JSFalseTag)
462 {
463 u.asBits.tag = FalseTag;
464 u.asBits.payload = 0;
465 }
466
467 inline JSValue::JSValue(HashTableDeletedValueTag)
468 {
469 u.asBits.tag = DeletedValueTag;
470 u.asBits.payload = 0;
471 }
472
473 inline JSValue::JSValue(JSCell* ptr)
474 {
475 if (ptr)
476 u.asBits.tag = CellTag;
477 else
478 u.asBits.tag = EmptyValueTag;
479 u.asBits.payload = reinterpret_cast<int32_t>(ptr);
480 }
481
482 inline JSValue::JSValue(const JSCell* ptr)
483 {
484 if (ptr)
485 u.asBits.tag = CellTag;
486 else
487 u.asBits.tag = EmptyValueTag;
488 u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
489 }
490
491 inline JSValue::operator bool() const
492 {
493 ASSERT(tag() != DeletedValueTag);
494 return tag() != EmptyValueTag;
495 }
496
497 inline bool JSValue::operator==(const JSValue& other) const
498 {
499 return u.asEncodedJSValue == other.u.asEncodedJSValue;
500 }
501
502 inline bool JSValue::operator!=(const JSValue& other) const
503 {
504 return u.asEncodedJSValue != other.u.asEncodedJSValue;
505 }
506
507 inline bool JSValue::isUndefined() const
508 {
509 return tag() == UndefinedTag;
510 }
511
512 inline bool JSValue::isNull() const
513 {
514 return tag() == NullTag;
515 }
516
517 inline bool JSValue::isUndefinedOrNull() const
518 {
519 return isUndefined() || isNull();
520 }
521
522 inline bool JSValue::isCell() const
523 {
524 return tag() == CellTag;
525 }
526
527 inline bool JSValue::isInt32() const
528 {
529 return tag() == Int32Tag;
530 }
531
532 inline bool JSValue::isUInt32() const
533 {
534 return tag() == Int32Tag && asInt32() > -1;
535 }
536
537 inline bool JSValue::isDouble() const
538 {
539 return tag() < LowestTag;
540 }
541
542 inline bool JSValue::isTrue() const
543 {
544 return tag() == TrueTag;
545 }
546
547 inline bool JSValue::isFalse() const
548 {
549 return tag() == FalseTag;
550 }
551
552 inline uint32_t JSValue::tag() const
553 {
554 return u.asBits.tag;
555 }
556
557 inline int32_t JSValue::payload() const
558 {
559 return u.asBits.payload;
560 }
561
562 inline int32_t JSValue::asInt32() const
563 {
564 ASSERT(isInt32());
565 return u.asBits.payload;
566 }
567
568 inline uint32_t JSValue::asUInt32() const
569 {
570 ASSERT(isUInt32());
571 return u.asBits.payload;
572 }
573
574 inline double JSValue::asDouble() const
575 {
576 ASSERT(isDouble());
577 return u.asDouble;
578 }
579
580 ALWAYS_INLINE JSCell* JSValue::asCell() const
581 {
582 ASSERT(isCell());
583 return reinterpret_cast<JSCell*>(u.asBits.payload);
584 }
585
586 inline JSValue::JSValue(ExecState* exec, double d)
587 {
588 const int32_t asInt32 = static_cast<int32_t>(d);
589 if (asInt32 != d || (!asInt32 && signbit(d))) { // true for -0.0
590 u.asDouble = d;
591 return;
592 }
593 *this = JSValue(exec, static_cast<int32_t>(d));
594 }
595
596 inline JSValue::JSValue(ExecState* exec, char i)
597 {
598 *this = JSValue(exec, static_cast<int32_t>(i));
599 }
600
601 inline JSValue::JSValue(ExecState* exec, unsigned char i)
602 {
603 *this = JSValue(exec, static_cast<int32_t>(i));
604 }
605
606 inline JSValue::JSValue(ExecState* exec, short i)
607 {
608 *this = JSValue(exec, static_cast<int32_t>(i));
609 }
610
611 inline JSValue::JSValue(ExecState* exec, unsigned short i)
612 {
613 *this = JSValue(exec, static_cast<int32_t>(i));
614 }
615
616 inline JSValue::JSValue(ExecState*, int i)
617 {
618 u.asBits.tag = Int32Tag;
619 u.asBits.payload = i;
620 }
621
622 inline JSValue::JSValue(ExecState* exec, unsigned i)
623 {
624 if (static_cast<int32_t>(i) < 0) {
625 *this = JSValue(exec, static_cast<double>(i));
626 return;
627 }
628 *this = JSValue(exec, static_cast<int32_t>(i));
629 }
630
631 inline JSValue::JSValue(ExecState* exec, long i)
632 {
633 if (static_cast<int32_t>(i) != i) {
634 *this = JSValue(exec, static_cast<double>(i));
635 return;
636 }
637 *this = JSValue(exec, static_cast<int32_t>(i));
638 }
639
640 inline JSValue::JSValue(ExecState* exec, unsigned long i)
641 {
642 if (static_cast<uint32_t>(i) != i) {
643 *this = JSValue(exec, static_cast<double>(i));
644 return;
645 }
646 *this = JSValue(exec, static_cast<uint32_t>(i));
647 }
648
649 inline JSValue::JSValue(ExecState* exec, long long i)
650 {
651 if (static_cast<int32_t>(i) != i) {
652 *this = JSValue(exec, static_cast<double>(i));
653 return;
654 }
655 *this = JSValue(exec, static_cast<int32_t>(i));
656 }
657
658 inline JSValue::JSValue(ExecState* exec, unsigned long long i)
659 {
660 if (static_cast<uint32_t>(i) != i) {
661 *this = JSValue(exec, static_cast<double>(i));
662 return;
663 }
664 *this = JSValue(exec, static_cast<uint32_t>(i));
665 }
666
667 inline JSValue::JSValue(JSGlobalData* globalData, double d)
668 {
669 const int32_t asInt32 = static_cast<int32_t>(d);
670 if (asInt32 != d || (!asInt32 && signbit(d))) { // true for -0.0
671 u.asDouble = d;
672 return;
673 }
674 *this = JSValue(globalData, static_cast<int32_t>(d));
675 }
676
677 inline JSValue::JSValue(JSGlobalData*, int i)
678 {
679 u.asBits.tag = Int32Tag;
680 u.asBits.payload = i;
681 }
682
683 inline JSValue::JSValue(JSGlobalData* globalData, unsigned i)
684 {
685 if (static_cast<int32_t>(i) < 0) {
686 *this = JSValue(globalData, static_cast<double>(i));
687 return;
688 }
689 *this = JSValue(globalData, static_cast<int32_t>(i));
690 }
691
692 inline bool JSValue::isNumber() const
693 {
694 return isInt32() || isDouble();
695 }
696
697 inline bool JSValue::isBoolean() const
698 {
699 return isTrue() || isFalse();
700 }
701
702 inline bool JSValue::getBoolean(bool& v) const
703 {
704 if (isTrue()) {
705 v = true;
706 return true;
707 }
708 if (isFalse()) {
709 v = false;
710 return true;
711 }
712
713 return false;
714 }
715
716 inline bool JSValue::getBoolean() const
717 {
718 ASSERT(isBoolean());
719 return tag() == TrueTag;
720 }
721
722 inline double JSValue::uncheckedGetNumber() const
723 {
724 ASSERT(isNumber());
725 return isInt32() ? asInt32() : asDouble();
726 }
727
728 ALWAYS_INLINE JSValue JSValue::toJSNumber(ExecState* exec) const
729 {
730 return isNumber() ? asValue() : jsNumber(exec, this->toNumber(exec));
731 }
732
733 inline bool JSValue::getNumber(double& result) const
734 {
735 if (isInt32()) {
736 result = asInt32();
737 return true;
738 }
739 if (isDouble()) {
740 result = asDouble();
741 return true;
742 }
743 return false;
744 }
745
746#else // USE(JSVALUE32_64)
747
748 // JSValue member functions.
749 inline EncodedJSValue JSValue::encode(JSValue value)
750 {
751 return reinterpret_cast<EncodedJSValue>(value.m_ptr);
752 }
753
754 inline JSValue JSValue::decode(EncodedJSValue ptr)
755 {
756 return JSValue(reinterpret_cast<JSCell*>(ptr));
757 }
758
759 inline JSValue JSValue::makeImmediate(intptr_t value)
760 {
761 return JSValue(reinterpret_cast<JSCell*>(value));
762 }
763
764 inline intptr_t JSValue::immediateValue()
765 {
766 return reinterpret_cast<intptr_t>(m_ptr);
767 }
768
769 // 0x0 can never occur naturally because it has a tag of 00, indicating a pointer value, but a payload of 0x0, which is in the (invalid) zero page.
770 inline JSValue::JSValue()
771 : m_ptr(0)
772 {
773 }
774
775 // 0x4 can never occur naturally because it has a tag of 00, indicating a pointer value, but a payload of 0x4, which is in the (invalid) zero page.
776 inline JSValue::JSValue(HashTableDeletedValueTag)
777 : m_ptr(reinterpret_cast<JSCell*>(0x4))
778 {
779 }
780
781 inline JSValue::JSValue(JSCell* ptr)
782 : m_ptr(ptr)
783 {
784 }
785
786 inline JSValue::JSValue(const JSCell* ptr)
787 : m_ptr(const_cast<JSCell*>(ptr))
788 {
789 }
790
791 inline JSValue::operator bool() const
792 {
793 return m_ptr;
794 }
795
796 inline bool JSValue::operator==(const JSValue& other) const
797 {
798 return m_ptr == other.m_ptr;
799 }
800
801 inline bool JSValue::operator!=(const JSValue& other) const
802 {
803 return m_ptr != other.m_ptr;
804 }
805
806 inline bool JSValue::isUndefined() const
807 {
808 return asValue() == jsUndefined();
809 }
810
811 inline bool JSValue::isNull() const
812 {
813 return asValue() == jsNull();
814 }
815#endif // USE(JSVALUE32_64)
816
817} // namespace JSC
818
819#endif // JSValue_h
Note: See TracBrowser for help on using the repository browser.