js/src/jsapi-tests/testOps.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsapi-tests/testOps.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     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 + *
     1.7 + * Tests for operators and implicit type conversion.
     1.8 + */
     1.9 +/* This Source Code Form is subject to the terms of the Mozilla Public
    1.10 + * License, v. 2.0. If a copy of the MPL was not distributed with this
    1.11 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.12 +
    1.13 +#include "jsapi-tests/tests.h"
    1.14 +
    1.15 +static bool
    1.16 +my_convert(JSContext* context, JS::HandleObject obj, JSType type, JS::MutableHandleValue rval)
    1.17 +{
    1.18 +    if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN) {
    1.19 +        rval.set(JS_NumberValue(123));
    1.20 +        return true;
    1.21 +    }
    1.22 +    return false;
    1.23 +}
    1.24 +
    1.25 +static const JSClass myClass = {
    1.26 +    "MyClass",
    1.27 +    0,
    1.28 +    JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
    1.29 +    JS_EnumerateStub, JS_ResolveStub, my_convert
    1.30 +};
    1.31 +
    1.32 +static bool
    1.33 +createMyObject(JSContext* context, unsigned argc, jsval *vp)
    1.34 +{
    1.35 +    JS_BeginRequest(context);
    1.36 +
    1.37 +    //JS_GC(context); //<- if we make GC here, all is ok
    1.38 +
    1.39 +    JSObject* myObject = JS_NewObject(context, &myClass, JS::NullPtr(), JS::NullPtr());
    1.40 +    *vp = OBJECT_TO_JSVAL(myObject);
    1.41 +
    1.42 +    JS_EndRequest(context);
    1.43 +
    1.44 +    return true;
    1.45 +}
    1.46 +
    1.47 +static const JSFunctionSpec s_functions[] =
    1.48 +{
    1.49 +    JS_FN("createMyObject", createMyObject, 0, 0),
    1.50 +    JS_FS_END
    1.51 +};
    1.52 +
    1.53 +BEGIN_TEST(testOps_bug559006)
    1.54 +{
    1.55 +    CHECK(JS_DefineFunctions(cx, global, s_functions));
    1.56 +
    1.57 +    EXEC("function main() { while(1) return 0 + createMyObject(); }");
    1.58 +
    1.59 +    for (int i = 0; i < 9; i++) {
    1.60 +        JS::RootedValue rval(cx);
    1.61 +        CHECK(JS_CallFunctionName(cx, global, "main", JS::HandleValueArray::empty(),
    1.62 +                                  &rval));
    1.63 +        CHECK_SAME(rval, INT_TO_JSVAL(123));
    1.64 +    }
    1.65 +    return true;
    1.66 +}
    1.67 +END_TEST(testOps_bug559006)
    1.68 +

mercurial