Debian Codegraph @

js/src/vm/StringObject-inl.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 vm_StringObject_inl_h
8 #define vm_StringObject_inl_h
9
10 #include "vm/StringObject.h"
11
12 #include "vm/JSObject-inl.h"
13 #include "vm/Shape-inl.h"
14
15 namespace js {
16
17 /* static */ inline bool StringObject::init(JSContext* cx,
18 Handle<StringObject*> obj,
19 HandleString str) {
20 MOZ_ASSERT(obj->numFixedSlots() == 2);
21
22 if (!SharedShape::ensureInitialCustomShape<StringObject>(cx, obj)) {
23 return false;
24 }
25
26 MOZ_ASSERT(obj->lookup(cx, NameToId(cx->names().length))->slot() ==
27 LENGTH_SLOT);
28
29 obj->setStringThis(str);
30
31 return true;
32 }
33
34 /* static */ inline StringObject* StringObject::create(JSContext* cx,
35 HandleString str,
36 HandleObject proto,
37 NewObjectKind newKind) {
38 Rooted<StringObject*> obj(
39 cx, NewObjectWithClassProtoAndKind<StringObject>(
40 cx, proto, newKind,
41 ObjectFlags({ObjectFlag::NeedsProxyGetSetResultValidation})));
42 if (!obj) {
43 return nullptr;
44 }
45 if (!StringObject::init(cx, obj, str)) {
46 return nullptr;
47 }
48 return obj;
49 }
50
51 } // namespace js
52
53 #endif /* vm_StringObject_inl_h */