michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * michael@0: * Tests for operators and implicit type conversion. michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: static bool michael@0: my_convert(JSContext* context, JS::HandleObject obj, JSType type, JS::MutableHandleValue rval) michael@0: { michael@0: if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN) { michael@0: rval.set(JS_NumberValue(123)); michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static const JSClass myClass = { michael@0: "MyClass", michael@0: 0, michael@0: JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, michael@0: JS_EnumerateStub, JS_ResolveStub, my_convert michael@0: }; michael@0: michael@0: static bool michael@0: createMyObject(JSContext* context, unsigned argc, jsval *vp) michael@0: { michael@0: JS_BeginRequest(context); michael@0: michael@0: //JS_GC(context); //<- if we make GC here, all is ok michael@0: michael@0: JSObject* myObject = JS_NewObject(context, &myClass, JS::NullPtr(), JS::NullPtr()); michael@0: *vp = OBJECT_TO_JSVAL(myObject); michael@0: michael@0: JS_EndRequest(context); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: static const JSFunctionSpec s_functions[] = michael@0: { michael@0: JS_FN("createMyObject", createMyObject, 0, 0), michael@0: JS_FS_END michael@0: }; michael@0: michael@0: BEGIN_TEST(testOps_bug559006) michael@0: { michael@0: CHECK(JS_DefineFunctions(cx, global, s_functions)); michael@0: michael@0: EXEC("function main() { while(1) return 0 + createMyObject(); }"); michael@0: michael@0: for (int i = 0; i < 9; i++) { michael@0: JS::RootedValue rval(cx); michael@0: CHECK(JS_CallFunctionName(cx, global, "main", JS::HandleValueArray::empty(), michael@0: &rval)); michael@0: CHECK_SAME(rval, INT_TO_JSVAL(123)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testOps_bug559006) michael@0: