1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
8 static int callCount[2] = {0, 0};
11 callCountHook(JSContext *cx, JSStackFrame *fp, JSBool before, JSBool *ok, void *closure)
16 JS_GetFrameThis(cx, fp, &thisv); // assert if fp is incomplete
18 return cx; // any non-null value causes the hook to be called again after
21 BEGIN_TEST(testDebugger_bug519719)
23 JS_SetCallHook(rt, callCountHook, NULL);
24 EXEC("function call(fn) { fn(0); }\n"
25 "function f(g) { for (var i = 0; i < 9; i++) call(g); }\n"
26 "f(Math.sin);\n" // record loop, starting in f
27 "f(Math.cos);\n"); // side exit in f -> call
28 CHECK(callCount[0] == 20);
29 CHECK(callCount[1] == 20);
32 END_TEST(testDebugger_bug519719)
35 nonStrictThisHook(JSContext *cx, JSStackFrame *fp, JSBool before, JSBool *ok, void *closure)
38 bool *allWrapped = (bool *) closure;
40 JS_GetFrameThis(cx, fp, &thisv);
41 *allWrapped = *allWrapped && !JSVAL_IS_PRIMITIVE(thisv);
46 BEGIN_TEST(testDebugger_getThisNonStrict)
48 bool allWrapped = true;
49 JS_SetCallHook(rt, nonStrictThisHook, (void *) &allWrapped);
50 EXEC("function nonstrict() { }\n"
51 "Boolean.prototype.nonstrict = nonstrict;\n"
52 "String.prototype.nonstrict = nonstrict;\n"
53 "Number.prototype.nonstrict = nonstrict;\n"
54 "Object.prototype.nonstrict = nonstrict;\n"
55 "nonstrict.call(true);\n"
57 "nonstrict.call('');\n"
59 "nonstrict.call(42);\n"
61 // The below don't really get 'wrapped', but it's okay.
62 "nonstrict.call(undefined);\n"
63 "nonstrict.call(null);\n"
64 "nonstrict.call({});\n"
65 "({}).nonstrict();\n");
69 END_TEST(testDebugger_getThisNonStrict)
72 strictThisHook(JSContext *cx, JSStackFrame *fp, JSBool before, JSBool *ok, void *closure)
75 bool *anyWrapped = (bool *) closure;
77 JS_GetFrameThis(cx, fp, &thisv);
78 *anyWrapped = *anyWrapped || !JSVAL_IS_PRIMITIVE(thisv);
83 BEGIN_TEST(testDebugger_getThisStrict)
85 bool anyWrapped = false;
86 JS_SetCallHook(rt, strictThisHook, (void *) &anyWrapped);
87 EXEC("function strict() { 'use strict'; }\n"
88 "Boolean.prototype.strict = strict;\n"
89 "String.prototype.strict = strict;\n"
90 "Number.prototype.strict = strict;\n"
91 "strict.call(true);\n"
97 "strict.call(undefined);\n"
98 "strict.call(null);\n");
102 END_TEST(testDebugger_getThisStrict)