Line data Source code
1 0 : /* 2 : 3 : OOJSFunction.h 4 : 5 : Object encapsulating a runnable JavaScript function. 6 : 7 : 8 : JavaScript support for Oolite 9 : Copyright (C) 2007-2013 David Taylor and Jens Ayton. 10 : 11 : This program is free software; you can redistribute it and/or 12 : modify it under the terms of the GNU General Public License 13 : as published by the Free Software Foundation; either version 2 14 : of the License, or (at your option) any later version. 15 : 16 : This program is distributed in the hope that it will be useful, 17 : but WITHOUT ANY WARRANTY; without even the implied warranty of 18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 : GNU General Public License for more details. 20 : 21 : You should have received a copy of the GNU General Public License 22 : along with this program; if not, write to the Free Software 23 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 : MA 02110-1301, USA. 25 : 26 : */ 27 : 28 : 29 : #import "OOCocoa.h" 30 : #include <jsapi.h> 31 : 32 : 33 0 : @interface OOJSFunction: NSObject 34 : { 35 : @private 36 0 : JSFunction *_function; 37 0 : NSString *_name; 38 : } 39 : 40 0 : - (id) initWithFunction:(JSFunction *)function context:(JSContext *)context; 41 0 : - (id) initWithName:(NSString *)name 42 : scope:(JSObject *)scope // may be NULL, in which case global object is used. 43 : code:(NSString *)code // full JS code for function, including function declaration. 44 : argumentCount:(NSUInteger)argCount 45 : argumentNames:(const char **)argNames 46 : fileName:(NSString *)fileName 47 : lineNumber:(NSUInteger)lineNumber 48 : context:(JSContext *)context; // may be NULL. If not null, must be in a request. 49 : 50 0 : - (NSString *) name; 51 0 : - (JSFunction *) function; 52 0 : - (jsval) functionValue; 53 : 54 : // Raw evaluation. Context may not be NULL and must be in a request. 55 0 : - (BOOL) evaluateWithContext:(JSContext *)context 56 : scope:(JSObject *)jsThis 57 : argc:(uintN)argc 58 : argv:(jsval *)argv 59 : result:(jsval *)result; 60 : 61 : // Object-wrapper evaluation. 62 0 : - (id) evaluateWithContext:(JSContext *)context 63 : scope:(id)jsThis 64 : arguments:(NSArray *)arguments; 65 : 66 : // As above, but converts result to a boolean. 67 0 : - (BOOL) evaluatePredicateWithContext:(JSContext *)context 68 : scope:(id)jsThis 69 : arguments:(NSArray *)arguments; 70 : 71 : @end