Oolite
Loading...
Searching...
No Matches
OOJSSpecialFunctions.m
Go to the documentation of this file.
1/*
2
3OOJSSpecialFunctions.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27#include <jsdbgapi.h>
28
29static JSBool SpecialJSWarning(JSContext* context, uintN argc, jsval* vp);
30#ifdef OO_DEBUG_MONITOR_ENABLED
31static JSBool SpecialMarkConsoleEntryPoint(JSContext* context, uintN argc, jsval* vp);
32#endif
33
34static JSFunctionSpec sSpecialFunctionsMethods[] = {
35 // JS name Function min args
36 { "jsWarning", SpecialJSWarning, 1 },
37#ifdef OO_DEBUG_MONITOR_ENABLED
38 { "markConsoleEntryPoint", SpecialMarkConsoleEntryPoint, 0 },
39#endif
40 { 0 }
41};
42
43void InitOOJSSpecialFunctions(JSContext* context, JSObject* global)
44{
45}
46
48{
49 /*
50 Special object is created on the fly so it can be GCed (the debug
51 console script keeps a reference to its copy, but the prefix script
52 doesn't) and so we don't need to clean up a root on JS engine reset.
53 -- Ahruman 2011-03-30
54 */
55
56 JSObject* special = NULL;
57 OOJSAddGCObjectRoot(context, &special, "OOJSSpecialFunctions");
58
59 special = JS_NewObject(context, NULL, NULL, NULL);
60 JS_DefineFunctions(context, special, sSpecialFunctionsMethods);
61 JS_FreezeObject(context, special);
62
63 OOJSValue* result = [OOJSValue valueWithJSObject:special inContext:context];
64
65 JS_RemoveObjectRoot(context, &special);
66
67 return result;
68}
69
70static JSBool SpecialJSWarning(JSContext* context, uintN argc, jsval* vp)
71{
72 OOJS_PROFILE_ENTER // These functions are exception-safe
73
74 if (EXPECT_NOT(argc < 1))
75 {
76 OOJSReportBadArguments(context, @"special", @"jsWarning", argc, OOJS_ARGV, nil, @"string");
77 return NO;
78 }
79
81 OOJSReportWarning(context, @"%@", OOStringFromJSValue(context, OOJS_ARGV[0]));
83
85
87}
88
89#ifdef OO_DEBUG_MONITOR_ENABLED
90static JSBool SpecialMarkConsoleEntryPoint(JSContext* context, uintN argc, jsval* vp)
91{
92 // First stack frame will be in eval() in console.script.evaluate(), unless someone is playing silly buggers.
93
94 JSStackFrame* frame = NULL;
95 if (JS_FrameIterator(context, &frame) != NULL) {
96 OOJSMarkConsoleEvalLocation(context, frame);
97 }
98
100}
101#endif
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
static JSBool SpecialJSWarning(JSContext *context, uintN argc, jsval *vp)
static JSFunctionSpec sSpecialFunctionsMethods[]
OOJSValue * JSSpecialFunctionsObjectWrapper(JSContext *context)
void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJSMarkConsoleEvalLocation(cx, frame)
void OOJSSetWarningOrErrorStackSkip(unsigned skip)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define OOJS_ARGV
#define OOJSAddGCObjectRoot(context, root, name)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_VOID
return nil
id valueWithJSObject:inContext:(JSObject *object,[inContext] JSContext *context)