2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include "PrivateName.h"
37 class Symbol final
: public JSCell
{
40 static const unsigned StructureFlags
= Base::StructureFlags
| OverridesGetOwnPropertySlot
| InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero
| StructureIsImmortal
;
44 static const bool needsDestruction
= true;
46 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
48 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(SymbolType
, StructureFlags
), info());
51 static Symbol
* create(VM
& vm
)
53 Symbol
* symbol
= new (NotNull
, allocateCell
<Symbol
>(vm
.heap
)) Symbol(vm
);
54 symbol
->finishCreation(vm
);
58 static Symbol
* create(ExecState
* exec
, JSString
* description
)
61 String desc
= description
->value(exec
);
62 Symbol
* symbol
= new (NotNull
, allocateCell
<Symbol
>(vm
.heap
)) Symbol(vm
, desc
);
63 symbol
->finishCreation(vm
);
67 static Symbol
* create(VM
& vm
, SymbolImpl
& uid
)
69 Symbol
* symbol
= new (NotNull
, allocateCell
<Symbol
>(vm
.heap
)) Symbol(vm
, uid
);
70 symbol
->finishCreation(vm
);
74 const PrivateName
& privateName() const { return m_privateName
; }
75 String
descriptiveString() const;
77 JSValue
toPrimitive(ExecState
*, PreferredPrimitiveType
) const;
78 bool getPrimitiveNumber(ExecState
*, double& number
, JSValue
&) const;
79 JSObject
* toObject(ExecState
*, JSGlobalObject
*) const;
80 double toNumber(ExecState
*) const;
83 static void destroy(JSCell
*);
86 Symbol(VM
&, const String
&);
87 Symbol(VM
&, SymbolImpl
& uid
);
89 void finishCreation(VM
& vm
)
91 Base::finishCreation(vm
);
92 ASSERT(inherits(info()));
95 PrivateName m_privateName
;
98 Symbol
* asSymbol(JSValue
);
100 inline Symbol
* asSymbol(JSValue value
)
102 ASSERT(value
.asCell()->isSymbol());
103 return jsCast
<Symbol
*>(value
.asCell());