Oolite 1.91.0.7645-241119-222d325
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
26#include <jsdbgapi.h>
28
29
30static JSBool SpecialJSWarning(JSContext *context, uintN argc, jsval *vp);
31#ifndef NDEBUG
32static JSBool SpecialMarkConsoleEntryPoint(JSContext *context, uintN argc, jsval *vp);
33#endif
34
35
36static JSFunctionSpec sSpecialFunctionsMethods[] =
37{
38 // JS name Function min args
39 { "jsWarning", SpecialJSWarning, 1 },
40#ifndef NDEBUG
41 { "markConsoleEntryPoint", SpecialMarkConsoleEntryPoint, 0 },
42#endif
43 { 0 }
44};
45
46
47void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
48{
49}
50
51
53{
54 /*
55 Special object is created on the fly so it can be GCed (the debug
56 console script keeps a reference to its copy, but the prefix script
57 doesn't) and so we don't need to clean up a root on JS engine reset.
58 -- Ahruman 2011-03-30
59 */
60
61 JSObject *special = NULL;
62 OOJSAddGCObjectRoot(context, &special, "OOJSSpecialFunctions");
63
64 special = JS_NewObject(context, NULL, NULL, NULL);
65 JS_DefineFunctions(context, special, sSpecialFunctionsMethods);
66 JS_FreezeObject(context, special);
67
68 OOJSValue *result = [OOJSValue valueWithJSObject:special inContext:context];
69
70 JS_RemoveObjectRoot(context, &special);
71
72 return result;
73}
74
75
76static JSBool SpecialJSWarning(JSContext *context, uintN argc, jsval *vp)
77{
78 OOJS_PROFILE_ENTER // These functions are exception-safe
79
80 if (EXPECT_NOT(argc < 1))
81 {
82 OOJSReportBadArguments(context, @"special", @"jsWarning", argc, OOJS_ARGV, nil, @"string");
83 return NO;
84 }
85
87 OOJSReportWarning(context, @"%@", OOStringFromJSValue(context, OOJS_ARGV[0]));
89
91
93}
94
95
96#ifndef NDEBUG
97static JSBool SpecialMarkConsoleEntryPoint(JSContext *context, uintN argc, jsval *vp)
98{
99 // First stack frame will be in eval() in console.script.evaluate(), unless someone is playing silly buggers.
100
101 JSStackFrame *frame = NULL;
102 if (JS_FrameIterator(context, &frame) != NULL)
103 {
104 OOJSMarkConsoleEvalLocation(context, frame);
105 }
106
108}
109#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)
static JSBool SpecialMarkConsoleEntryPoint(JSContext *context, uintN argc, jsval *vp)
void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
void OOJSReportWarning(JSContext *context, NSString *format,...)
void OOJSSetWarningOrErrorStackSkip(unsigned skip)
void OOJSMarkConsoleEvalLocation(JSContext *context, JSStackFrame *stackFrame)
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)