utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2014 Apple Inc. All rights reserved. |
utatane.tea@gmail.com | 7f364f2 | 2016-07-29 07:15:01 +0000 | [diff] [blame] | 4 | * Copyright (C) 2015-2016 Yusuke Suzuki <utatane.tea@gmail.com>. |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 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 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame^] | 28 | #pragma once |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 29 | |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 30 | #include "JSString.h" |
| 31 | #include "PrivateName.h" |
| 32 | |
| 33 | namespace JSC { |
| 34 | |
akling@apple.com | 4b9e000 | 2015-04-13 19:12:48 +0000 | [diff] [blame] | 35 | class Symbol final : public JSCell { |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 36 | public: |
| 37 | typedef JSCell Base; |
fpizlo@apple.com | cbf65c4 | 2016-04-18 20:33:47 +0000 | [diff] [blame] | 38 | static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal | OverridesToThis; |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 39 | |
| 40 | DECLARE_EXPORT_INFO; |
| 41 | |
| 42 | static const bool needsDestruction = true; |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 43 | |
| 44 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
| 45 | { |
| 46 | return Structure::create(vm, globalObject, prototype, TypeInfo(SymbolType, StructureFlags), info()); |
| 47 | } |
| 48 | |
utatane.tea@gmail.com | 7f364f2 | 2016-07-29 07:15:01 +0000 | [diff] [blame] | 49 | static Symbol* create(VM&); |
| 50 | static Symbol* create(ExecState*, JSString* description); |
utatane.tea@gmail.com | 2bd025a | 2016-09-02 03:42:09 +0000 | [diff] [blame] | 51 | JS_EXPORT_PRIVATE static Symbol* create(VM&, SymbolImpl& uid); |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 52 | |
| 53 | const PrivateName& privateName() const { return m_privateName; } |
| 54 | String descriptiveString() const; |
| 55 | |
| 56 | JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const; |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 57 | bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const; |
| 58 | JSObject* toObject(ExecState*, JSGlobalObject*) const; |
| 59 | double toNumber(ExecState*) const; |
| 60 | |
sbarati@apple.com | a3db465 | 2016-09-20 01:05:50 +0000 | [diff] [blame] | 61 | static ptrdiff_t offsetOfSymbolImpl() |
| 62 | { |
| 63 | // PrivateName is just a Ref<SymbolImpl> which can just be used as a SymbolImpl*. |
| 64 | return OBJECT_OFFSETOF(Symbol, m_privateName); |
| 65 | } |
| 66 | |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 67 | protected: |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 68 | static void destroy(JSCell*); |
| 69 | |
| 70 | Symbol(VM&); |
| 71 | Symbol(VM&, const String&); |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 72 | Symbol(VM&, SymbolImpl& uid); |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 73 | |
utatane.tea@gmail.com | 7f364f2 | 2016-07-29 07:15:01 +0000 | [diff] [blame] | 74 | void finishCreation(VM&); |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 75 | |
| 76 | PrivateName m_privateName; |
| 77 | }; |
| 78 | |
| 79 | Symbol* asSymbol(JSValue); |
| 80 | |
| 81 | inline Symbol* asSymbol(JSValue value) |
| 82 | { |
| 83 | ASSERT(value.asCell()->isSymbol()); |
| 84 | return jsCast<Symbol*>(value.asCell()); |
| 85 | } |
| 86 | |
| 87 | } // namespace JSC |