]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | /* |
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>. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
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. | |
14 | * | |
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. | |
26 | */ | |
27 | ||
28 | #ifndef Symbol_h | |
29 | #define Symbol_h | |
30 | ||
31 | #include "JSCell.h" | |
32 | #include "JSString.h" | |
33 | #include "PrivateName.h" | |
34 | ||
35 | namespace JSC { | |
36 | ||
37 | class Symbol final : public JSCell { | |
38 | public: | |
39 | typedef JSCell Base; | |
40 | static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | StructureIsImmortal; | |
41 | ||
42 | DECLARE_EXPORT_INFO; | |
43 | ||
44 | static const bool needsDestruction = true; | |
45 | ||
46 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) | |
47 | { | |
48 | return Structure::create(vm, globalObject, prototype, TypeInfo(SymbolType, StructureFlags), info()); | |
49 | } | |
50 | ||
51 | static Symbol* create(VM& vm) | |
52 | { | |
53 | Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm); | |
54 | symbol->finishCreation(vm); | |
55 | return symbol; | |
56 | } | |
57 | ||
58 | static Symbol* create(ExecState* exec, JSString* description) | |
59 | { | |
60 | VM& vm = exec->vm(); | |
61 | String desc = description->value(exec); | |
62 | Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, desc); | |
63 | symbol->finishCreation(vm); | |
64 | return symbol; | |
65 | } | |
66 | ||
67 | static Symbol* create(VM& vm, SymbolImpl& uid) | |
68 | { | |
69 | Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, uid); | |
70 | symbol->finishCreation(vm); | |
71 | return symbol; | |
72 | } | |
73 | ||
74 | const PrivateName& privateName() const { return m_privateName; } | |
75 | String descriptiveString() const; | |
76 | ||
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; | |
81 | ||
82 | protected: | |
83 | static void destroy(JSCell*); | |
84 | ||
85 | Symbol(VM&); | |
86 | Symbol(VM&, const String&); | |
87 | Symbol(VM&, SymbolImpl& uid); | |
88 | ||
89 | void finishCreation(VM& vm) | |
90 | { | |
91 | Base::finishCreation(vm); | |
92 | ASSERT(inherits(info())); | |
93 | } | |
94 | ||
95 | PrivateName m_privateName; | |
96 | }; | |
97 | ||
98 | Symbol* asSymbol(JSValue); | |
99 | ||
100 | inline Symbol* asSymbol(JSValue value) | |
101 | { | |
102 | ASSERT(value.asCell()->isSymbol()); | |
103 | return jsCast<Symbol*>(value.asCell()); | |
104 | } | |
105 | ||
106 | } // namespace JSC | |
107 | ||
108 | #endif // Symbol_h |