js/src/jsapi-tests/testRegExpInstanceProperties.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "jscompartment.h"
michael@0 9 #include "jsgc.h"
michael@0 10
michael@0 11 #include "jsapi-tests/tests.h"
michael@0 12 #include "vm/Shape.h"
michael@0 13
michael@0 14 BEGIN_TEST(testRegExpInstanceProperties)
michael@0 15 {
michael@0 16 jsval regexpProtoVal;
michael@0 17 EVAL("RegExp.prototype", &regexpProtoVal);
michael@0 18
michael@0 19 JSObject *regexpProto = JSVAL_TO_OBJECT(regexpProtoVal);
michael@0 20
michael@0 21 if (!helper(regexpProto))
michael@0 22 return false;
michael@0 23
michael@0 24 JS_GC(cx);
michael@0 25
michael@0 26 CHECK_EQUAL(regexpProto->compartment()->initialRegExpShape, nullptr);
michael@0 27
michael@0 28 jsval regexp;
michael@0 29 EVAL("/foopy/", &regexp);
michael@0 30 JSObject *robj = JSVAL_TO_OBJECT(regexp);
michael@0 31
michael@0 32 CHECK(robj->lastProperty());
michael@0 33 CHECK_EQUAL(robj->compartment()->initialRegExpShape, robj->lastProperty());
michael@0 34
michael@0 35 return true;
michael@0 36 }
michael@0 37
michael@0 38 /*
michael@0 39 * Do this all in a nested function evaluation so as (hopefully) not to get
michael@0 40 * screwed up by the conservative stack scanner when GCing.
michael@0 41 */
michael@0 42 MOZ_NEVER_INLINE bool helper(JSObject *regexpProto)
michael@0 43 {
michael@0 44 CHECK(!regexpProto->inDictionaryMode());
michael@0 45
michael@0 46 // Verify the compartment's cached shape is being used by RegExp.prototype.
michael@0 47 const js::Shape *shape = regexpProto->lastProperty();
michael@0 48 js::AutoShapeRooter root(cx, shape);
michael@0 49 for (js::Shape::Range r = shape;
michael@0 50 &r.front() != regexpProto->compartment()->initialRegExpShape;
michael@0 51 r.popFront())
michael@0 52 {
michael@0 53 CHECK(!r.empty());
michael@0 54 }
michael@0 55
michael@0 56 JS::RootedValue v(cx, INT_TO_JSVAL(17));
michael@0 57 CHECK(JS_SetProperty(cx, regexpProto, "foopy", v));
michael@0 58 v = INT_TO_JSVAL(42);
michael@0 59 CHECK(JS_SetProperty(cx, regexpProto, "bunky", v));
michael@0 60 CHECK(JS_DeleteProperty(cx, regexpProto, "foopy"));
michael@0 61 CHECK(regexpProto->inDictionaryMode());
michael@0 62
michael@0 63 const js::Shape *shape2 = regexpProto->lastProperty();
michael@0 64 js::AutoShapeRooter root2(cx, shape2);
michael@0 65 js::Shape::Range r2 = shape2;
michael@0 66 while (!r2.empty()) {
michael@0 67 CHECK(&r2.front() != regexpProto->compartment()->initialRegExpShape);
michael@0 68 r2.popFront();
michael@0 69 }
michael@0 70
michael@0 71 return true;
michael@0 72 }
michael@0 73 END_TEST(testRegExpInstanceProperties)

mercurial