Permalink
Browse files

Refactor narwhal-jsc, build webkit-debug version, cleanup Makefile, a…

…dd narwhal-jsc script to dispatch
  • Loading branch information...
1 parent 00f9401 commit a00f01894c1718227fed623b1941354cc14db237 tlrobinson committed Dec 29, 2009
Showing with 568 additions and 210 deletions.
  1. +28 −0 Info.plist
  2. +65 −37 Makefile
  3. +19 −0 NWDebug.h
  4. +172 −0 NWDebug.m
  5. +25 −10 bootstrap.js
  6. +36 −26 include/narwhal.h
  7. +29 −16 narwhal-jsc.c
  8. +96 −24 narwhal.c
  9. +27 −26 src/binary-engine.cc
  10. +62 −62 src/file-engine.cc
  11. +1 −1 src/io-engine.cc
  12. +5 −6 src/jack/handler/jill.cc
  13. +3 −2 src/os-engine.cc
View
28 Info.plist
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>narwhal-jsc</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.280north.narwhal-jsc</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>narwhal-jsc</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>10.5</string>
+ <key>NSPrincipalClass</key>
+ <string>NWApplication</string>
+</dict>
+</plist>
View
102 Makefile
@@ -1,5 +1,6 @@
CPP =g++
-CPPFLAGS = -0s -force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc
+CC =gcc
+CPPFLAGS = -0s -force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc
#CPPFLAGS += -g -O0
#CPPFLAGS += -DDEBUG_ON
#CPPFLAGS += -save-temps
@@ -32,62 +33,89 @@ JSCOCOA_FRAMEWORK=$(FRAMEWORKS_DIR)/JSCocoa.framework
JSCOCOA_BUILD=deps/JSCocoa/JSCocoa/build/Release/JSCocoa.framework
JSCOCOA_CHECKOUT=deps/JSCocoa
-all: jsc modules rewrite-lib-paths
-jscocoa: frameworks-jscocoa jsc-jscocoa modules rewrite-lib-paths
-webkit: jsc-webkit modules rewrite-lib-paths
+all: webkit webkit-debug jscore
+
+jscore: bin/narwhal-jscore modules config-jscore
+webkit: bin/narwhal-webkit modules config-webkit
+webkit-debug: bin/narwhal-webkit-debug modules config-webkit-debug
+jscocoa: frameworks-jscocoa bin/narwhal-jscocoa modules config-jscocoa
+
lib/libnarwhal.dylib: narwhal.c
- $(CPP) $(CPPFLAGS) $(INCLUDES) -dynamiclib -o $@ $< $(FRAMEWORKS) -framework JavaScriptCore -lreadline
+ $(CC) -o $@ $< -dynamiclib $(CPPFLAGS) $(INCLUDES) $(FRAMEWORKS) -framework JavaScriptCore -lreadline
+
+bin/narwhal-jscore: $(SOURCE) lib/libnarwhal.dylib
+ mkdir -p `dirname $@`
+ $(CC) -o $@ $(SOURCE) $(CPPFLAGS) $(INCLUDES) $(LIBS)
+ install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$@"
-jsc: $(SOURCE) lib/libnarwhal.dylib
- mkdir -p `dirname $(EXECUTABLE)`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -o $(EXECUTABLE) $(SOURCE) $(LIBS)
- install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$(EXECUTABLE)"
+bin/narwhal-webkit: $(SOURCE) lib/libnarwhal.dylib
+ mkdir -p `dirname $@`
+ $(CC) -o $@ -DWEBKIT -x objective-c $(SOURCE) $(CPPFLAGS) $(INCLUDES) $(LIBS) \
+ -framework Foundation -framework WebKit
+ install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$@"
-jsc-webkit: $(SOURCE) lib/libnarwhal.dylib
- mkdir -p `dirname $(EXECUTABLE)`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -DWEBKIT -o $(EXECUTABLE) -x objective-c $(SOURCE) $(LIBS) \
- -framework WebKit -framework Foundation -ObjC
- install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$(EXECUTABLE)"
+bin/narwhal-webkit-debug: $(SOURCE) NWDebug.m lib/libnarwhal.dylib
+ mkdir -p `dirname $@`
+ $(CC) -o $@ -DWEBKIT_DEBUG -x objective-c $(SOURCE) NWDebug.m $(CPPFLAGS) $(INCLUDES) $(LIBS) \
+ -framework Foundation -framework WebKit \
+ -framework AppKit -sectcreate __TEXT __info_plist Info.plist
+ install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$@"
-jsc-jscocoa: $(SOURCE) lib/libnarwhal.dylib
- mkdir -p `dirname $(EXECUTABLE)`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -DJSCOCOA -o $(EXECUTABLE) -x objective-c $(SOURCE) $(LIBS) \
- -framework JSCocoa -framework Foundation -ObjC
- install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$(EXECUTABLE)"
+bin/narwhal-jscocoa: $(SOURCE) lib/libnarwhal.dylib
+ mkdir -p `dirname $@`
+ $(CC) -o $@ -DJSCOCOA -x objective-c $(SOURCE) $(CPPFLAGS) $(INCLUDES) $(LIBS) \
+ -framework Foundation -framework WebKit \
+ -framework JSCocoa
+ install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" "$@"
-frameworks: $(JSCORE_FRAMEWORK)
-frameworks-jscocoa: $(JSCORE_FRAMEWORK) $(JSCOCOA_FRAMEWORK)
+config-jscore:
+ echo 'export NARWHAL_JSC_MODE="jscore"' > narwhal-jsc.conf
+ # rm -f bin/narwhal-jsc
+ # ln -s narwhal-jscore bin/narwhal-jsc
-modules: $(MODULES)
+config-webkit:
+ echo 'export NARWHAL_JSC_MODE="webkit"' > narwhal-jsc.conf
+ # rm -f bin/narwhal-jsc
+ # ln -s narwhal-webkit bin/narwhal-jsc
+
+config-webkit-debug:
+ echo 'export NARWHAL_JSC_MODE="webkit-debug"' > narwhal-jsc.conf
+ # rm -f bin/narwhal-jsc
+ # ln -s narwhal-webkit-debug bin/narwhal-jsc
+
+config-jscocoa:
+ echo 'export NARWHAL_JSC_MODE="jscocoa"' > narwhal-jsc.conf
+ # rm -f bin/narwhal-jsc
+ # ln -s narwhal-jscocoa bin/narwhal-jsc
+
+modules: $(MODULES) rewrite-lib-paths
rewrite-lib-paths:
#find lib -name "*.dylib" \! -path "*.dSYM*" -exec install_name_tool -change "$(SYSTEM_JSC)" "$(RELATIVE_JSC)" {} \;
find lib -name "*.dylib" \! -path "*.dSYM*" -exec install_name_tool -change "$(ABSOLUTE_LIBNARWHAL)" "$(RELATIVE_LIBNARWHAL)" {} \;
-
-mongoose.o: mongoose.c
- gcc $(CPPFLAGS) -W -Wall -std=c99 -pedantic -fomit-frame-pointer -c mongoose.c
-
-lib/jack/handler/mongoose.dylib: src/jack/handler/mongoose.cc mongoose.o
+
+lib/%.dylib: src/%.cc
mkdir -p `dirname $@`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -dynamiclib -o $@ $< $(LIBS) mongoose.o
+ $(CPP) -o $@ $< $(CPPFLAGS) $(INCLUDES) -dynamiclib $(LIBS)
#install_name_tool -change "$(SYSTEM_JSC)" "$(RELATIVE_JSC)" "$@"
-deps/http-parser/http_parser.o:
- cd deps/http-parser && make http_parser.o
-
lib/jack/handler/jill.dylib: src/jack/handler/jill.cc deps/http-parser/http_parser.o lib/io-engine.dylib lib/binary-engine.dylib
mkdir -p `dirname $@`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -dynamiclib -o $@ $< $(LIBS) deps/http-parser/http_parser.o lib/io-engine.dylib lib/binary-engine.dylib
+ $(CPP) -o $@ $< $(CPPFLAGS) $(INCLUDES) -dynamiclib $(LIBS) deps/http-parser/http_parser.o lib/io-engine.dylib lib/binary-engine.dylib
#install_name_tool -change "$(SYSTEM_JSC)" "$(RELATIVE_JSC)" "$@"
install_name_tool -change "lib/io-engine.dylib" "@executable_path/../lib/io-engine.dylib" "$@"
install_name_tool -change "lib/binary-engine.dylib" "@executable_path/../lib/binary-engine.dylib" "$@"
-
-lib/%.dylib: src/%.cc
- mkdir -p `dirname $@`
- $(CPP) $(CPPFLAGS) $(INCLUDES) -dynamiclib -o $@ $< $(LIBS)
- #install_name_tool -change "$(SYSTEM_JSC)" "$(RELATIVE_JSC)" "$@"
+
+deps/http-parser/http_parser.o:
+ cd deps/http-parser && make http_parser.o
+
+
+
+frameworks: $(JSCORE_FRAMEWORK)
+
+frameworks-jscocoa: $(JSCOCOA_FRAMEWORK)
$(JSCORE_FRAMEWORK): $(JSCORE_BUILD)
mkdir -p `dirname $@`
View
19 NWDebug.h
@@ -0,0 +1,19 @@
+#import <Cocoa/Cocoa.h>
+#import <WebKit/WebKit.h>
+
+@interface NWApplication : NSApplication{
+}
+@end
+
+@interface NWAppDelegate : NSObject {
+ WebView *webView;
+ NSFileHandle *stdinFileHandle;
+}
+- (void)replStart;
+@end
+
+@interface NWInspector : NSObject {
+}
+@end
+
+WebView * NW_init();
View
172 NWDebug.m
@@ -0,0 +1,172 @@
+/*
+ based on "Nibless" project from http://lapcatsoftware.com/
+ http://lapcatsoftware.com/downloads/Nibless.zip
+*/
+
+#import "NWDebug.h"
+
+#import <objc/runtime.h>
+
+//#include <narwhal.h>
+
+static int global_argc;
+static char **global_argv;
+static char **global_envp;
+static WebView *global_webView;
+
+extern int narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[], int runShell);
+
+@implementation NWApplication
+
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ [self setDelegate:[[NWAppDelegate alloc] init]];
+ [pool release];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ id delegate = [self delegate];
+ if (delegate)
+ {
+ [self setDelegate:nil];
+ [delegate release];
+ }
+ [super dealloc];
+}
+
+@end
+
+
+@implementation NWAppDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ webView = global_webView;// [[WebView alloc] init]
+
+ id inspector = [webView inspector];
+ Class inspectorClass = [[inspector class] class];
+ //class_addMethod(inspectorClass, @selector(isSelectorExcludedFromWebScript:), (IMP)NW_isSelectorExcludedFromWebScript, "B@::");
+ method_exchangeImplementations(
+ class_getClassMethod(inspectorClass, @selector(isSelectorExcludedFromWebScript:)),
+ class_getClassMethod([NWInspector class], @selector(isSelectorExcludedFromWebScript:))
+ );
+
+ id win = [webView windowScriptObject];
+ [win setValue:inspector forKey:@"_inspector"];
+
+ JSGlobalContextRef context = [[webView mainFrame] globalContext];
+ JSValueRef exception = NULL;
+ narwhal(context, &exception, global_argc, global_argv, global_envp, 0);
+ if (exception) {
+ exit(1);
+ }
+
+ [self replStart];
+
+ //[[webView inspector] show:self];
+ //[inspector showConsole:self];
+
+ [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+}
+
+- (void)replPrompt
+{
+ fprintf(stdout, "js> ");
+ fflush(stdout);
+ [stdinFileHandle readInBackgroundAndNotify];
+}
+
+- (void)replStart
+{
+ stdinFileHandle = [[NSFileHandle fileHandleWithStandardInput] retain];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(didReadStdin:)
+ name:NSFileHandleReadCompletionNotification
+ object:stdinFileHandle];
+ [self replPrompt];
+}
+
+- (void)didReadStdin:(NSNotification *)aNotification
+{
+ NSData *data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
+ NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
+
+ JSStringRef source = JSStringCreateWithUTF8CString([string UTF8String]);
+ EvaluateREPL([[webView mainFrame] globalContext], source);
+ JSStringRelease(source);
+
+ [self replPrompt];
+}
+
+@end
+
+@implementation NWInspector
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
+{
+ //if (aSelector == @selector(nameAtIndex:))
+ return NO;
+ //return YES;
+}
+
+@end
+
+
+@implementation NSBundle (NWDebug)
+
++ (BOOL)NW_loadNibNamed:(NSString *)aNibName owner:(id)owner
+{
+ BOOL didLoadNib = YES;
+ if (aNibName != nil || owner != NSApp)
+ {
+ didLoadNib = [self NW_loadNibNamed:aNibName owner:owner];
+ }
+ return didLoadNib;
+}
+
+@end
+
+
+void NW_install_NSBundle_hack()
+{
+ Class bundleClass = [NSBundle class];
+ Method originalMethod = class_getClassMethod(bundleClass, @selector(loadNibNamed:owner:));
+ Method categoryMethod = class_getClassMethod(bundleClass, @selector(NW_loadNibNamed:owner:));
+ method_exchangeImplementations(originalMethod, categoryMethod);
+}
+
+void NW_register_defaults()
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ [[NSUserDefaults standardUserDefaults] registerDefaults:
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:YES], @"WebKitDeveloperExtras",
+ [NSNumber numberWithBool:NO], @"WebKitInspectorAttached",
+
+ [NSNumber numberWithBool:YES], @"WebKit Web Inspector Setting - debuggerEnabled",
+ [NSNumber numberWithBool:YES], @"WebKit Web Inspector Setting - profilerEnabled",
+ //[NSNumber numberWithBool:YES], @"WebKit Web Inspector Setting - resourceTrackingEnabled",
+ nil]];
+
+ [pool release];
+}
+
+WebView * NW_init(int argc, char *argv[], char *envp[])
+{
+ NW_install_NSBundle_hack();
+ NW_register_defaults();
+
+ global_argc = argc;
+ global_argv = argv;
+ global_envp = envp;
+ global_webView = [[WebView alloc] init];
+
+ return global_webView;
+}
View
35 bootstrap.js
@@ -1,4 +1,11 @@
-(function (evalGlobal, global) {
+(function bootstrap(evalGlobal, global) {
+
+ var profiling = false;
+ if (typeof _inspector !== "undefined" && ENV["NARWHAL_PROFILE"]) {
+ profiling = true;
+ _inspector.startProfilingJavaScript_();
+ }
+
var debug = true;
var prefix = ENV['NARWHAL_HOME'];
@@ -11,11 +18,11 @@
var loader = {};
var factories = {};
- loader.reload = function(topId, path) {
+ loader.reload = function reload(topId, path) {
factories[topId] = requireNative(topId, path);
}
- loader.load = function(topId, path) {
+ loader.load = function load(topId, path) {
if (!factories.hasOwnProperty(topId))
loader.reload(topId, path);
return factories[topId];
@@ -24,7 +31,9 @@
return loader;
};
- var narwhal = eval(_read(prefix + "/narwhal.js"));
+ var sourceURLTag = "\n//@ sourceURL="+prefix+"/narwhal.js";
+ var narwhal = evalGlobal(_read(prefix + "/narwhal.js") + "/**/" + sourceURLTag);
+ narwhal.displayName = "narwhal";
narwhal({
global: global,
@@ -34,20 +43,26 @@
prefix: prefix,
prefixes: [enginePrefix, prefix],
debug: debug,
- print: function (string) { _print(String(string)); },
- evaluate: function (text) {
- return eval("(function(require,exports,module,system,print){" + text + "/**/\n})");
+ print: function print(string) { _print(String(string)); },
+ evaluate: function evaluate(text, fileName, lineNumber) {
+ var sourceURLTag = "\n//@ sourceURL=" + fileName;
+ //return new Function("require", "exports", "module", "system", "print", text+"/**/"+sourceURLTag);
+ return eval("(function(require,exports,module,system,print){" + text + "/**/\n})"+sourceURLTag);
},
fs: {
- read: function(path) { return _read(path); },
- isFile: function(path) { return _isFile(path); }
+ read: function read(path) { return _read(path); },
+ isFile: function isFile(path) { return _isFile(path); }
},
loaders: [[".dylib", NativeLoader()]],
os : "darwin",
debug: ENV['NARWHAL_DEBUG'],
verbose: ENV['NARWHAL_VERBOSE']
});
+
+ if (profiling) {
+ _inspector.stopProfilingJavaScript_();
+ }
-})(function () {
+})(function evalGlobal() {
return eval(arguments[0]);
}, this);
View
62 include/narwhal.h
@@ -59,7 +59,7 @@ JSValueRef JSValueMakeStringWithUTF8CString(JSContextRef, const char *);
#define HANDLE_EXCEPTION(shouldPrint, shouldReturn) \
HANDLE_EXCEPTION_BLOCK({ \
- if (shouldPrint) {fprintf(stderr, "ERROR:" THROW_DEBUG, __FILE__, __LINE__); JS_Print(*_exception);} \
+ if (shouldPrint) {fprintf(stderr, "" THROW_DEBUG, __FILE__, __LINE__); JS_Print(*_exception);} \
if (shouldReturn) return NULL; \
})
@@ -210,8 +210,17 @@ JSValueRef _TO_STRING(JSContextRef _context, JSValueRef *_exception, JSValueRef
#define JS_str_utf16(str, len) JSValueMakeStringWithUTF16(_context, (JSChar*)str, (len)/sizeof(JSChar))
//#define JS_obj(value) JSValueToObject(_context, value, _exception)
-#define JS_fn(f) JSObjectMakeFunctionWithCallback(_context, NULL, f)
-#define JS_array(count, array) JSObjectMakeArray(_context, count, array, _exception)
+
+#define JS_fn(f) _JS_fn(_context, STRINGIZE(f), f)
+JSObjectRef _JS_fn(JSContextRef _context, const char *name, JSObjectCallAsFunctionCallback f)
+{
+ JSStringRef nameStr = JSStringCreateWithUTF8CString(name);
+ JSObjectRef value = JSObjectMakeFunctionWithCallback(_context, nameStr, f);
+ JSStringRelease(nameStr);
+ return value;
+}
+
+#define JS_array(count, array) JSObjectMakeArray(_context, count, array, _exception)
#define JS_date(ms) _JS_date(_context, _exception, ms)
NWValue _JS_date(JSContextRef _context, JSValueRef* _exception, long long usec) {
@@ -254,7 +263,7 @@ bool _HAS_PROPERTY(JSContextRef _context, JSObjectRef object, const char *proper
return has;
}
-#define EXPORTS(name, object) SET_VALUE(Exports, name, object);
+#define EXPORTS(name, object) SET_VALUE(NW_Exports, name, object);
#define FUNC_HEADER(f) \
JSValueRef f( \
@@ -293,22 +302,22 @@ bool _HAS_PROPERTY(JSContextRef _context, JSObjectRef object, const char *proper
}
#define NARWHAL_MODULE(MODULE_NAME) \
- JSObjectRef Require; \
- JSObjectRef Exports; \
- JSObjectRef Module; \
- JSObjectRef System; \
- JSObjectRef Print; \
+ JSObjectRef NW_Require; \
+ JSObjectRef NW_Exports; \
+ JSObjectRef NW_Module; \
+ JSObjectRef NW_System; \
+ JSObjectRef NW_Print; \
JSContextRef _context; \
NarwhalContext narwhal_context; \
\
void print(const char * string)\
{\
JSValueRef argv[] = { JS_str_utf8(string, strlen(string)) }; \
- JSObjectCallAsFunction(_context, Print, NULL, 1, argv, NULL); \
+ JSObjectCallAsFunction(_context, NW_Print, NULL, 1, argv, NULL); \
}\
- JSObjectRef require(const char *id) {\
+ JSObjectRef NW_require(const char *id) {\
JSValueRef argv[] = { JS_str_utf8(id, strlen(id)) }; \
- return JSValueToObject(_context, JSObjectCallAsFunction(_context, Require, NULL, 1, argv, NULL), NULL); \
+ return JSValueToObject(_context, JSObjectCallAsFunction(_context, NW_Require, NULL, 1, argv, NULL), NULL); \
}\
\
const char *moduleName = STRINGIZE(MODULE_NAME);\
@@ -320,18 +329,18 @@ bool _HAS_PROPERTY(JSContextRef _context, JSObjectRef object, const char *proper
extern "C" FUNC_HEADER(MODULE_NAME) \
{ _context = _ctx; \
ARG_COUNT(5); \
- Require = JSValueToObject(_context, ARGV(0), _exception); \
+ NW_Require = JSValueToObject(_context, ARGV(0), _exception); \
if (*_exception) { return NULL; }; \
- if (!JSObjectIsFunction(_context, Require)) { THROW("Argument 0 must be a function."); } \
- Exports = JSValueToObject(_context, ARGV(1), _exception); \
+ if (!JSObjectIsFunction(_context, NW_Require)) { THROW("Argument 0 must be a function."); } \
+ NW_Exports = JSValueToObject(_context, ARGV(1), _exception); \
if (*_exception) { return NULL; }; \
- Module = JSValueToObject(_context, ARGV(2), _exception); \
+ NW_Module = JSValueToObject(_context, ARGV(2), _exception); \
if (*_exception) { return NULL; }; \
- System = JSValueToObject(_context, ARGV(3), _exception); \
+ NW_System = JSValueToObject(_context, ARGV(3), _exception); \
if (*_exception) { return NULL; }; \
- Print = JSValueToObject(_context, ARGV(4), _exception); \
+ NW_Print = JSValueToObject(_context, ARGV(4), _exception); \
if (*_exception) { return NULL; }; \
- if (!JSObjectIsFunction(_context, Print)) { THROW("Argument 4 must be a function."); } \
+ if (!JSObjectIsFunction(_context, NW_Print)) { THROW("Argument 4 must be a function."); } \
#define END_NARWHAL_MODULE \
return JS_undefined; }\
@@ -404,15 +413,15 @@ JSClassRef Custom_class(JSContextRef _context)
return jsClass;
}
-extern JSObjectRef Require;
-extern JSObjectRef Exports;
-extern JSObjectRef Module;
-extern JSObjectRef System;
-extern JSObjectRef Print;
+extern JSObjectRef NW_Require;
+extern JSObjectRef NW_Exports;
+extern JSObjectRef NW_Module;
+extern JSObjectRef NW_System;
+extern JSObjectRef NW_Print;
extern JSContextRef _context;
extern NarwhalContext narwhal_context;
extern void print(const char * string);
-extern JSObjectRef require(const char *id);
+extern JSObjectRef NW_require(const char *id);
JSObjectRef JSObjectMakeArray(JSContextRef _context, size_t argc, const JSValueRef argv[], JSValueRef* _exception);
JSObjectRef JSObjectMakeDate(JSContextRef _context, size_t argc, const JSValueRef argv[], JSValueRef* _exception);
@@ -429,8 +438,9 @@ JSValueRef _PROTECT(JSContextRef _context, JSValueRef value) {
#define PROTECT_OBJECT(value) ((NWObject)PROTECT(value))
-JSValueRef narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[]);
+int narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[], int runShell);
+void* EvaluateREPL(JSContextRef _context, JSStringRef source);
#endif
View
45 narwhal-jsc.c
@@ -7,13 +7,22 @@
#ifdef WEBKIT
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
+#elif WEBKIT_DEBUG
+#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
+#import <WebKit/WebKit.h>
+#import "NWDebug.h"
#endif
int main(int argc, char *argv[], char *envp[])
{
#ifdef WEBKIT
NSAutoreleasePool *pool = [NSAutoreleasePool new];
- WebView * webView = [[WebView alloc] init];
+ WebView *webView = [[WebView alloc] init];
+ JSGlobalContextRef _context = [[webView mainFrame] globalContext];
+ #elif WEBKIT_DEBUG
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ WebView *webView = NW_init(argc, argv, envp);
JSGlobalContextRef _context = [[webView mainFrame] globalContext];
#elif defined(JSCOCOA)
NSAutoreleasePool *pool = [NSAutoreleasePool new];
@@ -23,22 +32,26 @@ int main(int argc, char *argv[], char *envp[])
JSGlobalContextRef _context = JSGlobalContextCreate(NULL);
#endif
- JSValueRef exception = NULL;
- JSValueRef *_exception = &exception;
+ #ifdef WEBKIT_DEBUG
+ return NSApplicationMain(argc, (const char **)argv);
+ #else
+ JSValueRef exception = NULL;
+ JSValueRef *_exception = &exception;
- CALL(narwhal, argc, argv, envp);
-
- int code = 0;
- if (*_exception) {
- code = 1;
- JS_Print(*_exception);
- }
+ CALL(narwhal, argc, argv, envp, 1);
- #ifdef WEBKIT
- [pool drain];
- #elif defined(JSCOCOA)
- [pool drain];
+ int code = 0;
+ if (*_exception) {
+ code = 1;
+ JS_Print(*_exception);
+ }
+
+ #ifdef WEBKIT
+ [pool drain];
+ #elif defined(JSCOCOA)
+ [pool drain];
+ #endif
+
+ return code;
#endif
-
- return code;
}
View
120 narwhal.c
@@ -164,8 +164,32 @@ JSObjectRef argvToArray(JSGlobalContextRef _context, JSValueRef *_exception, int
return ARGS;
}
+void* EvaluateREPL(JSContextRef _context, JSStringRef source)
+{
+ static JSStringRef replTag;
+ if (!replTag)
+ replTag = JSStringCreateWithUTF8CString("<repl>");
+
+ JSValueRef exception = NULL;
+ JSValueRef *_exception = &exception;
+ if (JSCheckScriptSyntax(_context, source, 0, 0, _exception) && !(*_exception))
+ {
+ JSValueRef value = JSEvaluateScript(_context, source, 0, replTag, 0, _exception);
+ HANDLE_EXCEPTION(true, false);
+
+ if (value && !JSValueIsUndefined(_context, value)) {
+ JS_Print(value);
+ HANDLE_EXCEPTION(true, false);
+ }
+ }
+ else
+ {
+ HANDLE_EXCEPTION(true, false);
+ }
+}
+
// The read-eval-execute loop of the shell.
-void* RunShell(JSContextRef _context) {
+void* RunREPL(JSContextRef _context) {
printf("Narwhal version %s, JavaScriptCore engine\n", NARWHAL_VERSION);
while (true)
{
@@ -184,22 +208,7 @@ void* RunShell(JSContextRef _context) {
LOCK();
- JSValueRef exception = NULL;
- JSValueRef *_exception = &exception;
- if (JSCheckScriptSyntax(_context, source, 0, 0, _exception) && !(*_exception))
- {
- JSValueRef value = JSEvaluateScript(_context, source, 0, 0, 0, _exception);
- HANDLE_EXCEPTION(true, false);
-
- if (value && !JSValueIsUndefined(_context, value)) {
- JS_Print(value);
- HANDLE_EXCEPTION(true, false);
- }
- }
- else
- {
- HANDLE_EXCEPTION(true, false);
- }
+ EvaluateREPL(_context, source);
JSStringRelease(source);
@@ -212,26 +221,73 @@ void* RunShell(JSContextRef _context) {
printf("\n");
}
-JSValueRef narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[])
+JSValueRef narwhal_wrapped(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[], int runShell)
{
pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
narwhal_context.context = _context;
narwhal_context.mutex = &_mutex;
LOCK();
+
+ // TODO: cleanup all this. strcpy, sprintf, etc BAD!
+ char executable[1024];
+ char buffer[1024];
+
+ // start with the executable name from argv[0]
+ strcpy(executable, argv[0]);
+
+ // follow any symlinks
+ size_t len;
+ while ((int)(len = readlink(executable, buffer, sizeof(buffer))) >= 0) {
+ buffer[len] = '\0';
+ // make relative to symlink's directory
+ if (buffer[0] != '/') {
+ char tmp[1024];
+ strcpy(tmp, buffer);
+ sprintf(buffer, "%s/%s", (char *)dirname(executable), tmp);
+ }
+ strcpy(executable, buffer);
+ }
+
+ // make absolute
+ if (executable[0] != '/') {
+ char tmp[1024], tmp2[1024];
+ getcwd(tmp, sizeof(tmp));
+ sprintf(buffer, "%s/%s", tmp, executable);
+ strcpy(executable, buffer);
+ }
+
+ char NARWHAL_HOME[1024], NARWHAL_ENGINE_HOME[1024];
+
+ // try getting NARWHAL_ENGINE_HOME from env variable. fall back to 2nd ancestor of executable path
+ if (getenv("NARWHAL_ENGINE_HOME"))
+ strcpy(NARWHAL_ENGINE_HOME, getenv("NARWHAL_ENGINE_HOME"));
+ else
+ strcpy(NARWHAL_ENGINE_HOME, (char *)dirname((char *)dirname(executable)));
+
+ // try getting NARWHAL_HOME from env variable. fall back to 2nd ancestor of NARWHAL_ENGINE_HOME
+ if (getenv("NARWHAL_HOME"))
+ strcpy(NARWHAL_HOME, getenv("NARWHAL_HOME"));
+ else
+ strcpy(NARWHAL_HOME, (char *)dirname((char *)dirname(NARWHAL_ENGINE_HOME)));
+
+ JSObjectRef ARGS = CALL(argvToArray, argc, argv);
+ JSObjectRef ENV = CALL(envpToObject, envp);
+
+ SET_VALUE(ENV, "NARWHAL_HOME", JS_str_utf8(NARWHAL_HOME, strlen(NARWHAL_HOME)));
+ SET_VALUE(ENV, "NARWHAL_ENGINE_HOME", JS_str_utf8(NARWHAL_ENGINE_HOME, strlen(NARWHAL_ENGINE_HOME)));
JSObjectRef global = JS_GLOBAL;
SET_VALUE(global, "print", JS_fn(NW_print));
SET_VALUE(global, "isFile", JS_fn(NW_isFile));
SET_VALUE(global, "read", JS_fn(NW_read));
SET_VALUE(global, "requireNative", JS_fn(NW_requireNative));
- SET_VALUE(global, "ARGS", CALL(argvToArray, argc, argv));
- SET_VALUE(global, "ENV", CALL(envpToObject, envp));
+ SET_VALUE(global, "ARGS", ARGS);
+ SET_VALUE(global, "ENV", ENV);
// Load bootstrap.js
- char *NARWHAL_ENGINE_HOME = getenv("NARWHAL_ENGINE_HOME");
char *bootstrapPathRelative = "/bootstrap.js";
char bootstrapPathFull[strlen(NARWHAL_ENGINE_HOME) + strlen(bootstrapPathRelative) + 1];
snprintf(bootstrapPathFull, sizeof(bootstrapPathFull), "%s%s", NARWHAL_ENGINE_HOME, bootstrapPathRelative);
@@ -241,11 +297,27 @@ JSValueRef narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc
THROW("Error reading bootstrap.js\n");
}
- JSEvaluateScript(_context, bootstrapSource, 0, 0, 0, _exception);
+ JSStringRef bootstrapTag = JSStringCreateWithUTF8CString(bootstrapPathFull);
+
+ JSEvaluateScript(_context, bootstrapSource, 0, bootstrapTag, 0, _exception);
+ if (*_exception) {
+ JS_Print(*_exception);
+ }
+
JSStringRelease(bootstrapSource);
+ JSStringRelease(bootstrapTag);
UNLOCK();
- if (!*_exception && argc <= 1)
- RunShell(_context);
+ if (!*_exception && argc <= 1 && runShell)
+ RunREPL(_context);
+
+}
+
+int narwhal(JSGlobalContextRef _context, JSValueRef *_exception, int argc, char *argv[], char *envp[], int runShell)
+{
+ narwhal_wrapped(_context, _exception, argc, argv, envp, runShell);
+ if (*_exception)
+ return 1;
+ return 0;
}
View
53 src/binary-engine.cc
@@ -1,4 +1,5 @@
#include <narwhal.h>
+
#include <stdlib.h>
#include <string.h>
#include <iconv.h>
@@ -65,7 +66,7 @@ END
#endif
-FUNCTION(B_ALLOC, ARG_INT(length))
+FUNCTION(BINARY_B_ALLOC, ARG_INT(length))
{
char *buffer = (char*)calloc(length, sizeof(char));
if (!buffer)
@@ -75,14 +76,14 @@ FUNCTION(B_ALLOC, ARG_INT(length))
}
END
-FUNCTION(B_LENGTH, ARG_OBJ(bytes))
+FUNCTION(BINARY_B_LENGTH, ARG_OBJ(bytes))
{
GET_INTERNAL(BytesPrivate*, byte_data, bytes);
return JS_int(byte_data->length);
}
END
-FUNCTION(B_FILL, ARG_OBJ(bytes), ARG_INT(from), ARG_INT(to), ARG_INT(value))
+FUNCTION(BINARY_B_FILL, ARG_OBJ(bytes), ARG_INT(from), ARG_INT(to), ARG_INT(value))
{
GET_INTERNAL(BytesPrivate*, byte_data, bytes);
@@ -98,7 +99,7 @@ FUNCTION(B_FILL, ARG_OBJ(bytes), ARG_INT(from), ARG_INT(to), ARG_INT(value))
}
END
-FUNCTION(B_COPY, ARG_OBJ(src), ARG_INT(srcOffset), ARG_OBJ(dst), ARG_INT(dstOffset), ARG_INT(length))
+FUNCTION(BINARY_B_COPY, ARG_OBJ(src), ARG_INT(srcOffset), ARG_OBJ(dst), ARG_INT(dstOffset), ARG_INT(length))
{
GET_INTERNAL(BytesPrivate*, src_data, src);
GET_INTERNAL(BytesPrivate*, dst_data, dst);
@@ -112,7 +113,7 @@ FUNCTION(B_COPY, ARG_OBJ(src), ARG_INT(srcOffset), ARG_OBJ(dst), ARG_INT(dstOffs
}
END
-FUNCTION(B_GET, ARG_OBJ(bytes), ARG_INT(index))
+FUNCTION(BINARY_B_GET, ARG_OBJ(bytes), ARG_INT(index))
{
GET_INTERNAL(BytesPrivate*, bytes_data, bytes);
@@ -125,7 +126,7 @@ FUNCTION(B_GET, ARG_OBJ(bytes), ARG_INT(index))
}
END
-FUNCTION(B_SET, ARG_OBJ(bytes), ARG_INT(index), ARG_INT(value))
+FUNCTION(BINARY_B_SET, ARG_OBJ(bytes), ARG_INT(index), ARG_INT(value))
{
GET_INTERNAL(BytesPrivate*, bytes_data, bytes);
@@ -140,14 +141,14 @@ FUNCTION(B_SET, ARG_OBJ(bytes), ARG_INT(index), ARG_INT(value))
}
END
-FUNCTION(B_DECODE_DEFAULT, ARG_OBJ(bytes), ARG_INT(offset), ARG_INT(length))
+FUNCTION(BINARY_B_DECODE_DEFAULT, ARG_OBJ(bytes), ARG_INT(offset), ARG_INT(length))
{
GET_INTERNAL(BytesPrivate*, bytes_data, bytes);
return JS_str_utf8((char *)(bytes_data->buffer + offset), length);
}
END
-FUNCTION(B_ENCODE_DEFAULT, ARG_UTF8(string))
+FUNCTION(BINARY_B_ENCODE_DEFAULT, ARG_UTF8(string))
{
int length = strlen(string);
@@ -219,7 +220,7 @@ int transcode(char *src, size_t srcLength, char **dstOut, size_t *dstLengthOut,
return 1;
}
-FUNCTION(B_DECODE, ARG_OBJ(bytes), ARG_INT(offset), ARG_INT(srcLength), ARG_UTF8(codec))
+FUNCTION(BINARY_B_DECODE, ARG_OBJ(bytes), ARG_INT(offset), ARG_INT(srcLength), ARG_UTF8(codec))
{
GET_INTERNAL(BytesPrivate*, src_data, bytes);
@@ -236,13 +237,13 @@ FUNCTION(B_DECODE, ARG_OBJ(bytes), ARG_INT(offset), ARG_INT(srcLength), ARG_UTF8
}
END
-FUNCTION(B_ENCODE, ARG_STR(string), ARG_UTF8(codec))
+FUNCTION(BINARY_B_ENCODE, ARG_STR(string), ARG_UTF8(codec))
{
char *src, *dst;
size_t srcLength, dstLength;
if (!GET_UTF16(string, &src, &srcLength))
- THROW("BLAHHHHH");
+ THROW("B_ENCODE: GET_UTF16 error");
if (!transcode(src, srcLength, &dst, &dstLength, UTF_16_ENCODING, codec))
THROW("B_ENCODE: iconv error");
@@ -253,7 +254,7 @@ FUNCTION(B_ENCODE, ARG_STR(string), ARG_UTF8(codec))
}
END
-FUNCTION(B_TRANSCODE, ARG_OBJ(srcBytes), ARG_INT(srcOffset), ARG_INT(srcLength), ARG_UTF8(srcCodec), ARG_UTF8(dstCodec))
+FUNCTION(BINARY_B_TRANSCODE, ARG_OBJ(srcBytes), ARG_INT(srcOffset), ARG_INT(srcLength), ARG_UTF8(srcCodec), ARG_UTF8(dstCodec))
{
GET_INTERNAL(BytesPrivate*, src_data, srcBytes);
@@ -270,20 +271,20 @@ END
NARWHAL_MODULE(binary_engine)
{
- EXPORTS("B_LENGTH", JS_fn(B_LENGTH));
- EXPORTS("B_ALLOC", JS_fn(B_ALLOC));
- EXPORTS("B_FILL", JS_fn(B_FILL));
- EXPORTS("B_COPY", JS_fn(B_COPY));
- EXPORTS("B_GET", JS_fn(B_GET));
- EXPORTS("B_SET", JS_fn(B_SET));
-
- EXPORTS("B_DECODE", JS_fn(B_DECODE));
- EXPORTS("B_ENCODE", JS_fn(B_ENCODE));
-
- EXPORTS("B_DECODE_DEFAULT", JS_fn(B_DECODE_DEFAULT));
- EXPORTS("B_ENCODE_DEFAULT", JS_fn(B_ENCODE_DEFAULT));
-
- EXPORTS("B_TRANSCODE", JS_fn(B_TRANSCODE));
+ EXPORTS("B_LENGTH", JS_fn(BINARY_B_LENGTH));
+ EXPORTS("B_ALLOC", JS_fn(BINARY_B_ALLOC));
+ EXPORTS("B_FILL", JS_fn(BINARY_B_FILL));
+ EXPORTS("B_COPY", JS_fn(BINARY_B_COPY));
+ EXPORTS("B_GET", JS_fn(BINARY_B_GET));
+ EXPORTS("B_SET", JS_fn(BINARY_B_SET));
+
+ EXPORTS("B_DECODE", JS_fn(BINARY_B_DECODE));
+ EXPORTS("B_ENCODE", JS_fn(BINARY_B_ENCODE));
+
+ EXPORTS("B_DECODE_DEFAULT", JS_fn(BINARY_B_DECODE_DEFAULT));
+ EXPORTS("B_ENCODE_DEFAULT", JS_fn(BINARY_B_ENCODE_DEFAULT));
+
+ EXPORTS("B_TRANSCODE", JS_fn(BINARY_B_TRANSCODE));
EXPORTS("DEFAULT_CODEC", JS_str_utf8("UTF-8", strlen("UTF-8")));
}
View
124 src/file-engine.cc
@@ -14,7 +14,7 @@
NWObject io;
-FUNCTION(F_cwd)
+FUNCTION(FILE_cwd)
{
ARG_COUNT(0);
@@ -29,7 +29,7 @@ FUNCTION(F_cwd)
}
END
-FUNCTION(F_canonicalImpl, ARG_UTF8_CAST(path))
+FUNCTION(FILE_canonicalImpl, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -44,7 +44,7 @@ FUNCTION(F_canonicalImpl, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_mtime, ARG_UTF8_CAST(path))
+FUNCTION(FILE_mtime, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -59,7 +59,7 @@ FUNCTION(F_mtime, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_size, ARG_UTF8_CAST(path))
+FUNCTION(FILE_size, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -70,7 +70,7 @@ FUNCTION(F_size, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_stat, ARG_UTF8_CAST(path))
+FUNCTION(FILE_stat, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -81,7 +81,7 @@ FUNCTION(F_stat, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_exists, ARG_UTF8_CAST(path))
+FUNCTION(FILE_exists, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -92,7 +92,7 @@ FUNCTION(F_exists, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_linkExists, ARG_UTF8_CAST(path))
+FUNCTION(FILE_linkExists, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -103,7 +103,7 @@ FUNCTION(F_linkExists, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_isDirectory, ARG_UTF8_CAST(path))
+FUNCTION(FILE_isDirectory, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -114,7 +114,7 @@ FUNCTION(F_isDirectory, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_isFile, ARG_UTF8_CAST(path))
+FUNCTION(FILE_isFile, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -125,7 +125,7 @@ FUNCTION(F_isFile, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_isLink, ARG_UTF8_CAST(path))
+FUNCTION(FILE_isLink, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -136,23 +136,23 @@ FUNCTION(F_isLink, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_isReadable, ARG_UTF8_CAST(path))
+FUNCTION(FILE_isReadable, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
return JS_bool(access(PATH_OR_DOT(path), R_OK) == 0);
}
END
-FUNCTION(F_isWritable, ARG_UTF8_CAST(path))
+FUNCTION(FILE_isWritable, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
return JS_bool(access(PATH_OR_DOT(path), W_OK) == 0);
}
END
-FUNCTION(F_chmod, ARG_UTF8_CAST(path), ARG_INT(mode))
+FUNCTION(FILE_chmod, ARG_UTF8_CAST(path), ARG_INT(mode))
{
ARG_COUNT(2);
@@ -163,7 +163,7 @@ FUNCTION(F_chmod, ARG_UTF8_CAST(path), ARG_INT(mode))
}
END
-FUNCTION(F_chown, ARG_UTF8_CAST(path), ARG_UTF8_CAST(owner), ARG_UTF8_CAST(group))
+FUNCTION(FILE_chown, ARG_UTF8_CAST(path), ARG_UTF8_CAST(owner), ARG_UTF8_CAST(group))
{
ARG_COUNT(3);
@@ -173,7 +173,7 @@ FUNCTION(F_chown, ARG_UTF8_CAST(path), ARG_UTF8_CAST(owner), ARG_UTF8_CAST(group
}
END
-FUNCTION(F_link, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
+FUNCTION(FILE_link, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
{
ARG_COUNT(1);
@@ -183,7 +183,7 @@ FUNCTION(F_link, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
}
END
-FUNCTION(F_symlink, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
+FUNCTION(FILE_symlink, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
{
ARG_COUNT(2);
@@ -194,7 +194,7 @@ FUNCTION(F_symlink, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
}
END
-FUNCTION(F_renameImpl, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
+FUNCTION(FILE_renameImpl, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
{
ARG_COUNT(2);
@@ -205,7 +205,7 @@ FUNCTION(F_renameImpl, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
}
END
-//FUNCTION(F_move, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
+//FUNCTION(FILE_move, ARG_UTF8_CAST(source), ARG_UTF8_CAST(target))
//{
// ARG_COUNT(2);
//
@@ -215,7 +215,7 @@ END
//}
//END
-FUNCTION(F_remove, ARG_UTF8_CAST(path))
+FUNCTION(FILE_remove, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -226,7 +226,7 @@ FUNCTION(F_remove, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_mkdir, ARG_UTF8_CAST(path))
+FUNCTION(FILE_mkdir, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -239,7 +239,7 @@ FUNCTION(F_mkdir, ARG_UTF8_CAST(path))
}
END
-//FUNCTION(F_mkdirs, ARG_UTF8_CAST(path))
+//FUNCTION(FILE_mkdirs, ARG_UTF8_CAST(path))
//{
// ARG_COUNT(1);
//
@@ -249,7 +249,7 @@ END
//}
//END
-FUNCTION(F_rmdir, ARG_UTF8_CAST(path))
+FUNCTION(FILE_rmdir, ARG_UTF8_CAST(path))
{
ARG_COUNT(1);
@@ -260,7 +260,7 @@ FUNCTION(F_rmdir, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_list, ARG_UTF8_CAST(path))
+FUNCTION(FILE_list, ARG_UTF8_CAST(path))
{
DIR *dp;
struct dirent *dirp;
@@ -282,7 +282,7 @@ FUNCTION(F_list, ARG_UTF8_CAST(path))
}
END
-FUNCTION(F_touchImpl, ARG_UTF8_CAST(path), ARG_DOUBLE(mtime))
+FUNCTION(FILE_touchImpl, ARG_UTF8_CAST(path), ARG_DOUBLE(mtime))
{
ARG_COUNT(2);
@@ -297,10 +297,10 @@ FUNCTION(F_touchImpl, ARG_UTF8_CAST(path), ARG_DOUBLE(mtime))
}
END
-FUNCTION(F_FileIO, ARG_UTF8_CAST(path))
+FUNCTION(FILE_FileIO, ARG_UTF8_CAST(path))
{
NWObject IO = GET_OBJECT(io, "IO");
- NWObject mode_fn = GET_OBJECT(Exports, "mode");
+ NWObject mode_fn = GET_OBJECT(NW_Exports, "mode");
ARGS_ARRAY(argv, ARGV(1));
NWObject modeObject = TO_OBJECT(CALL_AS_FUNCTION(mode_fn, JS_GLOBAL, 1, argv));
@@ -360,42 +360,42 @@ END
NARWHAL_MODULE(file_engine)
{
- Exports = PROTECT_OBJECT(require("./file"));
- io = PROTECT_OBJECT(require("io"));
-
- EXPORTS("FileIO", JS_fn(F_FileIO));
-
- EXPORTS("cwd", JS_fn(F_cwd));
- //EXPORTS("canonical", JS_fn(F_canonical));
- EXPORTS("canonicalImpl", JS_fn(F_canonicalImpl));
- EXPORTS("mtime", JS_fn(F_mtime));
- EXPORTS("size", JS_fn(F_size));
- EXPORTS("stat", JS_fn(F_stat));
- EXPORTS("exists", JS_fn(F_exists));
- EXPORTS("linkExists", JS_fn(F_linkExists));
- EXPORTS("isDirectory", JS_fn(F_isDirectory));
- EXPORTS("isFile", JS_fn(F_isFile));
- EXPORTS("isLink", JS_fn(F_isLink));
- EXPORTS("isReadable", JS_fn(F_isReadable));
- EXPORTS("isWritable", JS_fn(F_isWritable));
- EXPORTS("chmod", JS_fn(F_chmod));
- EXPORTS("chown", JS_fn(F_chown));
- EXPORTS("link", JS_fn(F_link));
- EXPORTS("symlink", JS_fn(F_symlink));
- //EXPORTS("rename", JS_fn(F_rename));
- //EXPORTS("move", JS_fn(F_rename));
- EXPORTS("renameImpl", JS_fn(F_renameImpl));
- //EXPORTS("move", JS_fn(F_move));
- EXPORTS("remove", JS_fn(F_remove));
- EXPORTS("mkdir", JS_fn(F_mkdir));
- //EXPORTS("mkdirs", JS_fn(F_mkdirs));
- EXPORTS("rmdir", JS_fn(F_rmdir));
- EXPORTS("listImpl", JS_fn(F_list));
- //EXPORTS("list", JS_fn(F_list));
- EXPORTS("touchImpl", JS_fn(F_touchImpl));
- //EXPORTS("touch", JS_fn(F_touch));
-
- NWObject file_engine_js = require("file-engine.js");
+ NW_Exports = PROTECT_OBJECT(NW_require("./file"));
+ io = PROTECT_OBJECT(NW_require("io"));
+
+ EXPORTS("FileIO", JS_fn(FILE_FileIO));
+
+ EXPORTS("cwd", JS_fn(FILE_cwd));
+ //EXPORTS("canonical", JS_fn(FILE_canonical));
+ EXPORTS("canonicalImpl", JS_fn(FILE_canonicalImpl));
+ EXPORTS("mtime", JS_fn(FILE_mtime));
+ EXPORTS("size", JS_fn(FILE_size));
+ EXPORTS("stat", JS_fn(FILE_stat));
+ EXPORTS("exists", JS_fn(FILE_exists));
+ EXPORTS("linkExists", JS_fn(FILE_linkExists));
+ EXPORTS("isDirectory", JS_fn(FILE_isDirectory));
+ EXPORTS("isFile", JS_fn(FILE_isFile));
+ EXPORTS("isLink", JS_fn(FILE_isLink));
+ EXPORTS("isReadable", JS_fn(FILE_isReadable));
+ EXPORTS("isWritable", JS_fn(FILE_isWritable));
+ EXPORTS("chmod", JS_fn(FILE_chmod));
+ EXPORTS("chown", JS_fn(FILE_chown));
+ EXPORTS("link", JS_fn(FILE_link));
+ EXPORTS("symlink", JS_fn(FILE_symlink));
+ //EXPORTS("rename", JS_fn(FILE_rename));
+ //EXPORTS("move", JS_fn(FILE_rename));
+ EXPORTS("renameImpl", JS_fn(FILE_renameImpl));
+ //EXPORTS("move", JS_fn(FILE_move));
+ EXPORTS("remove", JS_fn(FILE_remove));
+ EXPORTS("mkdir", JS_fn(FILE_mkdir));
+ //EXPORTS("mkdirs", JS_fn(FILE_mkdirs));
+ EXPORTS("rmdir", JS_fn(FILE_rmdir));
+ //EXPORTS("listImpl", JS_fn(FILE_list));
+ EXPORTS("list", JS_fn(FILE_list));
+ EXPORTS("touchImpl", JS_fn(FILE_touchImpl));
+ //EXPORTS("touch", JS_fn(FILE_touch));
+
+ NWObject file_engine_js = NW_require("file-engine.js");
EXPORTS("mkdirs", GET_VALUE(file_engine_js, "mkdirs"));
EXPORTS("touch", GET_VALUE(file_engine_js, "touch"));
EXPORTS("rename", GET_VALUE(file_engine_js, "rename"));
View
2 src/io-engine.cc
@@ -421,6 +421,6 @@ NARWHAL_MODULE(io_engine)
EXPORTS("STDOUT_FILENO", JS_int(STDOUT_FILENO));
EXPORTS("STDERR_FILENO", JS_int(STDERR_FILENO));
- require("io-engine.js");
+ NW_require("io-engine.js");
}
END_NARWHAL_MODULE
View
11 src/jack/handler/jill.cc
@@ -252,7 +252,7 @@ NWValue handlerWrapper(
HANDLE_EXCEPTION(true, true);
// jsgi.erros
- SET_VALUE(env, "jsgi.errors", GET_OBJECT(System, "stderr"));
+ SET_VALUE(env, "jsgi.errors", GET_OBJECT(NW_System, "stderr"));
HANDLE_EXCEPTION(true, true);
char *body;
@@ -546,7 +546,7 @@ int on_message_complete(http_parser *parser) {
return 0;
}
-FUNCTION(Jill_run, ARG_FN(app))
+FUNCTION(JILL_run, ARG_FN(app))
{
int port = 8080;
int backlog = 100;
@@ -692,19 +692,18 @@ END
NARWHAL_MODULE(http_server_engine)
{
- EXPORTS("run", JS_fn(Jill_run));
+ EXPORTS("run", JS_fn(JILL_run));
- NWObject io = require("io");
+ NWObject io = NW_require("io");
HANDLE_EXCEPTION(true, true);
ByteIO = GET_OBJECT(io, "ByteIO");
HANDLE_EXCEPTION(true, true);
- NWObject binary = require("binary");
+ NWObject binary = NW_require("binary");
HANDLE_EXCEPTION(true, true);
ByteString = GET_OBJECT(binary, "ByteString");
HANDLE_EXCEPTION(true, true);
-
}
END_NARWHAL_MODULE
View
5 src/os-engine.cc
@@ -1,4 +1,5 @@
#include <narwhal.h>
+
#include <stdlib.h>
#include <unistd.h>
@@ -199,9 +200,9 @@ NARWHAL_MODULE(os_engine)
EXPORTS("systemImpl", JS_fn(OS_systemImpl));
EXPORTS("popenImpl", JS_fn(OS_popenImpl));
- require("os-engine.js");
+ NW_require("os-engine.js");
- NWObject io = require("io");
+ NWObject io = NW_require("io");
HANDLE_EXCEPTION(true, true);
IO = PROTECT_OBJECT(GET_OBJECT(io, "IO"));

0 comments on commit a00f018

Please sign in to comment.