Debian Codegraph @

js/src/builtin/Symbol.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef builtin_Symbol_h
8 #define builtin_Symbol_h
9
10 #include "vm/NativeObject.h"
11
12 namespace JS {
13 class Symbol;
14 }
15
16 namespace js {
17
18 class SymbolObject : public NativeObject {
19 /* Stores this Symbol object's [[PrimitiveValue]]. */
20 static const unsigned PRIMITIVE_VALUE_SLOT = 0;
21
22 public:
23 static const unsigned RESERVED_SLOTS = 1;
24
25 static const JSClass class_;
26 static const JSClass& protoClass_;
27
28 /*
29 * Creates a new Symbol object boxing the given primitive Symbol. The
30 * object's [[Prototype]] is determined from context.
31 */
32 static SymbolObject* create(JSContext* cx, JS::HandleSymbol symbol);
33
34 JS::Symbol* unbox() const {
35 return getFixedSlot(PRIMITIVE_VALUE_SLOT).toSymbol();
36 }
37
38 private:
39 inline void setPrimitiveValue(JS::Symbol* symbol) {
40 setFixedSlot(PRIMITIVE_VALUE_SLOT, SymbolValue(symbol));
41 }
42
43 [[nodiscard]] static bool construct(JSContext* cx, unsigned argc, Value* vp);
44
45 // Static methods.
46 [[nodiscard]] static bool for_(JSContext* cx, unsigned argc, Value* vp);
47 [[nodiscard]] static bool keyFor(JSContext* cx, unsigned argc, Value* vp);
48
49 // Methods defined on Symbol.prototype.
50 [[nodiscard]] static bool toString_impl(JSContext* cx, const CallArgs& args);
51 [[nodiscard]] static bool toString(JSContext* cx, unsigned argc, Value* vp);
52 [[nodiscard]] static bool valueOf_impl(JSContext* cx, const CallArgs& args);
53 [[nodiscard]] static bool valueOf(JSContext* cx, unsigned argc, Value* vp);
54 [[nodiscard]] static bool toPrimitive(JSContext* cx, unsigned argc,
55 Value* vp);
56
57 // Properties defined on Symbol.prototype.
58 [[nodiscard]] static bool descriptionGetter_impl(JSContext* cx,
59 const CallArgs& args);
60 [[nodiscard]] static bool descriptionGetter(JSContext* cx, unsigned argc,
61 Value* vp);
62
63 static const JSPropertySpec properties[];
64 static const JSFunctionSpec methods[];
65 static const JSFunctionSpec staticMethods[];
66 static const ClassSpec classSpec_;
67 };
68
69 } /* namespace js */
70
71 #endif /* builtin_Symbol_h */