1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
2 // use this file except in compliance with the License. You may obtain a copy of
3 // the License at
4 //
5 //   http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 // License for the specific language governing permissions and limitations under
11 // the License.
12 
13 #ifndef COUCHJS_UTIL_H
14 #define COUCHJS_UTIL_H
15 
16 #include <jsapi.h>
17 
18 typedef struct {
19     int          eval;
20     int          stack_size;
21     const char** scripts;
22 } couch_args;
23 
24 std::string js_to_string(JSContext* cx, JS::HandleValue val);
25 bool js_to_string(JSContext* cx, JS::HandleValue val, std::string& str);
26 JSString* string_to_js(JSContext* cx, const std::string& s);
27 
28 couch_args* couch_parse_args(int argc, const char* argv[]);
29 int couch_fgets(char* buf, int size, FILE* fp);
30 JSString* couch_readline(JSContext* cx, FILE* fp);
31 size_t couch_readfile(const char* file, char** outbuf_p);
32 void couch_print(JSContext* cx, JS::HandleValue str, bool use_stderr);
33 void couch_error(JSContext* cx, JSErrorReport* report);
34 void couch_oom(JSContext* cx, void* data);
35 bool couch_load_funcs(JSContext* cx, JS::HandleObject obj, JSFunctionSpec* funcs);
36 
37 
38 #endif // Included util.h
39