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.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     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/. */
     7 #ifndef vm_StringObject_h
     8 #define vm_StringObject_h
    10 #include "jsobj.h"
    11 #include "jsstr.h"
    13 #include "vm/Shape.h"
    15 namespace js {
    17 class StringObject : public JSObject
    18 {
    19     static const unsigned PRIMITIVE_VALUE_SLOT = 0;
    20     static const unsigned LENGTH_SLOT = 1;
    22   public:
    23     static const unsigned RESERVED_SLOTS = 2;
    25     static const Class class_;
    27     /*
    28      * Creates a new String object boxing the given string.  The object's
    29      * [[Prototype]] is determined from context.
    30      */
    31     static inline StringObject *create(JSContext *cx, HandleString str,
    32                                        NewObjectKind newKind = GenericObject);
    34     JSString *unbox() const {
    35         return getFixedSlot(PRIMITIVE_VALUE_SLOT).toString();
    36     }
    38     inline size_t length() const {
    39         return size_t(getFixedSlot(LENGTH_SLOT).toInt32());
    40     }
    42     static size_t offsetOfPrimitiveValue() {
    43         return getFixedSlotOffset(PRIMITIVE_VALUE_SLOT);
    44     }
    45     static size_t offsetOfLength() {
    46         return getFixedSlotOffset(LENGTH_SLOT);
    47     }
    49   private:
    50     inline bool init(JSContext *cx, HandleString str);
    52     void setStringThis(JSString *str) {
    53         JS_ASSERT(getReservedSlot(PRIMITIVE_VALUE_SLOT).isUndefined());
    54         setFixedSlot(PRIMITIVE_VALUE_SLOT, StringValue(str));
    55         setFixedSlot(LENGTH_SLOT, Int32Value(int32_t(str->length())));
    56     }
    58     /* For access to init, as String.prototype is special. */
    59     friend JSObject *
    60     ::js_InitStringClass(JSContext *cx, js::HandleObject global);
    62     /* For access to assignInitialShape. */
    63     friend bool
    64     EmptyShape::ensureInitialCustomShape<StringObject>(ExclusiveContext *cx,
    65                                                        Handle<StringObject*> obj);
    67     /*
    68      * Compute the initial shape to associate with fresh String objects, which
    69      * encodes the initial length property. Return the shape after changing
    70      * |obj|'s last property to it.
    71      */
    72     static Shape *
    73     assignInitialShape(ExclusiveContext *cx, Handle<StringObject*> obj);
    74 };
    76 } // namespace js
    78 #endif /* vm_StringObject_h */

mercurial