1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
* vim: set ts=8 sw=4 et tw=99:
4
/* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12
static int emptyTrapCallCount = 0;
15
EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
18
JS_GC(JS_GetRuntime(cx));
19
if (JSVAL_IS_STRING(closure))
21
return JSTRAP_CONTINUE;
24
BEGIN_TEST(testTrap_gc)
26
static const char source[] =
33
"({ result: sum });\n"
37
JS::RootedScript script(cx, JS_CompileScript(cx, global, source, strlen(source), __FILE__, 1));
41
JS::RootedValue v2(cx);
42
CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
44
CHECK_EQUAL(emptyTrapCallCount, 0);
47
CHECK(JS_SetDebugMode(cx, JS_TRUE));
49
static const char trapClosureText[] = "some trap closure";
51
// scope JSScript usage to make sure that it is not used after
52
// JS_ExecuteScript. This way we avoid using Anchor.
53
JS::RootedString trapClosure(cx);
55
jsbytecode *line2 = JS_LineNumberToPC(cx, script, 1);
58
jsbytecode *line6 = JS_LineNumberToPC(cx, script, 5);
61
trapClosure = JS_NewStringCopyZ(cx, trapClosureText);
63
JS_SetTrap(cx, script, line2, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
64
JS_SetTrap(cx, script, line6, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
68
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(trapClosure), trapClosureText));
72
CHECK(JS_ExecuteScript(cx, global, script, v2.address()));
73
CHECK_EQUAL(emptyTrapCallCount, 11);
77
CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(trapClosure), trapClosureText));