js/src/vm/StringObject-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/vm/StringObject-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef vm_StringObject_inl_h
    1.11 +#define vm_StringObject_inl_h
    1.12 +
    1.13 +#include "vm/StringObject.h"
    1.14 +
    1.15 +#include "jsobjinlines.h"
    1.16 +
    1.17 +#include "vm/Shape-inl.h"
    1.18 +
    1.19 +namespace js {
    1.20 +
    1.21 +inline bool
    1.22 +StringObject::init(JSContext *cx, HandleString str)
    1.23 +{
    1.24 +    JS_ASSERT(numFixedSlots() == 2);
    1.25 +
    1.26 +    Rooted<StringObject *> self(cx, this);
    1.27 +
    1.28 +    if (!EmptyShape::ensureInitialCustomShape<StringObject>(cx, self))
    1.29 +        return false;
    1.30 +
    1.31 +    JS_ASSERT(self->nativeLookup(cx, NameToId(cx->names().length))->slot() == LENGTH_SLOT);
    1.32 +
    1.33 +    self->setStringThis(str);
    1.34 +
    1.35 +    return true;
    1.36 +}
    1.37 +
    1.38 +inline StringObject *
    1.39 +StringObject::create(JSContext *cx, HandleString str, NewObjectKind newKind)
    1.40 +{
    1.41 +    JSObject *obj = NewBuiltinClassInstance(cx, &class_, newKind);
    1.42 +    if (!obj)
    1.43 +        return nullptr;
    1.44 +    Rooted<StringObject*> strobj(cx, &obj->as<StringObject>());
    1.45 +    if (!strobj->init(cx, str))
    1.46 +        return nullptr;
    1.47 +    return strobj;
    1.48 +}
    1.49 +
    1.50 +} // namespace js
    1.51 +
    1.52 +#endif /* vm_StringObject_inl_h */

mercurial