Source code

Revision control

Other Tools

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
#include "vm/SymbolType.h"
12
13
namespace js {
14
15
class GlobalObject;
16
17
class SymbolObject : public NativeObject {
18
/* Stores this Symbol object's [[PrimitiveValue]]. */
19
static const unsigned PRIMITIVE_VALUE_SLOT = 0;
20
21
public:
22
static const unsigned RESERVED_SLOTS = 1;
23
24
static const JSClass class_;
25
26
static JSObject* initClass(JSContext* cx, Handle<GlobalObject*> global,
27
bool defineMembers);
28
29
/*
30
* Creates a new Symbol object boxing the given primitive Symbol. The
31
* object's [[Prototype]] is determined from context.
32
*/
33
static SymbolObject* create(JSContext* cx, JS::HandleSymbol symbol);
34
35
JS::Symbol* unbox() const {
36
return getFixedSlot(PRIMITIVE_VALUE_SLOT).toSymbol();
37
}
38
39
private:
40
inline void setPrimitiveValue(JS::Symbol* symbol) {
41
setFixedSlot(PRIMITIVE_VALUE_SLOT, SymbolValue(symbol));
42
}
43
44
static MOZ_MUST_USE bool construct(JSContext* cx, unsigned argc, Value* vp);
45
46
// Static methods.
47
static MOZ_MUST_USE bool for_(JSContext* cx, unsigned argc, Value* vp);
48
static MOZ_MUST_USE bool keyFor(JSContext* cx, unsigned argc, Value* vp);
49
50
// Methods defined on Symbol.prototype.
51
static MOZ_MUST_USE bool toString_impl(JSContext* cx, const CallArgs& args);
52
static MOZ_MUST_USE bool toString(JSContext* cx, unsigned argc, Value* vp);
53
static MOZ_MUST_USE bool valueOf_impl(JSContext* cx, const CallArgs& args);
54
static MOZ_MUST_USE bool valueOf(JSContext* cx, unsigned argc, Value* vp);
55
static MOZ_MUST_USE bool toPrimitive(JSContext* cx, unsigned argc, Value* vp);
56
57
// Properties defined on Symbol.prototype.
58
static MOZ_MUST_USE bool descriptionGetter_impl(JSContext* cx,
59
const CallArgs& args);
60
static MOZ_MUST_USE 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
};
67
68
extern JSObject* InitSymbolClass(JSContext* cx, Handle<GlobalObject*> global);
69
70
extern JSObject* InitBareSymbolCtor(JSContext* cx,
71
Handle<GlobalObject*> global);
72
73
} /* namespace js */
74
75
#endif /* builtin_Symbol_h */