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
29#ifdef OO_DEBUG_MONITOR_ENABLED
30static JSValue SpecialMarkConsoleEntryPoint(OOJS_NATIVE_ARGS);
31#endif
32
33static const JSCFunctionListEntry sSpecialFunctionsMethods[] = {
34 // JS name Function min args
35 JS_CFUNC_DEF("jsWarning", 1, SpecialJSWarning),
36#ifdef OO_DEBUG_MONITOR_ENABLED
37 JS_CFUNC_DEF("markConsoleEntryPoint", 0, SpecialMarkConsoleEntryPoint),
38#endif
39};
40
41void InitOOJSSpecialFunctions(JSContext* context, JSValueConst global)
42{
43}
44
45JSValue JSSpecialFunctionsObjectWrapper(JSContext* context)
46{
47 /*
48 Special object is created on the fly so it can be GCed (the debug
49 console script keeps a reference to its copy, but the prefix script
50 doesn't) and so we don't need to clean up a root on JS engine reset.
51 -- Ahruman 2011-03-30
52
53 With QuickJS, the caller owns the returned object.
54 */
55
56 JSValue special = JS_NewObject(context);
57 if (JS_IsException(special)) {
59 return JS_NULL;
60 }
61 JS_SetPropertyFunctionList(context, special, sSpecialFunctionsMethods, OOJS_COUNT(sSpecialFunctionsMethods));
62 JS_FreezeObject(context, special);
63
64 return special;
65}
66
68{
69 OOJS_PROFILE_ENTER // These functions are exception-safe
70
71 if (EXPECT_NOT(argc < 1))
72 {
73 OOJSReportBadArguments(context, @"special", @"jsWarning", argc, OOJS_ARGV, nil, @"string");
74 return JS_EXCEPTION;
75 }
76
78 OOJSReportWarning(context, @"%@", OOStringFromJSValue(context, OOJS_ARGV[0]));
80
82
84}
85
86#ifdef OO_DEBUG_MONITOR_ENABLED
87static JSValue SpecialMarkConsoleEntryPoint(OOJS_NATIVE_ARGS)
88{
89 /* The SpiderMonkey version recorded the calling stack frame (in eval() in
90 console.script.evaluate()) with OOJSMarkConsoleEvalLocation(), so that
91 OOJSDescribeLocation() could describe locations in console-evaluated
92 code specially. QuickJS has no stack frame API and the engine has no
93 OOJSDescribeLocation(), so this does nothing; locations in console
94 code are reported like any other.
95 */
97}
98#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,...)
void OOJSSetWarningOrErrorStackSkip(unsigned skip)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OOINLINE void OOJSReportPendingException(JSContext *context)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_VOID
return nil
#define OOJS_NATIVE_ARGS
#define OOJS_COUNT(array)