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