1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sw=4 et tw=99:
3 : *
4 : * Tests for operators and implicit type conversion.
5 : */
6 :
7 : #include "tests.h"
8 :
9 : static JSBool
10 9 : my_convert(JSContext* context, JSObject* obj, JSType type, jsval* rval)
11 : {
12 9 : if (type == JSTYPE_VOID || type == JSTYPE_STRING || type == JSTYPE_NUMBER || type == JSTYPE_BOOLEAN)
13 9 : return JS_NewNumberValue(context, 123, rval);
14 0 : return JS_FALSE;
15 : }
16 :
17 : static JSClass myClass = {
18 : "MyClass",
19 : 0,
20 : JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
21 : JS_EnumerateStub, JS_ResolveStub, my_convert
22 : };
23 :
24 : static JSBool
25 9 : createMyObject(JSContext* context, unsigned argc, jsval *vp)
26 : {
27 9 : JS_BeginRequest(context);
28 :
29 : //JS_GC(context); //<- if we make GC here, all is ok
30 :
31 9 : JSObject* myObject = JS_NewObject(context, &myClass, NULL, NULL);
32 9 : *vp = OBJECT_TO_JSVAL(myObject);
33 :
34 9 : JS_EndRequest(context);
35 :
36 9 : return JS_TRUE;
37 : }
38 :
39 : static JSFunctionSpec s_functions[] =
40 : {
41 : { "createMyObject", createMyObject, 0 },
42 : { 0,0,0,0 }
43 : };
44 :
45 4 : BEGIN_TEST(testOps_bug559006)
46 : {
47 1 : CHECK(JS_DefineFunctions(cx, global, s_functions));
48 :
49 1 : EXEC("function main() { while(1) return 0 + createMyObject(); }");
50 :
51 10 : for (int i = 0; i < 9; i++) {
52 18 : jsvalRoot rval(cx);
53 9 : CHECK(JS_CallFunctionName(cx, global, "main", 0, NULL, rval.addr()));
54 9 : CHECK_SAME(rval, INT_TO_JSVAL(123));
55 : }
56 1 : return true;
57 : }
58 2 : END_TEST(testOps_bug559006)
59 :
|