blob: 933a2e5184ab99ff26fcc12f6230b8d03ee19d80 [file] [log] [blame]
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +00001/*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
utatane.tea@gmail.com7f364f22016-07-29 07:15:01 +00004 * Copyright (C) 2015-2016 Yusuke Suzuki <utatane.tea@gmail.com>.
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +00005 *
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
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000031#include "JSString.h"
32#include "PrivateName.h"
33
34namespace JSC {
35
akling@apple.com4b9e0002015-04-13 19:12:48 +000036class Symbol final : public JSCell {
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000037public:
38 typedef JSCell Base;
fpizlo@apple.comcbf65c42016-04-18 20:33:47 +000039 static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal | OverridesToThis;
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000040
41 DECLARE_EXPORT_INFO;
42
43 static const bool needsDestruction = true;
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000044
45 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
46 {
47 return Structure::create(vm, globalObject, prototype, TypeInfo(SymbolType, StructureFlags), info());
48 }
49
utatane.tea@gmail.com7f364f22016-07-29 07:15:01 +000050 static Symbol* create(VM&);
51 static Symbol* create(ExecState*, JSString* description);
52 static Symbol* create(VM&, SymbolImpl& uid);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000053
54 const PrivateName& privateName() const { return m_privateName; }
55 String descriptiveString() const;
56
57 JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000058 bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
59 JSObject* toObject(ExecState*, JSGlobalObject*) const;
60 double toNumber(ExecState*) const;
61
62protected:
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000063 static void destroy(JSCell*);
64
65 Symbol(VM&);
66 Symbol(VM&, const String&);
utatane.tea@gmail.com8268d392015-05-23 18:41:53 +000067 Symbol(VM&, SymbolImpl& uid);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000068
utatane.tea@gmail.com7f364f22016-07-29 07:15:01 +000069 void finishCreation(VM&);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +000070
71 PrivateName m_privateName;
72};
73
74Symbol* asSymbol(JSValue);
75
76inline Symbol* asSymbol(JSValue value)
77{
78 ASSERT(value.asCell()->isSymbol());
79 return jsCast<Symbol*>(value.asCell());
80}
81
82} // namespace JSC
83
84#endif // Symbol_h