Thu, 22 Jan 2015 13:21:57 +0100
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 | * Tests for operators and implicit type conversion. |
michael@0 | 5 | */ |
michael@0 | 6 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 9 | |
michael@0 | 10 | #include "jsapi-tests/tests.h" |
michael@0 | 11 | |
michael@0 | 12 | static bool |
michael@0 | 13 | my_convert(JSContext* context, JS::HandleObject obj, JSType type, JS::MutableHandleValue rval) |
michael@0 | 14 | { |
michael@0 | 15 | if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN) { |
michael@0 | 16 | rval.set(JS_NumberValue(123)); |
michael@0 | 17 | return true; |
michael@0 | 18 | } |
michael@0 | 19 | return false; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | static const JSClass myClass = { |
michael@0 | 23 | "MyClass", |
michael@0 | 24 | 0, |
michael@0 | 25 | JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, |
michael@0 | 26 | JS_EnumerateStub, JS_ResolveStub, my_convert |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | static bool |
michael@0 | 30 | createMyObject(JSContext* context, unsigned argc, jsval *vp) |
michael@0 | 31 | { |
michael@0 | 32 | JS_BeginRequest(context); |
michael@0 | 33 | |
michael@0 | 34 | //JS_GC(context); //<- if we make GC here, all is ok |
michael@0 | 35 | |
michael@0 | 36 | JSObject* myObject = JS_NewObject(context, &myClass, JS::NullPtr(), JS::NullPtr()); |
michael@0 | 37 | *vp = OBJECT_TO_JSVAL(myObject); |
michael@0 | 38 | |
michael@0 | 39 | JS_EndRequest(context); |
michael@0 | 40 | |
michael@0 | 41 | return true; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | static const JSFunctionSpec s_functions[] = |
michael@0 | 45 | { |
michael@0 | 46 | JS_FN("createMyObject", createMyObject, 0, 0), |
michael@0 | 47 | JS_FS_END |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | BEGIN_TEST(testOps_bug559006) |
michael@0 | 51 | { |
michael@0 | 52 | CHECK(JS_DefineFunctions(cx, global, s_functions)); |
michael@0 | 53 | |
michael@0 | 54 | EXEC("function main() { while(1) return 0 + createMyObject(); }"); |
michael@0 | 55 | |
michael@0 | 56 | for (int i = 0; i < 9; i++) { |
michael@0 | 57 | JS::RootedValue rval(cx); |
michael@0 | 58 | CHECK(JS_CallFunctionName(cx, global, "main", JS::HandleValueArray::empty(), |
michael@0 | 59 | &rval)); |
michael@0 | 60 | CHECK_SAME(rval, INT_TO_JSVAL(123)); |
michael@0 | 61 | } |
michael@0 | 62 | return true; |
michael@0 | 63 | } |
michael@0 | 64 | END_TEST(testOps_bug559006) |
michael@0 | 65 |