js/src/vm/StringObject.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef vm_StringObject_h
michael@0 8 #define vm_StringObject_h
michael@0 9
michael@0 10 #include "jsobj.h"
michael@0 11 #include "jsstr.h"
michael@0 12
michael@0 13 #include "vm/Shape.h"
michael@0 14
michael@0 15 namespace js {
michael@0 16
michael@0 17 class StringObject : public JSObject
michael@0 18 {
michael@0 19 static const unsigned PRIMITIVE_VALUE_SLOT = 0;
michael@0 20 static const unsigned LENGTH_SLOT = 1;
michael@0 21
michael@0 22 public:
michael@0 23 static const unsigned RESERVED_SLOTS = 2;
michael@0 24
michael@0 25 static const Class class_;
michael@0 26
michael@0 27 /*
michael@0 28 * Creates a new String object boxing the given string. The object's
michael@0 29 * [[Prototype]] is determined from context.
michael@0 30 */
michael@0 31 static inline StringObject *create(JSContext *cx, HandleString str,
michael@0 32 NewObjectKind newKind = GenericObject);
michael@0 33
michael@0 34 JSString *unbox() const {
michael@0 35 return getFixedSlot(PRIMITIVE_VALUE_SLOT).toString();
michael@0 36 }
michael@0 37
michael@0 38 inline size_t length() const {
michael@0 39 return size_t(getFixedSlot(LENGTH_SLOT).toInt32());
michael@0 40 }
michael@0 41
michael@0 42 static size_t offsetOfPrimitiveValue() {
michael@0 43 return getFixedSlotOffset(PRIMITIVE_VALUE_SLOT);
michael@0 44 }
michael@0 45 static size_t offsetOfLength() {
michael@0 46 return getFixedSlotOffset(LENGTH_SLOT);
michael@0 47 }
michael@0 48
michael@0 49 private:
michael@0 50 inline bool init(JSContext *cx, HandleString str);
michael@0 51
michael@0 52 void setStringThis(JSString *str) {
michael@0 53 JS_ASSERT(getReservedSlot(PRIMITIVE_VALUE_SLOT).isUndefined());
michael@0 54 setFixedSlot(PRIMITIVE_VALUE_SLOT, StringValue(str));
michael@0 55 setFixedSlot(LENGTH_SLOT, Int32Value(int32_t(str->length())));
michael@0 56 }
michael@0 57
michael@0 58 /* For access to init, as String.prototype is special. */
michael@0 59 friend JSObject *
michael@0 60 ::js_InitStringClass(JSContext *cx, js::HandleObject global);
michael@0 61
michael@0 62 /* For access to assignInitialShape. */
michael@0 63 friend bool
michael@0 64 EmptyShape::ensureInitialCustomShape<StringObject>(ExclusiveContext *cx,
michael@0 65 Handle<StringObject*> obj);
michael@0 66
michael@0 67 /*
michael@0 68 * Compute the initial shape to associate with fresh String objects, which
michael@0 69 * encodes the initial length property. Return the shape after changing
michael@0 70 * |obj|'s last property to it.
michael@0 71 */
michael@0 72 static Shape *
michael@0 73 assignInitialShape(ExclusiveContext *cx, Handle<StringObject*> obj);
michael@0 74 };
michael@0 75
michael@0 76 } // namespace js
michael@0 77
michael@0 78 #endif /* vm_StringObject_h */

mercurial