├── .gitignore ├── .gitmodules ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Nodelike Tests ├── Assert_Tests.m ├── AsyncListener_Tests.m ├── Buffer_Tests.m ├── Console_Tests.m ├── EventEmitter_Tests.m ├── NLTestCase.h ├── NLTestCase.m ├── NLTimer_Tests.m ├── Net_Tests.m ├── NextTick_Tests.m ├── Nodelike Tests-Info.plist ├── Nodelike Tests-Prefix.pch ├── Read_Tests.m ├── Resource_Tests.m ├── Stream_Tests.m ├── Util_Tests.m ├── VM_Tests.m ├── Write_Tests.m ├── en.lproj │ └── InfoPlist.strings ├── node_modules │ └── test_module │ │ ├── index.js │ │ └── node_modules │ │ ├── test_nested.js │ │ └── test_nested_folder │ │ └── index.js ├── package │ ├── test-assert.js │ ├── test-asynclistener-error-multiple-handled.js │ ├── test-asynclistener-error-multiple-mix.js │ ├── test-asynclistener-error-multiple-unhandled.js │ ├── test-asynclistener-error-net.js │ ├── test-asynclistener-error-throw-in-after.js │ ├── test-asynclistener-error-throw-in-before-multiple.js │ ├── test-asynclistener-error-throw-in-before.js │ ├── test-asynclistener-error-throw-in-error.js │ ├── test-asynclistener-error.js │ ├── test-asynclistener-multi-timeout.js │ ├── test-asynclistener-remove-add-in-before.js │ ├── test-asynclistener-remove-before.js │ ├── test-asynclistener-remove-in-before.js │ ├── test-asynclistener-remove-inflight-error.js │ ├── test-asynclistener-remove-inflight.js │ ├── test-asynclistener-run-error-once.js │ ├── test-asynclistener-run-inst-once.js │ ├── test-asynclistener-throw-before-infinite-recursion.js │ ├── test-asynclistener.js │ ├── test-buffer-ascii.js │ ├── test-buffer-concat.js │ ├── test-buffer-inspect.js │ ├── test-buffer.js │ ├── test-console-instance.js │ ├── test-console-not-call-toString.js │ ├── test-console.js │ ├── test-event-emitter-add-listeners.js │ ├── test-event-emitter-check-listener-leaks.js │ ├── test-event-emitter-listeners-side-effects.js │ ├── test-event-emitter-listeners.js │ ├── test-event-emitter-max-listeners.js │ ├── test-event-emitter-modify-in-emit.js │ ├── test-event-emitter-no-error-provided-to-error-event.js │ ├── test-event-emitter-num-args.js │ ├── test-event-emitter-once.js │ ├── test-event-emitter-remove-all-listeners.js │ ├── test-event-emitter-remove-listeners.js │ ├── test-event-emitter-set-max-listeners-side-effects.js │ ├── test-event-emitter-subclass.js │ ├── test-net-end-without-connect.js │ ├── test-net-isip.js │ ├── test-net-server-unref.js │ ├── test-next-tick-doesnt-hang.js │ ├── test-next-tick-error-spin.js │ ├── test-next-tick-errors.js │ ├── test-next-tick-intentional-starvation.js │ ├── test-next-tick-ordering.js │ ├── test-next-tick-ordering2.js │ ├── test-next-tick.js │ ├── test-readdouble.js │ ├── test-readfloat.js │ ├── test-readint.js │ ├── test-readuint.js │ ├── test-stream-big-packet.js │ ├── test-stream-big-push.js │ ├── test-stream-end-paused.js │ ├── test-stream-pipe-after-end.js │ ├── test-stream-pipe-cleanup.js │ ├── test-stream-pipe-error-handling.js │ ├── test-stream-pipe-event.js │ ├── test-stream-push-order.js │ ├── test-stream-push-strings.js │ ├── test-stream-readable-event.js │ ├── test-stream-readable-flow-recursion.js │ ├── test-stream-transform-objectmode-falsey-value.js │ ├── test-stream-unshift-empty-chunk.js │ ├── test-stream-unshift-read-race.js │ ├── test-stream-writable-decoded-encoding.js │ ├── test-stream-writev.js │ ├── test-stream2-compatibility.js │ ├── test-stream2-finish-pipe.js │ ├── test-stream2-fs.js │ ├── test-stream2-httpclient-response-end.js │ ├── test-stream2-large-read-stall.js │ ├── test-stream2-objects.js │ ├── test-stream2-pipe-error-handling.js │ ├── test-stream2-pipe-error-once-listener.js │ ├── test-stream2-push.js │ ├── test-stream2-read-sync-stack.js │ ├── test-stream2-readable-empty-buffer-no-eof.js │ ├── test-stream2-readable-from-list.js │ ├── test-stream2-readable-legacy-drain.js │ ├── test-stream2-readable-non-empty-end.js │ ├── test-stream2-readable-wrap-empty.js │ ├── test-stream2-readable-wrap.js │ ├── test-stream2-set-encoding.js │ ├── test-stream2-stderr-sync.js │ ├── test-stream2-transform.js │ ├── test-stream2-unpipe-drain.js │ ├── test-stream2-unpipe-leak.js │ ├── test-stream2-writable.js │ ├── test-stream3-pause-then-read.js │ ├── test-timers-first-fire.js │ ├── test-timers-immediate-queue.js │ ├── test-timers-immediate.js │ ├── test-timers-linked-list.js │ ├── test-timers-ordering.js │ ├── test-timers-this.js │ ├── test-timers-uncaught-exception.js │ ├── test-timers-unref.js │ ├── test-timers-zero-timeout.js │ ├── test-timers.js │ ├── test-util-debug.js │ ├── test-util-format.js │ ├── test-util-inspect.js │ ├── test-util-log.js │ ├── test-util.js │ ├── test-vm-basic.js │ ├── test-vm-context-async-script.js │ ├── test-vm-context-property-forwarding.js │ ├── test-vm-context.js │ ├── test-vm-create-and-run-in-context.js │ ├── test-vm-create-context-accessors.js │ ├── test-vm-create-context-arg.js │ ├── test-vm-create-context-circular-reference.js │ ├── test-vm-function-declaration.js │ ├── test-vm-global-define-property.js │ ├── test-vm-global-identity.js │ ├── test-vm-infinite-recursion.js │ ├── test-vm-is-context.js │ ├── test-vm-new-script-new-context.js │ ├── test-vm-new-script-this-context.js │ ├── test-vm-run-in-new-context.js │ ├── test-vm-static-this.js │ ├── test-vm-timeout.js │ ├── test-writedouble.js │ ├── test-writefloat.js │ ├── test-writeint.js │ └── test-writeuint.js └── test-common.js ├── Nodelike.podspec ├── Nodelike.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── Nodelike.xcscheme ├── Nodelike ├── NLAsync.h ├── NLAsync.m ├── NLBinding.h ├── NLBinding.m ├── NLBuffer.h ├── NLBuffer.m ├── NLCares.h ├── NLCares.m ├── NLConstants.h ├── NLConstants.m ├── NLContext.h ├── NLContext.m ├── NLContextify.h ├── NLContextify.m ├── NLFS.h ├── NLFS.m ├── NLHTTPParser.h ├── NLHTTPParser.m ├── NLHandle.h ├── NLHandle.m ├── NLNatives.h ├── NLNatives.m ├── NLProcess.h ├── NLProcess.m ├── NLSmalloc.h ├── NLSmalloc.m ├── NLStream.h ├── NLStream.m ├── NLTCP.h ├── NLTCP.m ├── NLTTY.h ├── NLTTY.m ├── NLTimer.h ├── NLTimer.m ├── NLUDP.h ├── NLUDP.m ├── NLUV.h ├── NLUV.m ├── NSObject+Nodelike.h ├── NSObject+Nodelike.m ├── Nodelike-Prefix.pch └── Nodelike.h ├── README.md ├── StyleSettings.plist ├── coveralls.rb ├── demo.gif └── lib ├── _debugger.js ├── _http_agent.js ├── _http_client.js ├── _http_common.js ├── _http_incoming.js ├── _http_outgoing.js ├── _http_server.js ├── _linklist.js ├── _stream_duplex.js ├── _stream_passthrough.js ├── _stream_readable.js ├── _stream_transform.js ├── _stream_writable.js ├── _tls_legacy.js ├── _tls_wrap.js ├── assert.js ├── buffer.js ├── child_process.js ├── cluster.js ├── console.js ├── constants.js ├── crypto.js ├── dgram.js ├── dns.js ├── domain.js ├── events.js ├── freelist.js ├── fs.js ├── http.js ├── https.js ├── module.js ├── net.js ├── node.js ├── nodelike.js ├── os.js ├── path.js ├── punycode.js ├── querystring.js ├── readline.js ├── repl.js ├── smalloc.js ├── stream.js ├── string_decoder.js ├── sys.js ├── timers.js ├── tls.js ├── tty.js ├── url.js ├── util.js ├── vm.js └── zlib.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | 4 | *.xccheckout 5 | build 6 | 7 | .idea 8 | *~ 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libuv"] 2 | path = libuv 3 | url = https://github.com/joyent/libuv.git 4 | [submodule "http-parser"] 5 | path = http-parser 6 | url = https://github.com/joyent/http-parser.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | xcode_sdk: iphonesimulator 3 | xcode_scheme: Nodelike 4 | xcode_project: Nodelike.xcodeproj 5 | notifications: 6 | flowdock: 803358c5edc46b50866b8e588b4c374b 7 | webhooks: 8 | urls: 9 | - https://webhooks.gitter.im/e/fa1f3636231a3e89e7fd 10 | on_success: change 11 | on_failure: always 12 | on_start: false 13 | hipchat: 14 | secure: PWUImx7gQYERVm1kpBaZGOE+fLVmL4WnOSuDJSTBMaD0X1kL+6wo+qPJVCrp49IIa2GWEOkCDS0ZJaaEmN1mifct4HMSkgzD9W8PbvPFc0GryYvuZEos5j+932a8opV5GnysDMeF2szZZIog2D6dePZpA9CSJLDvTwK8OxjBLDQ= 15 | env: 16 | global: 17 | secure: JKBqjntMCwpZfgbUwM3dDHINkQDsJLGiPltpSSN29n4V8FRffMEegEss/ApeSL6xme2om6oRWNuJ8FJKgWR73DbUw9A58Sd0g5kNvVvLAC6lSeCoeeFWAmcx3agYakoVByWNFhTfHRqoCE8N0fwFc7wxki4zV8WzAg/6QXm0vXA= 18 | before_script: 19 | - sudo easy_install cpp-coveralls 20 | after_success: 21 | - ./coveralls.rb --extension m --exclude-folder "Nodelike Tests" 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Nodelike CHANGELOG 2 | 3 | ## 0.1.0 4 | Inital release 5 | 6 | * Created a cocoapod 7 | [Ryan Marsh](https://github.com/ryanwmarsh) 8 | [#4](https://github.com/node-app/Nodelike/pull/4) 9 | -------------------------------------------------------------------------------- /Nodelike Tests/Assert_Tests.m: -------------------------------------------------------------------------------- 1 | #import "NLTestCase.h" 2 | 3 | @interface Assert_Tests : NLTestCase 4 | 5 | @end 6 | 7 | @implementation Assert_Tests : NLTestCase 8 | 9 | - (void)testAll { 10 | [self runWithPrefix:@"test-assert"]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Nodelike Tests/AsyncListener_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncListener_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 4/2/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NLTestCase.h" 12 | 13 | @interface AsyncListener_Tests : NLTestCase 14 | 15 | @end 16 | 17 | @implementation AsyncListener_Tests 18 | 19 | - (void)testAll { 20 | [self runWithPrefix:@"test-asynclistener"]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Nodelike Tests/Buffer_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Buffer_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/22/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface Buffer_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation Buffer_Tests 16 | 17 | - (void)testAll { 18 | [self runWithPrefix:@"test-buffer"]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Nodelike Tests/Console_Tests.m: -------------------------------------------------------------------------------- 1 | #import "NLTestCase.h" 2 | 3 | @interface Console_Tests : NLTestCase 4 | 5 | @end 6 | 7 | @implementation Console_Tests : NLTestCase 8 | 9 | - (void)testAll { 10 | [self runWithPrefix:@"test-console"]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Nodelike Tests/EventEmitter_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // EventEmitter_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 3/8/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface EventEmitter_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation EventEmitter_Tests 16 | 17 | - (void)testAll { 18 | [self runWithPrefix:@"test-event-emitter"]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Nodelike Tests/NLTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLTestCase.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 3/8/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NLTestCase : XCTestCase 12 | 13 | - (void)runWithPrefix:(NSString *)prefix skipping:(NSArray *)bad; 14 | - (void)runWithPrefix:(NSString *)prefix; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Nodelike Tests/NLTestCase.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLTestCase.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 3/8/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | #import "NLContext.h" 12 | #import "NLNatives.h" 13 | 14 | @implementation NLTestCase 15 | 16 | - (void)runWithPrefix:(NSString *)prefix { 17 | [self runWithPrefix:prefix skipping:nil]; 18 | } 19 | 20 | - (void)runWithPrefix:(NSString *)prefix skipping:(NSArray *)bad { 21 | [NLNatives.modules enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) { 22 | if ([obj hasPrefix:prefix]) { 23 | if ([bad containsObject:obj]) { 24 | NSLog(@"skipping %@", obj); 25 | return; 26 | } 27 | NSLog(@"running %@", obj); 28 | NLContext *ctx = [NLContext new]; 29 | [ctx evaluateScript:@"require_ = require; require = (function (module) { return require_(module.substr(0,9) === '../common' ? 'test-common' : module); });"]; 30 | [ctx evaluateScript:[NLNatives source:obj]]; 31 | JSValue *e = ctx.exception; 32 | if (e) 33 | XCTFail(@"%@: Context exception thrown: %@; stack: %@", obj, e, [e valueForProperty:@"stack"]); 34 | [NLContext runEventLoopSyncInContext:ctx]; 35 | [ctx emitExit]; 36 | [NLContext runEventLoopSyncInContext:ctx]; 37 | } 38 | }]; 39 | } 40 | 41 | + (void)tearDown { 42 | [super tearDown]; 43 | // flush coverage data 44 | extern void __gcov_flush(void); 45 | __gcov_flush(); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Nodelike Tests/NLTimer_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLTimer_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 1/25/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | #import "NLContext.h" 12 | 13 | @interface NLTimer_Tests : NLTestCase 14 | 15 | @end 16 | 17 | @implementation NLTimer_Tests 18 | 19 | - (void)testTimer { 20 | [self runWithPrefix:@"test-timers"]; 21 | } 22 | 23 | - (void)testSetTimeout0 { 24 | __block bool canary = false; 25 | NLContext *ctx = [NLContext new]; 26 | ctx.exceptionHandler = ^(JSContext *ctx, JSValue *e) { 27 | XCTFail(@"Context exception thrown: %@", e); 28 | }; 29 | ctx[@"callback"] = ^{ 30 | canary = true; 31 | }; 32 | [ctx evaluateScript:@"require('timers').setTimeout(callback, 0);"]; 33 | [NLContext runEventLoopAsyncInContext:ctx]; 34 | [NSThread sleepForTimeInterval:0.1f]; 35 | XCTAssertTrue(canary, @"Canary not true immediately after timeout fired."); 36 | } 37 | 38 | - (void)testSetTimeout1000 { 39 | __block bool canary = false; 40 | NLContext *ctx = [NLContext new]; 41 | ctx.exceptionHandler = ^(JSContext *ctx, JSValue *e) { 42 | XCTFail(@"Context exception thrown: %@", e); 43 | }; 44 | ctx[@"callback"] = ^{ 45 | canary = true; 46 | }; 47 | [ctx evaluateScript:@"require('timers').setTimeout(callback, 1000);"]; 48 | [NLContext runEventLoopAsyncInContext:ctx]; 49 | XCTAssertFalse(canary, @"Canary not false immediately after timeout set."); 50 | [NSThread sleepForTimeInterval:1.1f]; 51 | XCTAssertTrue(canary, @"Canary not true immediately after timeout fired."); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Nodelike Tests/Net_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Net_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 4/2/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface Net_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation Net_Tests 16 | 17 | - (void)testAll { 18 | [self runWithPrefix:@"test-net"]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Nodelike Tests/NextTick_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NextTick_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 3/2/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface NextTick_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation NextTick_Tests 16 | 17 | - (void)testAll { 18 | [self runWithPrefix:@"test-next-tick"]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Nodelike Tests/Nodelike Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.nodeapp.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Nodelike Tests/Nodelike Tests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #import 10 | #endif 11 | -------------------------------------------------------------------------------- /Nodelike Tests/Read_Tests.m: -------------------------------------------------------------------------------- 1 | #import "NLTestCase.h" 2 | 3 | @interface Read_Tests : NLTestCase 4 | 5 | @end 6 | 7 | @implementation Read_Tests : NLTestCase 8 | 9 | - (void)testAll { 10 | [self runWithPrefix:@"test-readint"]; 11 | [self runWithPrefix:@"test-readuint"]; 12 | [self runWithPrefix:@"test-readdouble"]; 13 | [self runWithPrefix:@"test-readfloat"]; 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Nodelike Tests/Stream_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Stream_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 4/2/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NLTestCase.h" 12 | 13 | @interface Stream_Tests : NLTestCase 14 | 15 | @end 16 | 17 | @implementation Stream_Tests 18 | 19 | - (void)testAll { 20 | [self runWithPrefix:@"test-stream"]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Nodelike Tests/Util_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Util_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/19/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface Util_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation Util_Tests 16 | 17 | - (void)testAll { 18 | [self runWithPrefix:@"test-util"]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Nodelike Tests/VM_Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // VM_Tests.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/19/14. 6 | // Copyright (c) 2014 Sam Rijs. All rights reserved. 7 | // 8 | 9 | #import "NLTestCase.h" 10 | 11 | @interface VM_Tests : NLTestCase 12 | 13 | @end 14 | 15 | @implementation VM_Tests 16 | 17 | - (void)testAll { 18 | NSMutableArray * bad = [NSMutableArray new]; 19 | #if !USE_PRIVATE_APIS 20 | [bad addObject:@"test-vm-timeout"]; 21 | #endif 22 | [self runWithPrefix:@"test-vm" skipping:bad]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Nodelike Tests/Write_Tests.m: -------------------------------------------------------------------------------- 1 | #import "NLTestCase.h" 2 | 3 | @interface Write_Tests : NLTestCase 4 | 5 | @end 6 | 7 | @implementation Write_Tests : NLTestCase 8 | 9 | - (void)testAll { 10 | [self runWithPrefix:@"test-write"]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Nodelike Tests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Nodelike Tests/node_modules/test_module/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | nested: require("test_nested"), 3 | nested_folder: require("test_nested_folder") 4 | }; -------------------------------------------------------------------------------- /Nodelike Tests/node_modules/test_module/node_modules/test_nested.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | foo: "bar" 4 | 5 | }; 6 | -------------------------------------------------------------------------------- /Nodelike Tests/node_modules/test_module/node_modules/test_nested_folder/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | foo: "bar folder" 4 | 5 | }; 6 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-error-multiple-handled.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var active = null; 26 | var cntr = 0; 27 | 28 | function onAsync0() { 29 | return 0; 30 | } 31 | 32 | function onAsync1() { 33 | return 1; 34 | } 35 | 36 | function onError(stor) { 37 | results.push(stor); 38 | return true; 39 | } 40 | 41 | var results = []; 42 | var asyncNoHandleError0 = { 43 | create: onAsync0, 44 | error: onError 45 | }; 46 | var asyncNoHandleError1 = { 47 | create: onAsync1, 48 | error: onError 49 | }; 50 | 51 | var listeners = [ 52 | process.addAsyncListener(asyncNoHandleError0), 53 | process.addAsyncListener(asyncNoHandleError1) 54 | ]; 55 | 56 | process.nextTick(function() { 57 | throw new Error(); 58 | }); 59 | 60 | process.removeAsyncListener(listeners[0]); 61 | process.removeAsyncListener(listeners[1]); 62 | 63 | process.on('exit', function(code) { 64 | // If the exit code isn't ok then return early to throw the stack that 65 | // caused the bad return code. 66 | if (code !== 0) 67 | return; 68 | 69 | // Handling of errors should propagate to all listeners. 70 | assert.equal(results[0], 0); 71 | assert.equal(results[1], 1); 72 | assert.equal(results.length, 2); 73 | 74 | console.log('ok'); 75 | }); 76 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-error-multiple-mix.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var results = []; 26 | var asyncNoHandleError = { 27 | error: function(stor) { 28 | results.push(1); 29 | } 30 | }; 31 | 32 | var asyncHandleError = { 33 | error: function(stor) { 34 | results.push(0); 35 | return true; 36 | } 37 | }; 38 | 39 | var listeners = [ 40 | process.addAsyncListener(asyncHandleError), 41 | process.addAsyncListener(asyncNoHandleError) 42 | ]; 43 | 44 | // Even if an error handler returns true, both should fire. 45 | process.nextTick(function() { 46 | throw new Error(); 47 | }); 48 | 49 | process.removeAsyncListener(listeners[0]); 50 | process.removeAsyncListener(listeners[1]); 51 | 52 | process.on('exit', function(code) { 53 | // If the exit code isn't ok then return early to throw the stack that 54 | // caused the bad return code. 55 | if (code !== 0) 56 | return; 57 | 58 | // Mixed handling of errors should propagate to all listeners. 59 | assert.equal(results[0], 0); 60 | assert.equal(results[1], 1); 61 | assert.equal(results.length, 2); 62 | 63 | console.log('ok'); 64 | }); 65 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-error-multiple-unhandled.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | function onAsync0() { 26 | return 0; 27 | } 28 | 29 | function onAsync1() { 30 | return 1; 31 | } 32 | 33 | function onError(stor) { 34 | results.push(stor); 35 | } 36 | 37 | var results = []; 38 | var asyncNoHandleError0 = { 39 | create: onAsync0, 40 | error: onError 41 | }; 42 | var asyncNoHandleError1 = { 43 | create: onAsync1, 44 | error: onError 45 | }; 46 | 47 | var listeners = [ 48 | process.addAsyncListener(asyncNoHandleError0), 49 | process.addAsyncListener(asyncNoHandleError1) 50 | ]; 51 | 52 | var uncaughtFired = false; 53 | process.on('uncaughtException', function() { 54 | uncaughtFired = true; 55 | 56 | // Unhandled errors should propagate to all listeners. 57 | assert.equal(results[0], 0); 58 | assert.equal(results[1], 1); 59 | assert.equal(results.length, 2); 60 | }); 61 | 62 | process.nextTick(function() { 63 | throw new Error(); 64 | }); 65 | 66 | process.on('exit', function(code) { 67 | // If the exit code isn't ok then return early to throw the stack that 68 | // caused the bad return code. 69 | if (code !== 0) 70 | return; 71 | 72 | // Need to remove the async listeners or tests will always pass 73 | for (var i = 0; i < listeners.length; i++) 74 | process.removeAsyncListener(listeners[i]); 75 | 76 | assert.ok(uncaughtFired); 77 | console.log('ok'); 78 | }); 79 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-error-throw-in-after.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var once = 0; 26 | 27 | var results = []; 28 | var handlers = { 29 | after: function() { 30 | throw 1; 31 | }, 32 | error: function(stor, err) { 33 | // Error handler must be called exactly *once*. 34 | once++; 35 | assert.equal(err, 1); 36 | return true; 37 | } 38 | } 39 | 40 | var key = process.addAsyncListener(handlers); 41 | 42 | var uncaughtFired = false; 43 | process.on('uncaughtException', function(err) { 44 | uncaughtFired = true; 45 | 46 | assert.equal(once, 1); 47 | }); 48 | 49 | process.nextTick(function() { }); 50 | 51 | process.removeAsyncListener(key); 52 | 53 | process.on('exit', function(code) { 54 | // If the exit code isn't ok then return early to throw the stack that 55 | // caused the bad return code. 56 | if (code !== 0) 57 | return; 58 | 59 | assert.ok(uncaughtFired); 60 | console.log('ok'); 61 | }); 62 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-error-throw-in-before.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var once = 0; 26 | 27 | var results = []; 28 | var handlers = { 29 | before: function() { 30 | throw 1; 31 | }, 32 | error: function(stor, err) { 33 | // Error handler must be called exactly *once*. 34 | once++; 35 | assert.equal(err, 1); 36 | return true; 37 | } 38 | } 39 | 40 | var key = process.addAsyncListener(handlers); 41 | 42 | var uncaughtFired = false; 43 | process.on('uncaughtException', function(err) { 44 | uncaughtFired = true; 45 | 46 | // Process should propagate error regardless of handlers return value. 47 | assert.equal(once, 1); 48 | }); 49 | 50 | process.nextTick(function() { }); 51 | 52 | process.removeAsyncListener(key); 53 | 54 | process.on('exit', function(code) { 55 | // If the exit code isn't ok then return early to throw the stack that 56 | // caused the bad return code. 57 | if (code !== 0) 58 | return; 59 | 60 | // Make sure that the uncaughtException actually fired. 61 | assert.ok(uncaughtFired); 62 | console.log('ok'); 63 | }); 64 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-multi-timeout.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var addListener = process.addAsyncListener; 26 | var removeListener = process.removeAsyncListener; 27 | var caught = []; 28 | var expect = []; 29 | 30 | var callbacksObj = { 31 | error: function(value, er) { 32 | process._rawDebug('caught', er.message); 33 | caught.push(er.message); 34 | return (expect.indexOf(er.message) !== -1); 35 | } 36 | }; 37 | 38 | var listener = process.createAsyncListener(callbacksObj); 39 | 40 | process.on('exit', function(code) { 41 | removeListener(listener); 42 | 43 | if (code > 0) 44 | return; 45 | 46 | expect = expect.sort(); 47 | caught = caught.sort(); 48 | 49 | process._rawDebug('expect', expect); 50 | process._rawDebug('caught', caught); 51 | assert.deepEqual(caught, expect, 'caught all expected errors'); 52 | process._rawDebug('ok'); 53 | }); 54 | 55 | 56 | expect.push('immediate simple a'); 57 | expect.push('immediate simple b'); 58 | process.nextTick(function() { 59 | addListener(listener); 60 | // Tests for a setImmediate specific bug encountered while implementing 61 | // AsyncListeners. 62 | setImmediate(function() { 63 | throw new Error('immediate simple a'); 64 | }); 65 | setImmediate(function() { 66 | throw new Error('immediate simple b'); 67 | }); 68 | removeListener(listener); 69 | }); 70 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-remove-add-in-before.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var val; 25 | var callbacks = { 26 | create: function() { 27 | return 42; 28 | }, 29 | before: function() { 30 | process.removeAsyncListener(listener); 31 | process.addAsyncListener(listener); 32 | }, 33 | after: function(context, storage) { 34 | val = storage; 35 | } 36 | }; 37 | 38 | var listener = process.addAsyncListener(callbacks); 39 | 40 | process.nextTick(function() {}); 41 | 42 | process.on('exit', function(status) { 43 | process.removeAsyncListener(listener); 44 | assert.equal(status, 0); 45 | assert.equal(val, 42); 46 | }); 47 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-remove-before.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var set = 0; 25 | 26 | var asyncNoHandleError = { 27 | before: function() { 28 | set++; 29 | }, 30 | after: function() { 31 | set++; 32 | } 33 | } 34 | 35 | var key = process.addAsyncListener(asyncNoHandleError); 36 | 37 | process.removeAsyncListener(key); 38 | 39 | process.nextTick(function() { }); 40 | 41 | process.on('exit', function(code) { 42 | // If the exit code isn't ok then return early to throw the stack that 43 | // caused the bad return code. 44 | if (code !== 0) 45 | return; 46 | 47 | // The async handler should never be called. 48 | assert.equal(set, 0); 49 | console.log('ok'); 50 | }); 51 | 52 | 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-remove-in-before.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var done = false; 25 | var callbacks = { 26 | before: function() { 27 | process.removeAsyncListener(listener); 28 | }, 29 | after: function() { 30 | done = true; 31 | } 32 | }; 33 | 34 | var listener = process.addAsyncListener(callbacks); 35 | 36 | process.nextTick(function() {}); 37 | 38 | process.on('exit', function(status) { 39 | process.removeAsyncListener(listener); 40 | assert.equal(status, 0); 41 | assert.ok(done); 42 | }); 43 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-remove-inflight-error.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var set = 0; 26 | var asyncNoHandleError = { 27 | error: function() { 28 | set++; 29 | } 30 | } 31 | 32 | var key = process.addAsyncListener(asyncNoHandleError); 33 | 34 | process.nextTick(function() { 35 | throw 1; 36 | }); 37 | 38 | process.removeAsyncListener(key); 39 | 40 | var uncaughtFired = false; 41 | process.on('uncaughtException', function() { 42 | uncaughtFired = true; 43 | 44 | // Throwing should call the error handler once, then propagate to 45 | // uncaughtException 46 | assert.equal(set, 1); 47 | }); 48 | 49 | process.on('exit', function(code) { 50 | // If the exit code isn't ok then return early to throw the stack that 51 | // caused the bad return code. 52 | if (code !== 0) 53 | return; 54 | 55 | assert.ok(uncaughtFired); 56 | console.log('ok'); 57 | }); 58 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-remove-inflight.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var set = 0; 26 | var asyncNoHandleError = { 27 | before: function() { 28 | set++; 29 | }, 30 | after: function() { 31 | set++; 32 | } 33 | } 34 | 35 | var key = process.addAsyncListener(asyncNoHandleError); 36 | 37 | process.nextTick(function() { }); 38 | 39 | process.removeAsyncListener(key); 40 | 41 | process.on('exit', function(code) { 42 | // If the exit code isn't ok then return early to throw the stack that 43 | // caused the bad return code. 44 | if (code !== 0) 45 | return; 46 | 47 | // Calling removeAsyncListener *after* a callback is scheduled 48 | // should not affect the handler from responding to the callback. 49 | assert.equal(set, 2); 50 | console.log('ok'); 51 | }); 52 | 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-run-error-once.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var net = require('net'); 25 | 26 | var cntr = 0; 27 | var al = process.addAsyncListener({ 28 | error: function(stor, er) { 29 | cntr++; 30 | process._rawDebug('Handling error: ' + er.message); 31 | return true; 32 | } 33 | }); 34 | 35 | process.on('exit', function(status) { 36 | process.removeAsyncListener(al); 37 | 38 | assert.equal(status, 0); 39 | assert.equal(cntr, 1); 40 | console.log('ok'); 41 | }); 42 | 43 | 44 | var server = net.createServer(function(c) { 45 | throw new Error('net - error: server connection'); 46 | }); 47 | 48 | 49 | server.listen(common.PORT, function() { 50 | net.connect(common.PORT, function() { 51 | setImmediate(function() { 52 | process.exit(); 53 | }); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-run-inst-once.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var cntr = 0; 26 | var al = process.createAsyncListener({ 27 | create: function() { cntr++; }, 28 | }); 29 | 30 | process.on('exit', function() { 31 | assert.equal(cntr, 4); 32 | console.log('ok'); 33 | }); 34 | 35 | process.addAsyncListener(al); 36 | 37 | process.nextTick(function() { 38 | process.addAsyncListener(al); 39 | process.nextTick(function() { 40 | process.addAsyncListener(al); 41 | process.nextTick(function() { 42 | process.nextTick(function() { }); 43 | }); 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-asynclistener-throw-before-infinite-recursion.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | // If there is an uncaughtException listener then the error thrown from 26 | // "before" will be considered handled, thus calling setImmediate to 27 | // finish execution of the nextTickQueue. This in turn will cause "before" 28 | // to fire again, entering into an infinite loop. 29 | // So the asyncQueue is cleared from the returned setImmediate in 30 | // _fatalException to prevent this from happening. 31 | var cntr = 0; 32 | 33 | 34 | process.addAsyncListener({ 35 | before: function() { 36 | if (++cntr > 1) { 37 | // Can't throw since uncaughtException will also catch that. 38 | process._rawDebug('Error: Multiple before callbacks called'); 39 | process.exit(1); 40 | } 41 | throw new Error('before'); 42 | } 43 | }); 44 | 45 | process.on('uncaughtException', function() { }); 46 | 47 | process.nextTick(); 48 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-buffer-ascii.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | // ASCII conversion in node.js simply masks off the high bits, 26 | // it doesn't do transliteration. 27 | assert.equal(Buffer('hérité').toString('ascii'), 'hC)ritC)'); 28 | 29 | // 71 characters, 78 bytes. The ’ character is a triple-byte sequence. 30 | var input = 'C’est, graphiquement, la réunion d’un accent aigu ' + 31 | 'et d’un accent grave.'; 32 | 33 | var expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' + 34 | 'db\u0000\u0019un accent aigu et db\u0000\u0019un ' + 35 | 'accent grave.'; 36 | 37 | var buf = Buffer(input); 38 | 39 | for (var i = 0; i < expected.length; ++i) { 40 | assert.equal(buf.slice(i).toString('ascii'), expected.slice(i)); 41 | 42 | // Skip remainder of multi-byte sequence. 43 | if (input.charCodeAt(i) > 65535) ++i; 44 | if (input.charCodeAt(i) > 127) ++i; 45 | } 46 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-buffer-concat.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var zero = []; 26 | var one = [ new Buffer('asdf') ]; 27 | var long = []; 28 | for (var i = 0; i < 10; i++) long.push(new Buffer('asdf')); 29 | 30 | var flatZero = Buffer.concat(zero); 31 | var flatOne = Buffer.concat(one); 32 | var flatLong = Buffer.concat(long); 33 | var flatLongLen = Buffer.concat(long, 40); 34 | 35 | assert(flatZero.length === 0); 36 | assert(flatOne.toString() === 'asdf'); 37 | assert(flatOne === one[0]); 38 | assert(flatLong.toString() === (new Array(10+1).join('asdf'))); 39 | assert(flatLongLen.toString() === (new Array(10+1).join('asdf'))); 40 | 41 | console.log("ok"); 42 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-buffer-inspect.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var util = require('util'); 26 | 27 | var buffer = require('buffer'); 28 | 29 | buffer.INSPECT_MAX_BYTES = 2; 30 | 31 | var b = new Buffer(4); 32 | b.fill('1234'); 33 | 34 | var s = new buffer.SlowBuffer(4); 35 | s.fill('1234'); 36 | 37 | var expected = ''; 38 | 39 | assert.strictEqual(util.inspect(b), expected); 40 | assert.strictEqual(util.inspect(s), expected); 41 | 42 | b = new Buffer(2); 43 | b.fill('12'); 44 | 45 | s = new buffer.SlowBuffer(2); 46 | s.fill('12'); 47 | 48 | expected = ''; 49 | 50 | assert.strictEqual(util.inspect(b), expected); 51 | assert.strictEqual(util.inspect(s), expected); 52 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-console-not-call-toString.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | 24 | 25 | var common = require('../common'); 26 | var assert = require('assert'); 27 | 28 | var func = function() {}; 29 | var toStringCalled = false; 30 | func.toString = function() { 31 | toStringCalled = true; 32 | }; 33 | 34 | require('util').inspect(func); 35 | 36 | assert.ok(!toStringCalled); 37 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-add-listeners.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | 26 | var e = new events.EventEmitter(); 27 | 28 | var events_new_listener_emited = []; 29 | var listeners_new_listener_emited = []; 30 | var times_hello_emited = 0; 31 | 32 | // sanity check 33 | assert.equal(e.addListener, e.on); 34 | 35 | e.on('newListener', function(event, listener) { 36 | console.log('newListener: ' + event); 37 | events_new_listener_emited.push(event); 38 | listeners_new_listener_emited.push(listener); 39 | }); 40 | 41 | function hello(a, b) { 42 | console.log('hello'); 43 | times_hello_emited += 1; 44 | assert.equal('a', a); 45 | assert.equal('b', b); 46 | } 47 | e.on('hello', hello); 48 | 49 | var foo = function() {}; 50 | e.once('foo', foo); 51 | 52 | console.log('start'); 53 | 54 | e.emit('hello', 'a', 'b'); 55 | 56 | 57 | // just make sure that this doesn't throw: 58 | var f = new events.EventEmitter(); 59 | f.setMaxListeners(0); 60 | 61 | 62 | process.on('exit', function() { 63 | assert.deepEqual(['hello', 'foo'], events_new_listener_emited); 64 | assert.deepEqual([hello, foo], listeners_new_listener_emited); 65 | assert.equal(1, times_hello_emited); 66 | }); 67 | 68 | 69 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-listeners-side-effects.js: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Joyent, Inc. and other Node contributors. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a 5 | // copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to permit 9 | // persons to whom the Software is furnished to do so, subject to the 10 | // following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 18 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | var common = require('../common'); 24 | var assert = require('assert'); 25 | var events = require('events'); 26 | 27 | var EventEmitter = require('events').EventEmitter; 28 | var assert = require('assert'); 29 | 30 | var e = new EventEmitter; 31 | var fl; // foo listeners 32 | 33 | fl = e.listeners('foo'); 34 | assert(Array.isArray(fl)); 35 | assert(fl.length === 0); 36 | assert.deepEqual(e._events, {}); 37 | 38 | e.on('foo', assert.fail); 39 | fl = e.listeners('foo'); 40 | assert(e._events.foo === assert.fail); 41 | assert(Array.isArray(fl)); 42 | assert(fl.length === 1); 43 | assert(fl[0] === assert.fail); 44 | 45 | e.listeners('bar'); 46 | assert(!e._events.hasOwnProperty('bar')); 47 | 48 | e.on('foo', assert.ok); 49 | fl = e.listeners('foo'); 50 | 51 | assert(Array.isArray(e._events.foo)); 52 | assert(e._events.foo.length === 2); 53 | assert(e._events.foo[0] === assert.fail); 54 | assert(e._events.foo[1] === assert.ok); 55 | 56 | assert(Array.isArray(fl)); 57 | assert(fl.length === 2); 58 | assert(fl[0] === assert.fail); 59 | assert(fl[1] === assert.ok); 60 | 61 | console.log('ok'); 62 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-listeners.js: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Joyent, Inc. and other Node contributors. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a 5 | // copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to permit 9 | // persons to whom the Software is furnished to do so, subject to the 10 | // following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 18 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | var common = require('../common'); 24 | var assert = require('assert'); 25 | var events = require('events'); 26 | 27 | function listener() {} 28 | function listener2() {} 29 | 30 | var e1 = new events.EventEmitter(); 31 | e1.on('foo', listener); 32 | var fooListeners = e1.listeners('foo'); 33 | assert.deepEqual(e1.listeners('foo'), [listener]); 34 | e1.removeAllListeners('foo'); 35 | assert.deepEqual(e1.listeners('foo'), []); 36 | assert.deepEqual(fooListeners, [listener]); 37 | 38 | var e2 = new events.EventEmitter(); 39 | e2.on('foo', listener); 40 | var e2ListenersCopy = e2.listeners('foo'); 41 | assert.deepEqual(e2ListenersCopy, [listener]); 42 | assert.deepEqual(e2.listeners('foo'), [listener]); 43 | e2ListenersCopy.push(listener2); 44 | assert.deepEqual(e2.listeners('foo'), [listener]); 45 | assert.deepEqual(e2ListenersCopy, [listener, listener2]); 46 | 47 | var e3 = new events.EventEmitter(); 48 | e3.on('foo', listener); 49 | var e3ListenersCopy = e3.listeners('foo'); 50 | e3.on('foo', listener2); 51 | assert.deepEqual(e3.listeners('foo'), [listener, listener2]); 52 | assert.deepEqual(e3ListenersCopy, [listener]); 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-max-listeners.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | 26 | var gotEvent = false; 27 | 28 | process.on('exit', function() { 29 | assert(gotEvent); 30 | }); 31 | 32 | var e = new events.EventEmitter(); 33 | 34 | e.on('maxListeners', function() { 35 | gotEvent = true; 36 | }); 37 | 38 | // Should not corrupt the 'maxListeners' queue. 39 | e.setMaxListeners(42); 40 | 41 | assert.throws(function() { 42 | e.setMaxListeners(NaN); 43 | }); 44 | 45 | assert.throws(function() { 46 | e.setMaxListeners(-1); 47 | }); 48 | 49 | assert.throws(function() { 50 | e.setMaxListeners("and even this"); 51 | }); 52 | 53 | e.emit('maxListeners'); 54 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-no-error-provided-to-error-event.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | var domain = require('domain'); 26 | 27 | var errorCatched = false; 28 | 29 | var e = new events.EventEmitter(); 30 | 31 | var d = domain.create(); 32 | d.add(e); 33 | d.on('error', function (er) { 34 | assert(er instanceof Error, 'error created'); 35 | errorCatched = true; 36 | }); 37 | 38 | e.emit('error'); 39 | 40 | process.on('exit', function () { 41 | assert(errorCatched, 'error got caught'); 42 | }); 43 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-num-args.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | 26 | var e = new events.EventEmitter(), 27 | num_args_emited = []; 28 | 29 | e.on('numArgs', function() { 30 | var numArgs = arguments.length; 31 | console.log('numArgs: ' + numArgs); 32 | num_args_emited.push(numArgs); 33 | }); 34 | 35 | console.log('start'); 36 | 37 | e.emit('numArgs'); 38 | e.emit('numArgs', null); 39 | e.emit('numArgs', null, null); 40 | e.emit('numArgs', null, null, null); 41 | e.emit('numArgs', null, null, null, null); 42 | e.emit('numArgs', null, null, null, null, null); 43 | 44 | process.on('exit', function() { 45 | assert.deepEqual([0, 1, 2, 3, 4, 5], num_args_emited); 46 | }); 47 | 48 | 49 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-once.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | 26 | var e = new events.EventEmitter(); 27 | var times_hello_emited = 0; 28 | 29 | e.once('hello', function(a, b) { 30 | times_hello_emited++; 31 | }); 32 | 33 | e.emit('hello', 'a', 'b'); 34 | e.emit('hello', 'a', 'b'); 35 | e.emit('hello', 'a', 'b'); 36 | e.emit('hello', 'a', 'b'); 37 | 38 | var remove = function() { 39 | assert.fail(1, 0, 'once->foo should not be emitted', '!'); 40 | }; 41 | 42 | e.once('foo', remove); 43 | e.removeListener('foo', remove); 44 | e.emit('foo'); 45 | 46 | process.on('exit', function() { 47 | assert.equal(1, times_hello_emited); 48 | }); 49 | 50 | var times_recurse_emitted = 0; 51 | 52 | e.once('e', function() { 53 | e.emit('e'); 54 | times_recurse_emitted++; 55 | }); 56 | 57 | e.once('e', function() { 58 | times_recurse_emitted++; 59 | }); 60 | 61 | e.emit('e'); 62 | 63 | process.on('exit', function() { 64 | assert.equal(2, times_recurse_emitted); 65 | }); 66 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-set-max-listeners-side-effects.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var events = require('events'); 25 | 26 | var e = new events.EventEmitter; 27 | 28 | assert.deepEqual(e._events, {}); 29 | e.setMaxListeners(5); 30 | assert.deepEqual(e._events, {}); 31 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-event-emitter-subclass.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var EventEmitter = require('events').EventEmitter; 25 | var util = require('util'); 26 | 27 | util.inherits(MyEE, EventEmitter); 28 | 29 | function MyEE(cb) { 30 | this.once(1, cb); 31 | this.emit(1); 32 | this.removeAllListeners(); 33 | EventEmitter.call(this); 34 | } 35 | 36 | var called = false; 37 | var myee = new MyEE(function() { 38 | called = true; 39 | }); 40 | 41 | 42 | util.inherits(ErrorEE, EventEmitter); 43 | function ErrorEE() { 44 | this.emit('error', new Error('blerg')); 45 | } 46 | 47 | assert.throws(function() { 48 | new ErrorEE(); 49 | }, /blerg/); 50 | 51 | process.on('exit', function() { 52 | assert(called); 53 | assert.deepEqual(myee._events, {}); 54 | console.log('ok'); 55 | }); 56 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-net-end-without-connect.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var net = require('net'); 24 | 25 | var sock = new net.Socket; 26 | sock.end(); // Should not throw. 27 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-net-server-unref.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var net = require('net'); 26 | var closed = false; 27 | 28 | var s = net.createServer(); 29 | s.listen(); 30 | s.unref(); 31 | 32 | setTimeout(function() { 33 | closed = true; 34 | s.close(); 35 | }, 1000).unref(); 36 | 37 | process.on('exit', function() { 38 | assert.strictEqual(closed, false, 'Unrefd socket should not hold loop open'); 39 | }); 40 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-doesnt-hang.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | /* 24 | * This test verifies that having a single nextTick statement and nothing else 25 | * does not hang the event loop. If this test times out it has failed. 26 | */ 27 | 28 | process.nextTick(function() { 29 | // Nothing 30 | }); 31 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-error-spin.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | if (process.argv[2] !== 'child') { 26 | var spawn = require('child_process').spawn; 27 | var child = spawn(process.execPath, [__filename, 'child'], { 28 | stdio: 'pipe'//'inherit' 29 | }); 30 | var timer = setTimeout(function() { 31 | throw new Error('child is hung'); 32 | }, 3000); 33 | child.on('exit', function(code) { 34 | console.error('ok'); 35 | assert(!code); 36 | clearTimeout(timer); 37 | }); 38 | } else { 39 | 40 | var domain = require('domain'); 41 | var d = domain.create(); 42 | process.maxTickDepth = 10; 43 | 44 | // in the error handler, we trigger several MakeCallback events 45 | d.on('error', function(e) { 46 | console.log('a') 47 | console.log('b') 48 | console.log('c') 49 | console.log('d') 50 | console.log('e') 51 | f(); 52 | }); 53 | 54 | function f() { 55 | process.nextTick(function() { 56 | d.run(function() { 57 | throw(new Error('x')); 58 | }); 59 | }); 60 | } 61 | 62 | f(); 63 | setTimeout(function () { 64 | console.error('broke in!'); 65 | //process.stdout.close(); 66 | //process.stderr.close(); 67 | process.exit(0); 68 | }); 69 | } 70 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-errors.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var order = [], 26 | exceptionHandled = false; 27 | 28 | // This nextTick function will throw an error. It should only be called once. 29 | // When it throws an error, it should still get removed from the queue. 30 | process.nextTick(function() { 31 | order.push('A'); 32 | // cause an error 33 | what(); 34 | }); 35 | 36 | // This nextTick function should remain in the queue when the first one 37 | // is removed. It should be called if the error in the first one is 38 | // caught (which we do in this test). 39 | process.nextTick(function() { 40 | order.push('C'); 41 | }); 42 | 43 | process.on('uncaughtException', function() { 44 | if (!exceptionHandled) { 45 | exceptionHandled = true; 46 | order.push('B'); 47 | } 48 | else { 49 | // If we get here then the first process.nextTick got called twice 50 | order.push('OOPS!'); 51 | } 52 | }); 53 | 54 | process.on('exit', function() { 55 | assert.deepEqual(['A', 'B', 'C'], order); 56 | }); 57 | 58 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-intentional-starvation.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | // this is the inverse of test-next-tick-starvation. 26 | // it verifies that process.nextTick will *always* come before other 27 | // events, up to the limit of the process.maxTickDepth value. 28 | 29 | // WARNING: unsafe! 30 | process.maxTickDepth = Infinity; 31 | 32 | var ran = false; 33 | var starved = false; 34 | var start = +new Date(); 35 | var timerRan = false; 36 | 37 | function spin() { 38 | ran = true; 39 | var now = +new Date(); 40 | if (now - start > 100) { 41 | console.log('The timer is starving, just as we planned.'); 42 | starved = true; 43 | 44 | // now let it out. 45 | return; 46 | } 47 | 48 | process.nextTick(spin); 49 | } 50 | 51 | function onTimeout() { 52 | if (!starved) throw new Error('The timer escaped!'); 53 | console.log('The timer ran once the ban was lifted'); 54 | timerRan = true; 55 | } 56 | 57 | spin(); 58 | setTimeout(onTimeout, 50); 59 | 60 | process.on('exit', function() { 61 | assert.ok(ran); 62 | assert.ok(starved); 63 | assert.ok(timerRan); 64 | }); 65 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-ordering.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var i; 25 | 26 | var N = 30; 27 | var done = []; 28 | 29 | function get_printer(timeout) { 30 | return function() { 31 | console.log('Running from setTimeout ' + timeout); 32 | done.push(timeout); 33 | }; 34 | } 35 | 36 | process.nextTick(function() { 37 | console.log('Running from nextTick'); 38 | done.push('nextTick'); 39 | }); 40 | 41 | for (i = 0; i < N; i += 1) { 42 | setTimeout(get_printer(i), i); 43 | } 44 | 45 | console.log('Running from main.'); 46 | 47 | 48 | process.on('exit', function() { 49 | assert.equal('nextTick', done[0]); 50 | /* Disabling this test. I don't think we can ensure the order 51 | for (i = 0; i < N; i += 1) { 52 | assert.equal(i, done[i + 1]); 53 | } 54 | */ 55 | }); 56 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick-ordering2.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var order = []; 26 | process.nextTick(function() { 27 | log("ordTick1"); 28 | setTimeout(function() { 29 | order.push('setTimeout'); 30 | }, 0); 31 | 32 | process.nextTick(function() { 33 | order.push('nextTick'); 34 | }); 35 | }); 36 | 37 | process.on('exit', function() { 38 | assert.deepEqual(order, ['nextTick', 'setTimeout']); 39 | }); 40 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-next-tick.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var complete = 0; 26 | 27 | process.nextTick(function() { 28 | complete++; 29 | process.nextTick(function() { 30 | complete++; 31 | process.nextTick(function() { 32 | complete++; 33 | }); 34 | }); 35 | }); 36 | 37 | setTimeout(function() { 38 | process.nextTick(function() { 39 | complete++; 40 | }); 41 | }, 50); 42 | 43 | process.nextTick(function() { 44 | complete++; 45 | }); 46 | 47 | process.on('exit', function() { 48 | assert.equal(5, complete); 49 | process.nextTick(function() { 50 | throw new Error('this should not occur'); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-end-paused.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var gotEnd = false; 25 | 26 | // Make sure we don't miss the end event for paused 0-length streams 27 | 28 | var Readable = require('stream').Readable; 29 | var stream = new Readable(); 30 | var calledRead = false; 31 | stream._read = function() { 32 | assert(!calledRead); 33 | calledRead = true; 34 | this.push(null); 35 | }; 36 | 37 | stream.on('data', function() { 38 | throw new Error('should not ever get data'); 39 | }); 40 | stream.pause(); 41 | 42 | setTimeout(function() { 43 | stream.on('end', function() { 44 | gotEnd = true; 45 | }); 46 | stream.resume(); 47 | }); 48 | 49 | process.on('exit', function() { 50 | assert(gotEnd); 51 | assert(calledRead); 52 | console.log('ok'); 53 | }); 54 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-pipe-event.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var stream = require('stream'); 24 | var assert = require('assert'); 25 | var util = require('util'); 26 | 27 | function Writable() { 28 | this.writable = true; 29 | stream.Stream.call(this); 30 | } 31 | util.inherits(Writable, stream.Stream); 32 | 33 | function Readable() { 34 | this.readable = true; 35 | stream.Stream.call(this); 36 | } 37 | util.inherits(Readable, stream.Stream); 38 | 39 | var passed = false; 40 | 41 | var w = new Writable(); 42 | w.on('pipe', function(src) { 43 | passed = true; 44 | }); 45 | 46 | var r = new Readable(); 47 | r.pipe(w); 48 | 49 | assert.ok(passed); 50 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-push-order.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common.js'); 23 | var Readable = require('stream').Readable; 24 | var assert = require('assert'); 25 | 26 | var s = new Readable({ 27 | highWaterMark: 20, 28 | encoding: 'ascii' 29 | }); 30 | 31 | var list = ['1', '2', '3', '4', '5', '6']; 32 | 33 | s._read = function (n) { 34 | var one = list.shift(); 35 | if (!one) { 36 | s.push(null); 37 | } else { 38 | var two = list.shift(); 39 | s.push(one); 40 | s.push(two); 41 | } 42 | }; 43 | 44 | var v = s.read(0); 45 | 46 | // ACTUALLY [1, 3, 5, 6, 4, 2] 47 | 48 | process.on("exit", function () { 49 | assert.deepEqual(s._readableState.buffer, 50 | ['1', '2', '3', '4', '5', '6']); 51 | console.log("ok"); 52 | }); 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-push-strings.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var Readable = require('stream').Readable; 26 | var util = require('util'); 27 | 28 | util.inherits(MyStream, Readable); 29 | function MyStream(options) { 30 | Readable.call(this, options); 31 | this._chunks = 3; 32 | } 33 | 34 | MyStream.prototype._read = function(n) { 35 | switch (this._chunks--) { 36 | case 0: 37 | return this.push(null); 38 | case 1: 39 | return setTimeout(function() { 40 | this.push('last chunk'); 41 | }.bind(this), 100); 42 | case 2: 43 | return this.push('second to last chunk'); 44 | case 3: 45 | return process.nextTick(function() { 46 | this.push('first chunk'); 47 | }.bind(this)); 48 | default: 49 | throw new Error('?'); 50 | } 51 | }; 52 | 53 | var ms = new MyStream(); 54 | var results = []; 55 | ms.on('readable', function() { 56 | var chunk; 57 | while (null !== (chunk = ms.read())) 58 | results.push(chunk + ''); 59 | }); 60 | 61 | var expect = [ 'first chunksecond to last chunk', 'last chunk' ]; 62 | process.on('exit', function() { 63 | assert.equal(ms._chunks, -1); 64 | assert.deepEqual(results, expect); 65 | console.log('ok'); 66 | }); 67 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-transform-objectmode-falsey-value.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var stream = require('stream'); 26 | var PassThrough = stream.PassThrough; 27 | 28 | var src = new PassThrough({ objectMode: true }); 29 | var tx = new PassThrough({ objectMode: true }); 30 | var dest = new PassThrough({ objectMode: true }); 31 | 32 | var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; 33 | var results = []; 34 | process.on('exit', function() { 35 | assert.deepEqual(results, expect); 36 | console.log('ok'); 37 | }); 38 | 39 | dest.on('data', function(x) { 40 | results.push(x); 41 | }); 42 | 43 | src.pipe(tx).pipe(dest); 44 | 45 | var i = -1; 46 | var int = setInterval(function() { 47 | if (i > 10) { 48 | src.end(); 49 | clearInterval(int); 50 | } else { 51 | src.write(i++); 52 | } 53 | }); 54 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream-writable-decoded-encoding.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var stream = require('stream'); 26 | var util = require('util'); 27 | 28 | function MyWritable(fn, options) { 29 | stream.Writable.call(this, options); 30 | this.fn = fn; 31 | }; 32 | 33 | util.inherits(MyWritable, stream.Writable); 34 | 35 | MyWritable.prototype._write = function (chunk, encoding, callback) { 36 | this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); 37 | callback(); 38 | }; 39 | 40 | ;(function decodeStringsTrue() { 41 | var m = new MyWritable(function(isBuffer, type, enc) { 42 | assert(isBuffer); 43 | assert.equal(type, 'object'); 44 | assert.equal(enc, 'buffer'); 45 | console.log('ok - decoded string is decoded'); 46 | }, { decodeStrings: true }); 47 | m.write('some-text', 'utf8'); 48 | m.end(); 49 | })(); 50 | 51 | ;(function decodeStringsFalse() { 52 | var m = new MyWritable(function(isBuffer, type, enc) { 53 | assert(!isBuffer); 54 | assert.equal(type, 'string'); 55 | assert.equal(enc, 'utf8'); 56 | console.log('ok - un-decoded string is not decoded'); 57 | }, { decodeStrings: false }); 58 | m.write('some-text', 'utf8'); 59 | m.end(); 60 | })(); 61 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-compatibility.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | var common = require('../common.js'); 24 | var R = require('_stream_readable'); 25 | var assert = require('assert'); 26 | 27 | var util = require('util'); 28 | var EE = require('events').EventEmitter; 29 | 30 | var ondataCalled = 0; 31 | 32 | function TestReader() { 33 | R.apply(this); 34 | this._buffer = new Buffer(100); 35 | this._buffer.fill('x'); 36 | 37 | this.on('data', function() { 38 | ondataCalled++; 39 | }); 40 | } 41 | 42 | util.inherits(TestReader, R); 43 | 44 | TestReader.prototype._read = function(n) { 45 | this.push(this._buffer); 46 | this._buffer = new Buffer(0); 47 | }; 48 | 49 | var reader = new TestReader(); 50 | setImmediate(function() { 51 | assert.equal(ondataCalled, 1); 52 | console.log('ok'); 53 | }); 54 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-finish-pipe.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common.js'); 23 | var stream = require('stream'); 24 | var Buffer = require('buffer').Buffer; 25 | 26 | var r = new stream.Readable(); 27 | r._read = function(size) { 28 | r.push(new Buffer(size)); 29 | }; 30 | 31 | var w = new stream.Writable(); 32 | w._write = function(data, encoding, cb) { 33 | cb(null); 34 | }; 35 | 36 | r.pipe(w); 37 | 38 | // This might sound unrealistic, but it happens in net.js. When 39 | // `socket.allowHalfOpen === false`, EOF will cause `.destroySoon()` call which 40 | // ends the writable side of net.Socket. 41 | w.end(); 42 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-fs.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | var common = require('../common.js'); 24 | var R = require('_stream_readable'); 25 | var assert = require('assert'); 26 | 27 | var fs = require('fs'); 28 | var FSReadable = fs.ReadStream; 29 | 30 | var path = require('path'); 31 | var file = path.resolve(common.fixturesDir, 'x1024.txt'); 32 | 33 | var size = fs.statSync(file).size; 34 | 35 | var expectLengths = [1024]; 36 | 37 | var util = require('util'); 38 | var Stream = require('stream'); 39 | 40 | util.inherits(TestWriter, Stream); 41 | 42 | function TestWriter() { 43 | Stream.apply(this); 44 | this.buffer = []; 45 | this.length = 0; 46 | } 47 | 48 | TestWriter.prototype.write = function(c) { 49 | this.buffer.push(c.toString()); 50 | this.length += c.length; 51 | return true; 52 | }; 53 | 54 | TestWriter.prototype.end = function(c) { 55 | if (c) this.buffer.push(c.toString()); 56 | this.emit('results', this.buffer); 57 | } 58 | 59 | var r = new FSReadable(file); 60 | var w = new TestWriter(); 61 | 62 | w.on('results', function(res) { 63 | console.error(res, w.length); 64 | assert.equal(w.length, size); 65 | var l = 0; 66 | assert.deepEqual(res.map(function (c) { 67 | return c.length; 68 | }), expectLengths); 69 | console.log('ok'); 70 | }); 71 | 72 | r.pipe(w); 73 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-httpclient-response-end.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common.js'); 23 | var assert = require('assert'); 24 | var http = require('http'); 25 | var msg = 'Hello'; 26 | var readable_event = false; 27 | var end_event = false; 28 | var server = http.createServer(function(req, res) { 29 | res.writeHead(200, {'Content-Type': 'text/plain'}); 30 | res.end(msg); 31 | }).listen(common.PORT, function() { 32 | http.get({port: common.PORT}, function(res) { 33 | var data = ''; 34 | res.on('readable', function() { 35 | console.log('readable event'); 36 | readable_event = true; 37 | data += res.read(); 38 | }); 39 | res.on('end', function() { 40 | console.log('end event'); 41 | end_event = true; 42 | assert.strictEqual(msg, data); 43 | server.close(); 44 | }); 45 | }); 46 | }); 47 | 48 | process.on('exit', function() { 49 | assert(readable_event); 50 | assert(end_event); 51 | }); 52 | 53 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-pipe-error-once-listener.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | var common = require('../common.js'); 24 | var assert = require('assert'); 25 | 26 | var util = require('util'); 27 | var stream = require('stream'); 28 | 29 | 30 | var Read = function() { 31 | stream.Readable.call(this); 32 | }; 33 | util.inherits(Read, stream.Readable); 34 | 35 | Read.prototype._read = function(size) { 36 | this.push('x'); 37 | this.push(null); 38 | }; 39 | 40 | 41 | var Write = function() { 42 | stream.Writable.call(this); 43 | }; 44 | util.inherits(Write, stream.Writable); 45 | 46 | Write.prototype._write = function(buffer, encoding, cb) { 47 | this.emit('error', new Error('boom')); 48 | this.emit('alldone'); 49 | }; 50 | 51 | var read = new Read(); 52 | var write = new Write(); 53 | 54 | write.once('error', function(err) {}); 55 | write.once('alldone', function(err) { 56 | console.log('ok'); 57 | }); 58 | 59 | process.on('exit', function(c) { 60 | console.error('error thrown even with listener'); 61 | }); 62 | 63 | read.pipe(write); 64 | 65 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-read-sync-stack.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var Readable = require('stream').Readable; 25 | var r = new Readable(); 26 | var N = 256 * 1024; 27 | 28 | // Go ahead and allow the pathological case for this test. 29 | // Yes, it's an infinite loop, that's the point. 30 | process.maxTickDepth = N + 2; 31 | 32 | var reads = 0; 33 | r._read = function(n) { 34 | var chunk = reads++ === N ? null : new Buffer(1); 35 | r.push(chunk); 36 | }; 37 | 38 | r.on('readable', function onReadable() { 39 | if (!(r._readableState.length % 256)) 40 | console.error('readable', r._readableState.length); 41 | r.read(N * 2); 42 | }); 43 | 44 | var ended = false; 45 | r.on('end', function onEnd() { 46 | ended = true; 47 | }); 48 | 49 | r.read(0); 50 | 51 | process.on('exit', function() { 52 | assert(ended); 53 | console.log('ok'); 54 | }); 55 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-readable-legacy-drain.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var Stream = require('stream'); 26 | var Readable = Stream.Readable; 27 | 28 | var r = new Readable(); 29 | var N = 256; 30 | var reads = 0; 31 | r._read = function(n) { 32 | return r.push(++reads === N ? null : new Buffer(1)); 33 | }; 34 | 35 | var rended = false; 36 | r.on('end', function() { 37 | rended = true; 38 | }); 39 | 40 | var w = new Stream(); 41 | w.writable = true; 42 | var writes = 0; 43 | var buffered = 0; 44 | w.write = function(c) { 45 | writes += c.length; 46 | buffered += c.length; 47 | process.nextTick(drain); 48 | return false; 49 | }; 50 | 51 | function drain() { 52 | assert(buffered <= 2); 53 | buffered = 0; 54 | w.emit('drain'); 55 | } 56 | 57 | 58 | var wended = false; 59 | w.end = function() { 60 | wended = true; 61 | }; 62 | 63 | // Just for kicks, let's mess with the drain count. 64 | // This verifies that even if it gets negative in the 65 | // pipe() cleanup function, we'll still function properly. 66 | r.on('readable', function() { 67 | w.emit('drain'); 68 | }); 69 | 70 | r.pipe(w); 71 | process.on('exit', function() { 72 | assert(rended); 73 | assert(wended); 74 | console.error('ok'); 75 | }); 76 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-readable-non-empty-end.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var assert = require('assert'); 23 | var common = require('../common.js'); 24 | var Readable = require('_stream_readable'); 25 | 26 | var len = 0; 27 | var chunks = new Array(10); 28 | for (var i = 1; i <= 10; i++) { 29 | chunks[i-1] = new Buffer(i); 30 | len += i; 31 | } 32 | 33 | var test = new Readable(); 34 | var n = 0; 35 | test._read = function(size) { 36 | var chunk = chunks[n++]; 37 | setTimeout(function() { 38 | test.push(chunk); 39 | }); 40 | }; 41 | 42 | test.on('end', thrower); 43 | function thrower() { 44 | throw new Error('this should not happen!'); 45 | } 46 | 47 | var bytesread = 0; 48 | test.on('readable', function() { 49 | var b = len - bytesread - 1; 50 | var res = test.read(b); 51 | if (res) { 52 | bytesread += res.length; 53 | console.error('br=%d len=%d', bytesread, len); 54 | setTimeout(next); 55 | } 56 | test.read(0); 57 | }); 58 | test.read(0); 59 | 60 | function next() { 61 | // now let's make 'end' happen 62 | test.removeListener('end', thrower); 63 | 64 | var endEmitted = false; 65 | process.on('exit', function() { 66 | assert(endEmitted, 'end should be emitted by now'); 67 | }); 68 | test.on('end', function() { 69 | endEmitted = true; 70 | }); 71 | 72 | // one to get the last byte 73 | var r = test.read(); 74 | assert(r); 75 | assert.equal(r.length, 1); 76 | r = test.read(); 77 | assert.equal(r, null); 78 | } 79 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-readable-wrap-empty.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var Readable = require('_stream_readable'); 26 | var EE = require('events').EventEmitter; 27 | 28 | var oldStream = new EE(); 29 | oldStream.pause = function(){}; 30 | oldStream.resume = function(){}; 31 | 32 | var newStream = new Readable().wrap(oldStream); 33 | 34 | var ended = false; 35 | newStream 36 | .on('readable', function(){}) 37 | .on('end', function(){ ended = true; }); 38 | 39 | oldStream.emit('end'); 40 | 41 | process.on('exit', function(){ 42 | assert.ok(ended); 43 | }); 44 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-stream2-unpipe-drain.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | var common = require('../common.js'); 24 | var assert = require('assert'); 25 | var stream = require('stream'); 26 | var crypto = require('crypto'); 27 | 28 | var util = require('util'); 29 | 30 | function TestWriter() { 31 | stream.Writable.call(this); 32 | } 33 | util.inherits(TestWriter, stream.Writable); 34 | 35 | TestWriter.prototype._write = function (buffer, encoding, callback) { 36 | console.log('write called'); 37 | // super slow write stream (callback never called) 38 | }; 39 | 40 | var dest = new TestWriter(); 41 | 42 | function TestReader(id) { 43 | stream.Readable.call(this); 44 | this.reads = 0; 45 | } 46 | util.inherits(TestReader, stream.Readable); 47 | 48 | TestReader.prototype._read = function (size) { 49 | this.reads += 1; 50 | this.push(crypto.randomBytes(size)); 51 | }; 52 | 53 | var src1 = new TestReader(); 54 | var src2 = new TestReader(); 55 | 56 | src1.pipe(dest); 57 | 58 | src1.once('readable', function () { 59 | process.nextTick(function () { 60 | 61 | src2.pipe(dest); 62 | 63 | src2.once('readable', function () { 64 | process.nextTick(function () { 65 | 66 | src1.unpipe(dest); 67 | }); 68 | }); 69 | }); 70 | }); 71 | 72 | 73 | process.on('exit', function () { 74 | assert.equal(src1.reads, 2); 75 | assert.equal(src2.reads, 2); 76 | }); 77 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-first-fire.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var TIMEOUT = 50; 26 | var last = process.hrtime(); 27 | setTimeout(function() { 28 | var hr = process.hrtime(last); 29 | var ms = (hr[0] * 1e3) + (hr[1] / 1e6); 30 | var delta = ms - TIMEOUT; 31 | console.log('timer fired in', delta); 32 | assert.ok(delta > 0, 'Timer fired early'); 33 | }, TIMEOUT); 34 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-immediate-queue.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | // setImmediate should run clear its queued cbs once per event loop turn 26 | // but immediates queued while processing the current queue should happen 27 | // on the next turn of the event loop. 28 | 29 | // in v0.10 hit should be 1, because we only process one cb per turn 30 | // in v0.11 and beyond it should be the exact same size of QUEUE 31 | // if we're letting things recursively add to the immediate QUEUE hit will be 32 | // > QUEUE 33 | 34 | var ticked = false; 35 | 36 | var hit = 0; 37 | var QUEUE = 1000; 38 | 39 | function run() { 40 | if (hit === 0) 41 | process.nextTick(function() { ticked = true; }); 42 | 43 | if (ticked) return; 44 | 45 | hit += 1; 46 | setImmediate(run); 47 | } 48 | 49 | for (var i = 0; i < QUEUE; i++) 50 | setImmediate(run); 51 | 52 | process.on('exit', function() { 53 | console.log('hit', hit); 54 | assert.strictEqual(hit, QUEUE, 'We ticked between the immediate queue'); 55 | }); 56 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-immediate.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var immediateA = false, 26 | immediateB = false, 27 | immediateC = [], 28 | before; 29 | 30 | setImmediate(function() { 31 | try { 32 | immediateA = process.hrtime(before); 33 | } catch(e) { 34 | console.log('failed to get hrtime with offset'); 35 | } 36 | clearImmediate(immediateB); 37 | }); 38 | 39 | before = process.hrtime(); 40 | 41 | immediateB = setImmediate(function() { 42 | immediateB = true; 43 | }); 44 | 45 | setImmediate(function(x, y, z) { 46 | immediateC = [x, y, z]; 47 | }, 1, 2, 3); 48 | 49 | process.on('exit', function() { 50 | assert.ok(immediateA, 'Immediate should happen after normal execution'); 51 | assert.notStrictEqual(immediateB, true, 'immediateB should not fire'); 52 | assert.deepEqual(immediateC, [1, 2, 3], 'immediateC args should match'); 53 | }); 54 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-ordering.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var i; 25 | 26 | var N = 30; 27 | 28 | var last_i = 0; 29 | var last_ts = 0; 30 | var start = Date.now(); 31 | 32 | var f = function(i) { 33 | if (i <= N) { 34 | // check order 35 | assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' + last_i + ' + 1'); 36 | last_i = i; 37 | 38 | // check that this iteration is fired at least 1ms later than the previous 39 | var now = Date.now(); 40 | console.log(i, now); 41 | assert(now >= last_ts + 1, 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); 42 | last_ts = now; 43 | 44 | // schedule next iteration 45 | setTimeout(f, 1, i + 1); 46 | } 47 | }; 48 | f(1); 49 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-this.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var assert = require('assert'); 23 | 24 | var immediateThis, intervalThis, timeoutThis, 25 | immediateArgsThis, intervalArgsThis, timeoutArgsThis; 26 | 27 | /* 28 | var immediateHandler = setImmediate(function () { 29 | immediateThis = this; 30 | }); 31 | 32 | var immediateArgsHandler = setImmediate(function () { 33 | immediateArgsThis = this; 34 | }, "args ..."); 35 | */ 36 | 37 | var intervalHandler = setInterval(function () { 38 | clearInterval(intervalHandler); 39 | 40 | intervalThis = this; 41 | }); 42 | 43 | var intervalArgsHandler = setInterval(function () { 44 | clearInterval(intervalArgsHandler); 45 | 46 | intervalArgsThis = this; 47 | }, 0, "args ..."); 48 | 49 | var timeoutHandler = setTimeout(function () { 50 | timeoutThis = this; 51 | }); 52 | 53 | var timeoutArgsHandler = setTimeout(function () { 54 | timeoutArgsThis = this; 55 | }, 0, "args ..."); 56 | 57 | process.once('exit', function () { 58 | assert.strictEqual(immediateThis, immediateHandler); 59 | assert.strictEqual(immediateArgsThis, immediateArgsHandler); 60 | 61 | assert.strictEqual(intervalThis, intervalHandler); 62 | assert.strictEqual(intervalArgsThis, intervalArgsHandler); 63 | 64 | assert.strictEqual(timeoutThis, timeoutHandler); 65 | assert.strictEqual(timeoutArgsThis, timeoutArgsHandler); 66 | }); 67 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-uncaught-exception.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var exceptions = 0; 26 | var timer1 = 0; 27 | var timer2 = 0; 28 | 29 | // the first timer throws... 30 | console.error('set first timer'); 31 | setTimeout(function() { 32 | console.error('first timer'); 33 | timer1++; 34 | throw new Error('BAM!'); 35 | }, 100); 36 | 37 | // ...but the second one should still run 38 | console.error('set second timer'); 39 | setTimeout(function() { 40 | console.error('second timer'); 41 | assert.equal(timer1, 1); 42 | timer2++; 43 | }, 100); 44 | 45 | function uncaughtException(err) { 46 | console.error('uncaught handler'); 47 | assert.equal(err.message, 'BAM!'); 48 | exceptions++; 49 | } 50 | process.on('uncaughtException', uncaughtException); 51 | 52 | var exited = false; 53 | process.on('exit', function() { 54 | assert(!exited); 55 | exited = true; 56 | process.removeListener('uncaughtException', uncaughtException); 57 | assert.equal(exceptions, 1); 58 | assert.equal(timer1, 1); 59 | assert.equal(timer2, 1); 60 | }); 61 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers-zero-timeout.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | // https://github.com/joyent/node/issues/2079 - zero timeout drops extra args 26 | (function() { 27 | var ncalled = 0; 28 | 29 | setTimeout(f, 0, 'foo', 'bar', 'baz'); 30 | var timer = setTimeout(function() {}, 0); 31 | 32 | function f(a, b, c) { 33 | assert.equal(a, 'foo'); 34 | assert.equal(b, 'bar'); 35 | assert.equal(c, 'baz'); 36 | ncalled++; 37 | } 38 | 39 | process.on('exit', function() { 40 | assert.equal(ncalled, 1); 41 | }); 42 | })(); 43 | 44 | (function() { 45 | var ncalled = 0; 46 | 47 | var iv = setInterval(f, 0, 'foo', 'bar', 'baz'); 48 | 49 | function f(a, b, c) { 50 | assert.equal(a, 'foo'); 51 | assert.equal(b, 'bar'); 52 | assert.equal(c, 'baz'); 53 | if (++ncalled == 3) clearTimeout(iv); 54 | } 55 | 56 | process.on('exit', function() { 57 | assert.equal(ncalled, 3); 58 | }); 59 | })(); 60 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-timers.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var inputs = [ 26 | undefined, 27 | null, 28 | true, 29 | false, 30 | '', 31 | [], 32 | {}, 33 | NaN, 34 | +Infinity, 35 | -Infinity, 36 | (1.0 / 0.0), // sanity check 37 | parseFloat('x'), // NaN 38 | -10, 39 | -1, 40 | -0.5, 41 | -0.0, 42 | 0, 43 | 0.0, 44 | 0.5, 45 | 1, 46 | 1.0, 47 | 10, 48 | 2147483648, // browser behaviour: timeouts > 2^31-1 run on next tick 49 | 12345678901234 // ditto 50 | ]; 51 | 52 | var timeouts = []; 53 | var intervals = []; 54 | 55 | inputs.forEach(function(value, index) { 56 | setTimeout(function() { 57 | timeouts[index] = true; 58 | }, value); 59 | 60 | var handle = setInterval(function() { 61 | clearInterval(handle); // disarm timer or we'll never finish 62 | intervals[index] = true; 63 | }, value); 64 | }); 65 | 66 | process.on('exit', function() { 67 | // assert that all timers have run 68 | inputs.forEach(function(value, index) { 69 | assert.equal(true, timeouts[index]); 70 | assert.equal(true, intervals[index]); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-util-log.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | var assert = require('assert'); 24 | var util = require('util'); 25 | 26 | assert.ok(process.stdout.writable); 27 | assert.ok(process.stderr.writable); 28 | 29 | var stdout_write = global.process.stdout.write; 30 | var strings = []; 31 | global.process.stdout.write = function(string) { 32 | strings.push(string); 33 | }; 34 | console._stderr = process.stdout; 35 | 36 | var tests = [ 37 | {input: 'foo', output: 'foo'}, 38 | {input: undefined, output: 'undefined'}, 39 | {input: null, output: 'null'}, 40 | {input: false, output: 'false'}, 41 | {input: 42, output: '42'}, 42 | {input: function(){}, output: '[Function]'}, 43 | {input: parseInt('not a number', 10), output: 'NaN'}, 44 | {input: {answer: 42}, output: '{ answer: 42 }'}, 45 | {input: [1,2,3], output: '[ 1, 2, 3 ]'} 46 | ]; 47 | 48 | // test util.log() 49 | tests.forEach(function(test) { 50 | util.log(test.input); 51 | var result = strings.shift().trim(), 52 | re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/), 53 | match = re.exec(result); 54 | assert.ok(match); 55 | assert.equal(match[1], test.output); 56 | }); 57 | 58 | global.process.stdout.write = stdout_write; 59 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-context-async-script.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | var sandbox = { setTimeout: setTimeout }; 27 | 28 | var ctx = vm.createContext(sandbox); 29 | 30 | vm.runInContext('setTimeout(function() { x = 3; }, 0);', ctx); 31 | setTimeout(function () { 32 | assert.strictEqual(sandbox.x, 3); 33 | assert.strictEqual(ctx.x, 3); 34 | }, 1); 35 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-context-property-forwarding.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | var sandbox = { x: 3 }; 27 | 28 | var ctx = vm.createContext(sandbox); 29 | 30 | assert.strictEqual(vm.runInContext('x;', ctx), 3); 31 | vm.runInContext('y = 4;', ctx); 32 | assert.strictEqual(sandbox.y, 4); 33 | assert.strictEqual(ctx.y, 4); 34 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-create-and-run-in-context.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var vm = require('vm'); 26 | 27 | console.error('run in a new empty context'); 28 | var context = vm.createContext(); 29 | var result = vm.runInContext('"passed";', context); 30 | assert.equal('passed', result); 31 | 32 | console.error('create a new pre-populated context'); 33 | context = vm.createContext({'foo': 'bar', 'thing': 'lala'}); 34 | assert.equal('bar', context.foo); 35 | assert.equal('lala', context.thing); 36 | 37 | console.error('test updating context'); 38 | result = vm.runInContext('var foo = 3;', context); 39 | assert.equal(3, context.foo); 40 | assert.equal('lala', context.thing); 41 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-create-context-accessors.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | var ctx = {}; 27 | 28 | Object.defineProperty(ctx, 'getter', { 29 | get: function() { 30 | return 'ok'; 31 | } 32 | }); 33 | 34 | var val; 35 | Object.defineProperty(ctx, 'setter', { 36 | set: function(_val) { 37 | val = _val; 38 | }, 39 | get: function() { 40 | return 'ok=' + val; 41 | } 42 | }); 43 | 44 | ctx = vm.createContext(ctx); 45 | 46 | var result = vm.runInContext('setter = "test";[getter,setter]', ctx); 47 | assert.deepEqual(result, ['ok', 'ok=test']); 48 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-create-context-arg.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | assert.throws(function() { 27 | var ctx = vm.createContext('string is not supported'); 28 | }, TypeError); 29 | 30 | assert.doesNotThrow(function() { 31 | var ctx = vm.createContext({ a: 1 }); 32 | ctx = vm.createContext([0, 1, 2, 3]); 33 | }); 34 | 35 | assert.doesNotThrow(function() { 36 | var sandbox = {}; 37 | vm.createContext(sandbox); 38 | vm.createContext(sandbox); 39 | }); 40 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-create-context-circular-reference.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | var sbx = {}; 27 | sbx.window = sbx; 28 | 29 | sbx = vm.createContext(sbx); 30 | 31 | sbx.test = 123; 32 | 33 | assert.equal(sbx.window.window.window.window.window.test, 123); 34 | 35 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-function-declaration.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var vm = require('vm'); 26 | var o = vm.createContext({ console: console }); 27 | 28 | // This triggers the setter callback in node_contextify.cc 29 | var code = 'var a = function() {};\n'; 30 | 31 | // but this does not, since function decls are defineProperties, 32 | // not simple sets. 33 | code += 'function b(){}\n'; 34 | 35 | // Grab the global b function as the completion value, to ensure that 36 | // we are getting the global function, and not some other thing 37 | code += '(function(){return this})().b;\n' 38 | 39 | var res = vm.runInContext(code, o, 'test'); 40 | 41 | assert.equal(typeof res, 'function', 'result should be function'); 42 | assert.equal(res.name, 'b', 'res should be named b'); 43 | assert.equal(typeof o.a, 'function', 'a should be function'); 44 | assert.equal(typeof o.b, 'function', 'b should be function'); 45 | assert.equal(res, o.b, 'result should be global b function'); 46 | 47 | console.log('ok'); 48 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-global-define-property.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | 25 | var vm = require('vm'); 26 | 27 | var code = 28 | 'Object.defineProperty(this, "f", {\n' + 29 | ' get: function() { return x; },\n' + 30 | ' set: function(k) { x = k; },\n' + 31 | ' configurable: true,\n' + 32 | ' enumerable: true\n' + 33 | '});\n' + 34 | 'g = f;\n' + 35 | 'f;\n'; 36 | 37 | var x = {}; 38 | var o = vm.createContext({ console: console, x: x }); 39 | 40 | var res = vm.runInContext(code, o, 'test'); 41 | 42 | assert(res); 43 | assert.equal(typeof res, 'object'); 44 | assert.equal(res, x); 45 | assert.equal(o.f, res); 46 | assert.deepEqual(Object.keys(o), ['console', 'x', 'f', 'g']); 47 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-global-identity.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | var ctx = vm.createContext(); 27 | ctx.window = ctx; 28 | var thisVal = vm.runInContext('this;', ctx); 29 | /* XXX 30 | var windowVal = vm.runInContext('window;', ctx); 31 | assert.strictEqual(thisVal, windowVal); 32 | */ 33 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-infinite-recursion.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // Flags: --stack-size=128 23 | 24 | var assert = require('assert'); 25 | var vm = require('vm'); 26 | var s = 'vm.runInNewContext(s, { vm: vm, s: s })'; 27 | 28 | assert.throws(function() { 29 | eval(s); 30 | }, /Maximum call stack/); 31 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-is-context.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | assert.throws(function() { 27 | vm.isContext('string is not supported'); 28 | }, TypeError); 29 | 30 | assert.strictEqual(vm.isContext({}), false); 31 | assert.strictEqual(vm.isContext([]), false); 32 | 33 | assert.strictEqual(vm.isContext(vm.createContext()), true); 34 | assert.strictEqual(vm.isContext(vm.createContext([])), true); 35 | 36 | var sandbox = { foo: 'bar' }; 37 | vm.createContext(sandbox); 38 | assert.strictEqual(vm.isContext(sandbox), true); 39 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-new-script-this-context.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var Script = require('vm').Script; 25 | 26 | common.globalCheck = false; 27 | 28 | console.error('run a string'); 29 | var script = new Script('\'passed\';'); 30 | var result = script.runInThisContext(script); 31 | assert.equal('passed', result); 32 | 33 | console.error('thrown error'); 34 | script = new Script('throw new Error(\'test\');'); 35 | assert.throws(function() { 36 | script.runInThisContext(script); 37 | }); 38 | 39 | hello = 5; 40 | script = new Script('hello = 2'); 41 | script.runInThisContext(script); 42 | assert.equal(2, hello); 43 | 44 | 45 | console.error('pass values'); 46 | code = 'foo = 1;' + 47 | 'bar = 2;' + 48 | 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; 49 | foo = 2; 50 | obj = { foo: 0, baz: 3 }; 51 | script = new Script(code); 52 | script.runInThisContext(script); 53 | assert.equal(0, obj.foo); 54 | assert.equal(2, bar); 55 | assert.equal(1, foo); 56 | 57 | console.error('call a function'); 58 | f = function() { foo = 100 }; 59 | script = new Script('f()'); 60 | script.runInThisContext(script); 61 | assert.equal(100, foo); 62 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-static-this.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | common.globalCheck = false; 27 | 28 | console.error('run a string'); 29 | var result = vm.runInThisContext('\'passed\';'); 30 | assert.equal('passed', result); 31 | 32 | console.error('thrown error'); 33 | assert.throws(function() { 34 | vm.runInThisContext('throw new Error(\'test\');'); 35 | }, /test/); 36 | 37 | hello = 5; 38 | vm.runInThisContext('hello = 2'); 39 | assert.equal(2, hello); 40 | 41 | 42 | console.error('pass values'); 43 | code = 'foo = 1;' + 44 | 'bar = 2;' + 45 | 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; 46 | foo = 2; 47 | obj = { foo: 0, baz: 3 }; 48 | var baz = vm.runInThisContext(code); 49 | assert.equal(0, obj.foo); 50 | assert.equal(2, bar); 51 | assert.equal(1, foo); 52 | 53 | console.error('call a function'); 54 | f = function() { foo = 100 }; 55 | vm.runInThisContext('f()'); 56 | assert.equal(100, foo); 57 | -------------------------------------------------------------------------------- /Nodelike Tests/package/test-vm-timeout.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var common = require('../common'); 23 | var assert = require('assert'); 24 | var vm = require('vm'); 25 | 26 | // Test 1: Timeout of 100ms executing endless loop 27 | assert.throws(function() { 28 | vm.runInThisContext('while(true) {}', { timeout: 100 }); 29 | }); 30 | 31 | // Test 2: Timeout must be >= 0ms 32 | assert.throws(function() { 33 | vm.runInThisContext('', { timeout: -1 }); 34 | }, RangeError); 35 | 36 | // Test 3: Timeout of 0ms 37 | assert.throws(function() { 38 | vm.runInThisContext('', { timeout: 0 }); 39 | }, RangeError); 40 | 41 | // Test 4: Timeout of 1000ms, script finishes first 42 | vm.runInThisContext('', { timeout: 1000 }); 43 | 44 | // Test 5: Nested vm timeouts, inner timeout propagates out 45 | assert.throws(function() { 46 | var context = { 47 | log: console.log, 48 | runInVM: function(timeout) { 49 | vm.runInNewContext('while(true) {}', context, { timeout: timeout }); 50 | } 51 | }; 52 | vm.runInNewContext('runInVM(10)', context, { timeout: 100 }); 53 | throw new Error('Test 5 failed'); 54 | }, /Script execution timed out./); 55 | -------------------------------------------------------------------------------- /Nodelike.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "Nodelike" 3 | s.version = "0.1.0" 4 | s.summary = "Node.js-compatible Framework for iOS" 5 | s.description = <<-DESC 6 | Nodelike implements a roughly Node.JS-compatible interface using JavaScriptCore.framework on iOS 7 and OS X Mavericks. 7 | 8 | (JavaScriptCore hasn't been available before iOS 7, and on OS X the project makes extensive use of the newly-updated 10.9-only Objective-C API. Previously on 10.8 there existed only a very low-level and very verbose C API.) 9 | 10 | The goals 11 | --------- 12 | - to be _drop-in compatible_ with the current nodejs master 13 | - to be _very lightweight_ 14 | - to _reuse javascript code from node_ (/lib) 15 | - to provide the _most minimal binding_ that is possible (via libuv) 16 | - NOT to archieve Node.js performance (this is meant as a client-side, not a server-side application) 17 | - NOT to be backwards-compatible (nodejs cutting edge and newest iOS/OS X required) 18 | DESC 19 | s.homepage = "http://nodeapp.org/" 20 | s.screenshots = "https://raw.github.com/node-app/Nodelike/master/demo.gif" 21 | s.license = 'Mozilla Public License Version 2.0' 22 | s.author = { "Sam Rijs" => "recv@awesam.de" } 23 | s.source = { :git => "https://github.com/node-app/Nodelike.git", :tag => s.version.to_s, :submodules => true } 24 | 25 | s.ios.deployment_target = '7.0' 26 | s.osx.deployment_target = '10.9' 27 | s.requires_arc = true 28 | 29 | s.source_files = 'Nodelike/*.{h,m}', 'libuv/src/**/*.{c,h}', 'libuv/include/*.h', 'http-parser/*.{c,h}' 30 | s.exclude_files = 'libuv/src/win', 'libuv/src/unix/*{bsd,aix,linux,sunos}*', 'libuv/include/uv-{bsd,linux,sunos,win}*.h','libuv/include/*msvc2008*.h' 31 | s.frameworks = 'Foundation', 'JavaScriptCore' 32 | s.libraries = 'System' 33 | s.resource_bundle = {'Nodelike' => 'lib/*.js'} 34 | s.compiler_flags ='-Wno-conversion' 35 | end 36 | -------------------------------------------------------------------------------- /Nodelike.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Nodelike/NLAsync.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLAsync.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/3/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLAsync : NLBinding 15 | 16 | @property (readonly) JSValue *object; 17 | @property (readonly) JSContext *context; 18 | 19 | - (instancetype)initInContext:(JSContext *)context; 20 | 21 | + (JSValue *)makeGlobalCallback:(JSValue *)func fromObject:(JSValue *)object withArguments:(NSArray *)args; 22 | - (JSValue *)makeCallback:(JSValue *)func withArguments:(NSArray *)args; 23 | 24 | - (void)makeCallbackFromMethod:(NSString *)method withArguments:(NSArray *)args; 25 | - (void)makeCallbackFromIndex:(unsigned int)idx withArguments:(NSArray *)args; 26 | 27 | + (void)setupAsyncListener:(JSValue *)flagObj run:(JSValue *)run load:(JSValue *)load unload:(JSValue *)unload; 28 | + (bool)hasAsyncListener:(JSContext *)context; 29 | 30 | + (void)setupNextTick:(JSValue *)obj func:(JSValue *)func; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Nodelike/NLBinding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLBinding.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import 13 | #import 14 | 15 | #import "uv.h" 16 | 17 | #import "NLContext.h" 18 | 19 | // In order to guarantee that the C string derived from an 20 | // NSString -UTF8String method call survives until libuv 21 | // gets a chance to copy it, it is annotated with the following 22 | // attribute, which guarantees that the object will be alive until 23 | // the end of the scope. 24 | #define longlived __attribute((objc_precise_lifetime)) 25 | 26 | @interface NLBinding : NSObject 27 | 28 | + (id)bindingForIdentifier:(NSString *)identifier; 29 | 30 | + (id)binding; 31 | 32 | + (JSValue *)makeConstructor:(id)block inContext:(JSContext *)context; 33 | + (JSValue *)constructor; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Nodelike/NLBinding.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLBinding.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | #import "NLFS.h" 15 | #import "NLConstants.h" 16 | #import "NLSmalloc.h" 17 | #import "NLBuffer.h" 18 | #import "NLCares.h" 19 | #import "NLUV.h" 20 | #import "NLTimer.h" 21 | #import "NLTCP.h" 22 | #import "NLUDP.h" 23 | #import "NLTTY.h" 24 | #import "NLProcess.h" 25 | #import "NLHTTPParser.h" 26 | #import "NLNatives.h" 27 | #import "NLContextify.h" 28 | 29 | @implementation NLBinding 30 | 31 | + (NSDictionary *)bindings { 32 | static NSDictionary *bindings = nil; 33 | static dispatch_once_t token = 0; 34 | dispatch_once(&token, ^{ 35 | bindings = @{@"fs": NLFS.class, 36 | @"constants": NLConstants.class, 37 | @"smalloc": NLSmalloc.class, 38 | @"buffer": NLBuffer.class, 39 | @"timer_wrap": NLTimer.class, 40 | @"cares_wrap": NLCares.class, 41 | @"tcp_wrap": NLTCP.class, 42 | @"udp_wrap": NLUDP.class, 43 | @"tty_wrap": NLTTY.class, 44 | @"uv": NLUV.class, 45 | @"process_wrap": NLProcess.class, 46 | @"http_parser": NLHTTPParser.class, 47 | @"natives": NLNatives.class, 48 | @"contextify": NLContextify.class}; 49 | }); 50 | return bindings; 51 | } 52 | 53 | + (id)bindingForIdentifier:(NSString *)identifier { 54 | Class cls = NLBinding.bindings[identifier]; 55 | if (cls) { 56 | return cls.binding; 57 | } else { 58 | return nil; 59 | } 60 | } 61 | 62 | + (id)binding { 63 | return self; 64 | } 65 | 66 | + (JSValue *)makeConstructor:(id)block inContext:(JSContext *)context { 67 | JSValue *fun = [context evaluateScript:@"(function () { return this.__construct.apply(this, arguments); });"]; 68 | fun[@"prototype"][@"__construct"] = block; 69 | return fun; 70 | } 71 | 72 | + (JSValue *)constructor { 73 | return [self makeConstructor:^{ return [self new]; } inContext:JSContext.currentContext]; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Nodelike/NLBuffer.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLBuffer.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/19/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLBuffer : NLBinding 15 | 16 | + (JSValue *)constructorInContext:(JSContext *)context; 17 | 18 | + (JSValue *)useData:(const char *)data ofLength:(size_t)len inContext:(JSContext *)ctx; 19 | 20 | + (int)getLength:(JSValue *)buffer; 21 | + (char *)getData:(JSValue *)buffer ofSize:(int)size; 22 | 23 | + (NSNumber *)writeString:(NSString *)str toBuffer:(JSValue *)target atOffset:(JSValue *)off withLength:(JSValue *)len; 24 | 25 | + (NSNumber *)write:(const char *)data toBuffer:(JSValue *)target atOffset:(JSValue *)off withLength:(JSValue *)len; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Nodelike/NLCares.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLCares.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/21/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @protocol NLCaresExports 15 | 16 | + (NSNumber *)isIP:(NSString *)ip; 17 | 18 | JSExportAs(getaddrinfo, + (NSNumber *)getAddrInfo:(JSValue *)obj hostname:(NSString *)hostname family:(NSNumber *)family); 19 | 20 | @end 21 | 22 | @interface NLCares : NLBinding 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Nodelike/NLConstants.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLConstants.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLConstants : NLBinding 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Nodelike/NLContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLContext.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #include "TargetConditionals.h" 13 | 14 | #if TARGET_OS_IPHONE 15 | #import 16 | #endif 17 | 18 | #import 19 | 20 | #import "uv.h" 21 | 22 | @interface NLContext : JSContext 23 | 24 | #pragma mark Public API 25 | 26 | + (void)attachToContext:(JSContext *)context; 27 | 28 | #if TARGET_OS_IPHONE 29 | + (void)attachToWebView:(UIWebView *)webView; 30 | #endif 31 | 32 | + (uv_loop_t *)eventLoopInContext:(JSContext *)context; 33 | 34 | + (void)runEventLoopSyncInContext:(JSContext *)context; 35 | + (void)runEventLoopAsyncInContext:(JSContext *)context; 36 | 37 | - (void)runProcessAsyncQueue; 38 | + (void)runProcessAsyncQueue:(JSContext *)context; 39 | 40 | - (int)emitExit; 41 | + (int)emitExit:(JSContext *)context; 42 | 43 | + (NSString *)resourcePath; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Nodelike/NLContextify.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLContextify.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/2/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @protocol NLContextifyExports 15 | 16 | JSExportAs(runInContext, - (JSValue *)runInContext:(JSValue *)context options:(JSValue *)options); 17 | - (JSValue *)runInThisContext:(JSValue *)options; 18 | JSExportAs(runInNewContext, - (JSValue *)runInNewContext:(JSValue *)sandbox options:(JSValue *)options); 19 | 20 | @end 21 | 22 | @interface NLContextify : NLBinding 23 | 24 | @property NSString *code; 25 | @property JSValue *options; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Nodelike/NLHTTPParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLHTTPParser.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 1/8/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @protocol NLHTTPParserExports 15 | 16 | - (JSValue *)execute:(JSValue *)buffer; 17 | - (JSValue *)finish; 18 | 19 | - (void)reinitialize:(NSNumber *)type; 20 | - (void)pause; 21 | - (void)resume; 22 | 23 | @end 24 | 25 | @interface NLHTTPParser : NLBinding 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Nodelike/NLHandle.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLHandle.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/28/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLAsync.h" 13 | 14 | @protocol NLHandleExports 15 | 16 | - (void)ref; 17 | - (void)unref; 18 | - (void)close:(JSValue *)cb; 19 | 20 | @end 21 | 22 | @interface NLHandle : NLAsync 23 | 24 | @property (readonly) uv_handle_t *handle; 25 | @property (readonly) NSValue *weakValue; 26 | 27 | - (id)initWithHandle:(uv_handle_t *)handle inContext:(JSContext *)context; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Nodelike/NLHandle.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLHandle.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/28/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLHandle.h" 13 | 14 | static const unsigned int kUnref = 1; 15 | static const unsigned int kCloseCallback = 2; 16 | 17 | @implementation NLHandle { 18 | unsigned int flags; 19 | JSValue *persistent; 20 | } 21 | 22 | + (NSMutableArray *)handleQueue { 23 | static NSMutableArray *queue; 24 | static dispatch_once_t token = 0; 25 | dispatch_once(&token, ^{ 26 | queue = [NSMutableArray new]; 27 | }); 28 | return queue; 29 | } 30 | 31 | - (void)ref { 32 | if (_handle != nil) { 33 | uv_ref(_handle); 34 | flags &= ~kUnref; 35 | } 36 | } 37 | 38 | - (void)unref { 39 | if (_handle != nil) { 40 | uv_unref(_handle); 41 | flags |= kUnref; 42 | } 43 | } 44 | 45 | - (void)close:(JSValue *)cb { 46 | if (_handle == nil) { 47 | return; 48 | } 49 | uv_close(_handle, onClose); 50 | _handle = nil; 51 | if (![cb isUndefined]) { 52 | [self.object setValue:cb forProperty:@"close"]; 53 | flags |= kCloseCallback; 54 | } 55 | } 56 | 57 | - (id)initWithHandle:(uv_handle_t *)handle inContext:(JSContext *)context { 58 | assert(context != nil); 59 | self = [super initInContext:context]; 60 | flags = 0; 61 | _handle = handle; 62 | _handle->data = (__bridge void *)self; 63 | persistent = self.object; 64 | _weakValue = [NSValue valueWithNonretainedObject:self]; 65 | [NLHandle.handleQueue addObject:_weakValue]; 66 | return self; 67 | } 68 | 69 | - (void)dealloc { 70 | [NLHandle.handleQueue removeObject:_weakValue]; 71 | } 72 | 73 | static void onClose(uv_handle_t *handle) { 74 | NLHandle *wrap = (__bridge NLHandle *)handle->data; 75 | if (wrap->flags & kCloseCallback) { 76 | [wrap makeCallbackFromMethod:@"close" withArguments:@[]]; 77 | } 78 | wrap->persistent = nil; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /Nodelike/NLNatives.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLNatives.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 1/25/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLNatives : NLBinding 15 | 16 | + (NSBundle *)bundle; 17 | + (NSArray *)modules; 18 | + (NSString *)source:(NSString *)module; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Nodelike/NLNatives.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLNatives.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 1/25/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLNatives.h" 13 | 14 | @implementation NLNatives 15 | 16 | + (NSBundle *)bundle { 17 | NSBundle *bundle = [NSBundle bundleForClass:self.class]; 18 | NSString *bundlePath = [bundle pathForResource:@"Nodelike" ofType:@"bundle"]; 19 | if (bundlePath) { 20 | return [NSBundle bundleWithPath:bundlePath]; 21 | } else { 22 | return bundle; 23 | } 24 | } 25 | 26 | + (NSArray *)modules { 27 | NSArray *files = [NSBundle pathsForResourcesOfType:@"js" inDirectory:self.bundle.bundlePath]; 28 | NSMutableArray *modules = [NSMutableArray new]; 29 | for (int i = 0; i < files.count; i++) { 30 | NSURL *url = files[i]; 31 | NSString *name = [url.lastPathComponent substringToIndex:url.lastPathComponent.length - url.pathExtension.length - 1]; 32 | [modules addObject:name]; 33 | } 34 | return modules; 35 | } 36 | 37 | + (NSString *)source:(NSString *)module { 38 | NSString *path = [self.bundle pathForResource:module ofType:@"js"]; 39 | NSString *content = [NSString stringWithContentsOfFile:path 40 | encoding:NSUTF8StringEncoding 41 | error:nil]; 42 | return content; 43 | } 44 | 45 | + (id)binding { 46 | NSArray *modules = [self modules]; 47 | JSValue *sources = [JSValue valueWithNewObjectInContext:JSContext.currentContext]; 48 | for (int i = 0; i < modules.count; i++) { 49 | NSString *name = modules[i]; 50 | [sources defineProperty:name 51 | descriptor:@{JSPropertyDescriptorGetKey: ^{ return [NLNatives source:name]; }}]; 52 | } 53 | sources[@"config"] = @"\n{}"; 54 | return sources; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Nodelike/NLProcess.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLProcess.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLHandle.h" 13 | 14 | @protocol NLProcessJSExports 15 | 16 | - (void)ref; 17 | - (void)unref; 18 | - (void)close:(JSValue *)cb; 19 | 20 | @end 21 | 22 | @interface NLProcess : NLHandle 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Nodelike/NLProcess.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLProcess.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLProcess.h" 13 | 14 | @implementation NLProcess { 15 | uv_process_t handle; 16 | } 17 | 18 | + (id)binding { 19 | return @{@"Process": self.constructor}; 20 | } 21 | 22 | - (id)init { 23 | return [super initWithHandle:(uv_handle_t *)&handle inContext:JSContext.currentContext]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Nodelike/NLSmalloc.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLSmalloc.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/19/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLSmalloc : NLBinding 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Nodelike/NLSmalloc.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLSmalloc.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/19/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLSmalloc.h" 13 | 14 | @implementation NLSmalloc 15 | 16 | + (id)binding { 17 | return @{@"kMaxLength": [NSNumber numberWithInt:INT_MAX], 18 | @"alloc": ^(JSValue *t, NSNumber *s) { return t; }, 19 | @"sliceOnto": ^(JSValue *s, JSValue *d, NSNumber *a, NSNumber *b) { 20 | return sliceOnto(s, d, a.intValue, b.intValue); 21 | }}; 22 | } 23 | 24 | static JSValue *sliceOnto(JSValue *src, JSValue *dst, int start, int end) { 25 | int length = end - start; 26 | JSContextRef context = src.context.JSGlobalContextRef; 27 | JSObjectRef srcRef = JSValueToObject(context, src.JSValueRef, nil); 28 | JSObjectRef dstRef = JSValueToObject(context, dst.JSValueRef, nil); 29 | for (int i = 0; i < length; i++) { 30 | JSObjectSetPropertyAtIndex(context, dstRef, i, JSObjectGetPropertyAtIndex(context, srcRef, i + start, NULL), NULL); 31 | } 32 | return src; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Nodelike/NLStream.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLStream.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 11/27/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLHandle.h" 13 | 14 | typedef struct writeWrap { 15 | uv_write_t req; 16 | void *wrap; 17 | void *object; 18 | } writeWrap; 19 | 20 | struct shutdownWrap { 21 | uv_shutdown_t req; 22 | void *wrap; 23 | void *object; 24 | }; 25 | 26 | struct NLStreamCallbacks { 27 | void (*doAlloc)(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); 28 | void (*doRead)(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf, uv_handle_type pending); 29 | int (*doWrite)(struct writeWrap* w, uv_buf_t* bufs, size_t count, uv_stream_t* send_handle, uv_write_cb cb); 30 | void (*afterWrite)(struct writeWrap *w); 31 | int (*doShutdown)(struct shutdownWrap* wrap, uv_shutdown_cb cb); 32 | }; 33 | 34 | @protocol NLStreamExports 35 | 36 | - (void)ref; 37 | - (void)unref; 38 | - (void)close:(JSValue *)cb; 39 | 40 | - (NSNumber *)readStart; 41 | - (NSNumber *)readStop; 42 | 43 | @property (readonly) NSNumber *writeQueueSize; 44 | 45 | JSExportAs(writeAsciiString, - (NSNumber *)writeObject:(JSValue *)obj withAsciiString:(NSString *)string forOptionalSendHandle:(NLHandle *)sendHandle); 46 | JSExportAs(writeUtf8String, - (NSNumber *)writeObject:(JSValue *)obj withUtf8String:(NSString *)string forOptionalSendHandle:(NLHandle *)sendHandle); 47 | JSExportAs(writeBuffer, - (NSNumber *)writeObject:(JSValue *)obj withBuffer:(JSValue *)buffer forOptionalSendHandle:(NLHandle *)sendHandle); 48 | 49 | - (NSNumber *)shutdown:(JSValue *)obj; 50 | 51 | @end 52 | 53 | @interface NLStream : NLHandle 54 | 55 | - (id)initWithStream:(uv_stream_t *)stream inContext:(JSContext *)context; 56 | 57 | - (NSNumber *)writeObject:(JSValue *)obj withData:(const char *)data ofLength:(size_t)size forOptionalSendHandle:(NLHandle *)sendHandle; 58 | 59 | @property uv_stream_t *stream; 60 | @property struct NLStreamCallbacks *callbacks; 61 | 62 | @property (readonly) NSNumber *writeQueueSize; 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Nodelike/NLTCP.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLTCP.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 12/13/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLStream.h" 13 | 14 | @protocol NLTCPExports 15 | 16 | - (void)ref; 17 | - (void)unref; 18 | - (void)close:(JSValue *)cb; 19 | 20 | - (NSNumber *)readStart; 21 | - (NSNumber *)readStop; 22 | 23 | - (NSNumber *)getsockname:(JSValue *)out; 24 | - (NSNumber *)getpeername:(JSValue *)out; 25 | 26 | - (NSNumber *)setNoDelay:(NSNumber *)enable; 27 | JSExportAs(setKeepAlive, - (NSNumber *)setKeepAlive:(NSNumber *)enable to:(NSNumber *)delay); 28 | 29 | - (void)open:(NSNumber *)fd; 30 | 31 | JSExportAs(bind, - (NSNumber *)bind:(NSString *)address port:(NSNumber *)port); 32 | JSExportAs(bind6, - (NSNumber *)bind6:(NSString *)address port:(NSNumber *)port); 33 | 34 | - (NSNumber *)listen:(NSNumber *)backlog; 35 | 36 | JSExportAs(connect, - (NSNumber *)connect:(JSValue *)obj address:(NSString *)address port:(NSNumber *)port); 37 | JSExportAs(connect6, - (NSNumber *)connect6:(JSValue *)obj address:(NSString *)address port:(NSNumber *)port); 38 | 39 | @end 40 | 41 | @interface NLTCP : NLStream 42 | 43 | - (id)initInContext:(JSContext *)context; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Nodelike/NLTTY.h: -------------------------------------------------------------------------------- 1 | #import "NLStream.h" 2 | 3 | @protocol NLTTYExports 4 | 5 | - (void)ref; 6 | - (void)unref; 7 | - (void)close:(JSValue *)cb; 8 | 9 | - (NSNumber *)readStart; 10 | - (NSNumber *)readStop; 11 | 12 | - (JSValue *)getWindowSize:(JSValue *)size; 13 | @end 14 | 15 | @interface NLTTY : NLStream 16 | 17 | - (id)initInContext:(JSContext *)context; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Nodelike/NLTTY.m: -------------------------------------------------------------------------------- 1 | #import "NLTTY.h" 2 | 3 | @implementation NLTTY { 4 | uv_tty_t handle; 5 | } 6 | 7 | + (id)binding { 8 | return @{ 9 | @"TTY": [NLBinding makeConstructor:^(NSNumber *fd, NSNumber *readable) { 10 | NLTTY *tty = [NLTTY new]; 11 | [tty TTY:fd readable:readable]; 12 | return tty; 13 | } inContext:JSContext.currentContext], 14 | @"guessHandleType": ^(NSNumber *fd){ return @"TTY"; }, 15 | }; 16 | } 17 | 18 | - (id)init { 19 | return [self initInContext:JSContext.currentContext]; 20 | } 21 | 22 | - (id)initInContext:(JSContext *)context { 23 | self = [super initWithStream:(uv_stream_t *)&handle inContext:context]; 24 | return self; 25 | } 26 | 27 | - (void)TTY:(NSNumber *)fd readable:(NSNumber *)readable { 28 | int r = uv_tty_init([NLContext eventLoopInContext:JSContext.currentContext], &handle, fd.intValue, readable.intValue); 29 | assert(r == 0); 30 | } 31 | 32 | - (JSValue *)getWindowSize:(JSValue *)size { 33 | return [JSValue valueWithNewErrorFromMessage:@"unimplemented" inContext:JSContext.currentContext]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Nodelike/NLTimer.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLTimer.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/30/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLHandle.h" 13 | 14 | @protocol NLTimerExports 15 | 16 | - (void)ref; 17 | - (void)unref; 18 | - (void)close:(JSValue *)cb; 19 | 20 | JSExportAs(start, - (NSNumber *)start:(NSNumber *)timeout repeat:(NSNumber *)repeat); 21 | - (NSNumber *)stop; 22 | - (NSNumber *)setRepeat:(NSNumber *)repeat; 23 | - (NSNumber *)getRepeat; 24 | - (NSNumber *)again; 25 | 26 | @end 27 | 28 | @interface NLTimer : NLHandle 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Nodelike/NLTimer.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLTimer.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/30/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLTimer.h" 13 | 14 | static const unsigned int kOnTimeout = 0; 15 | 16 | @implementation NLTimer { 17 | uv_timer_t handle; 18 | } 19 | 20 | + (id)binding { 21 | JSValue *timer = self.constructor; 22 | timer[@"kOnTimeout"] = [NSNumber numberWithUnsignedInt:kOnTimeout]; 23 | timer[@"now"] = ^{ 24 | uv_loop_t *eventLoop = [NLContext eventLoopInContext:JSContext.currentContext]; 25 | uv_update_time(eventLoop); 26 | return [NSNumber numberWithDouble:uv_now(eventLoop)]; 27 | }; 28 | return @{@"Timer": timer}; 29 | } 30 | 31 | - (id)init { 32 | self = [super initWithHandle:(uv_handle_t *)&handle inContext:JSContext.currentContext]; 33 | int r = uv_timer_init([NLContext eventLoopInContext:JSContext.currentContext], &handle); 34 | assert(r == 0); 35 | return self; 36 | } 37 | 38 | - (NSNumber *)start:(NSNumber *)timeout repeat:(NSNumber *)repeat { 39 | return [NSNumber numberWithInt:uv_timer_start(&handle, onTimeout, timeout.intValue, repeat.intValue)]; 40 | } 41 | 42 | - (NSNumber *)stop { 43 | return [NSNumber numberWithInt:uv_timer_stop(&handle)]; 44 | } 45 | 46 | - (NSNumber *)setRepeat:(NSNumber *)repeat { 47 | uv_timer_set_repeat(&handle, repeat.intValue); 48 | return @0; 49 | } 50 | 51 | - (NSNumber *)getRepeat { 52 | return [NSNumber numberWithDouble:uv_timer_get_repeat(&handle)]; 53 | } 54 | 55 | - (NSNumber *)again { 56 | return [NSNumber numberWithInt:uv_timer_again(&handle)]; 57 | } 58 | 59 | static void onTimeout(uv_timer_t *handle, int status) { 60 | [(__bridge NLHandle *)handle->data makeCallbackFromIndex:kOnTimeout withArguments:@[@(status)]]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Nodelike/NLUDP.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLUDP.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 1/6/14. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLHandle.h" 13 | 14 | @protocol NLUDPExports 15 | 16 | - (void)ref; 17 | - (void)unref; 18 | - (void)close:(JSValue *)cb; 19 | 20 | JSExportAs(bind, - (NSNumber *)bind:(longlived NSString *)address port:(NSNumber *)port flags:(NSNumber *)flags); 21 | JSExportAs(bind6, - (NSNumber *)bind6:(longlived NSString *)address port:(NSNumber *)port flags:(NSNumber *)flags); 22 | 23 | JSExportAs(send, - (NSNumber *)send:(JSValue *)req 24 | buffer:(JSValue *)buffer offset:(NSNumber *)offset length:(NSNumber *)length 25 | port:(NSNumber *)port address:(NSString *)address hasCallback:(NSNumber *)hasCallback); 26 | JSExportAs(send6, - (NSNumber *)send6:(JSValue *)req 27 | buffer:(JSValue *)buffer offset:(NSNumber *)offset length:(NSNumber *)length 28 | port:(NSNumber *)port address:(NSString *)address hasCallback:(NSNumber *)hasCallback); 29 | 30 | - (NSNumber *)recvStart; 31 | - (NSNumber *)recvStop; 32 | 33 | - (NSNumber *)getsockname:(JSValue *)out; 34 | 35 | JSExportAs(addMembership, - (NSNumber *)addMembership:(longlived NSString *)address iface:(longlived JSValue *)iface); 36 | JSExportAs(dropMembership, - (NSNumber *)dropMembership:(longlived NSString *)address iface:(longlived JSValue *)iface); 37 | 38 | - (NSNumber *)setTTL:(NSNumber *)flag; 39 | - (NSNumber *)setBroadcast:(NSNumber *)flag; 40 | - (NSNumber *)setMulticastTTL:(NSNumber *)flag; 41 | - (NSNumber *)setMulticastLoopback:(NSNumber *)flag; 42 | 43 | @end 44 | 45 | @interface NLUDP : NLHandle 46 | 47 | - (id)initInContext:(JSContext *)context; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Nodelike/NLUV.h: -------------------------------------------------------------------------------- 1 | // 2 | // NLUV.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/28/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLBinding.h" 13 | 14 | @interface NLUV : NLBinding 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Nodelike/NLUV.m: -------------------------------------------------------------------------------- 1 | // 2 | // NLUV.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/28/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NLUV.h" 13 | 14 | #import "uv.h" 15 | 16 | @implementation NLUV 17 | 18 | + (id)binding { 19 | 20 | NSMutableDictionary *b = [NSMutableDictionary new]; 21 | 22 | b[@"errname"] = ^(NSNumber *err) { 23 | return [NSString stringWithUTF8String:uv_err_name([err intValue])]; 24 | }; 25 | 26 | #define V(name, _) [b setObject:[NSNumber numberWithInt:UV_ ## name] forKey:@"UV_" # name]; 27 | UV_ERRNO_MAP(V) 28 | #undef V 29 | 30 | return b; 31 | 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Nodelike/NSObject+Nodelike.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Nodelike.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/2/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import 13 | 14 | extern char env_buffer_constructor; 15 | extern char env_contextify_hidden; 16 | extern char env_process_object; 17 | extern char env_event_loop; 18 | 19 | @interface NSObject (Nodelike) 20 | 21 | - (id)nodelikeGet:(void *)key; 22 | - (void)nodelikeSet:(void *)key toValue:(id)value; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Nodelike/NSObject+Nodelike.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Nodelike.m 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 2/2/14. 6 | // Copyright (c) 2014 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import "NSObject+Nodelike.h" 13 | 14 | #import "objc/runtime.h" 15 | 16 | char env_buffer_constructor = 0; 17 | char env_contextify_hidden = 0; 18 | char env_process_object = 0; 19 | char env_event_loop = 0; 20 | 21 | @implementation NSObject (Nodelike) 22 | 23 | - (id)nodelikeGet:(void *)key { 24 | return objc_getAssociatedObject(self, key); 25 | } 26 | 27 | - (void)nodelikeSet:(void *)key toValue:(id)value { 28 | objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_RETAIN); 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Nodelike/Nodelike-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /Nodelike/Nodelike.h: -------------------------------------------------------------------------------- 1 | // 2 | // Nodelike.h 3 | // Nodelike 4 | // 5 | // Created by Sam Rijs on 10/15/13. 6 | // Copyright (c) 2013 Sam Rijs. 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla Public 9 | // License, v. 2.0. If a copy of the MPL was not distributed with this 10 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #import 13 | 14 | #import "NLContext.h" -------------------------------------------------------------------------------- /StyleSettings.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | kRequireSpaceAfterColon 6 | 7 | kRequireOpenBraceOnMethodSignatureLine 8 | 9 | kRequireOpenBraceOnConditionalStatementLine 10 | 11 | kRequireSpaceBeforeOpeningBrace 12 | 13 | kMethodParameterPrefix 14 | 15 | kElseFormatRule 16 | 0 17 | kEqualSpacingRule 18 | 1 19 | kRequireSpaceAfterConditionalStatement 20 | 21 | kMathSpacingRule 22 | 1 23 | kElseIfFormatRule 24 | 0 25 | kInterfaceColonSpacingRule 26 | 1 27 | kRequireSpaceAfterCommas 28 | 29 | kRequireSpaceBeforeCaseColons 30 | 31 | kSignatureAsteriskSpacingRule 32 | 2 33 | kViolationsShouldBeErrors 34 | 35 | kRequireSpaceAfterParameterType 36 | 37 | kStaticVariableAsteriskSpacingRule 38 | 2 39 | kComparisonSpacingRule 40 | 1 41 | kRequireSpaceAfterPropertyDeclaration 42 | 43 | kRequireSpaceAfterMethodType 44 | 45 | kRequireSpaceAfterReturnType 46 | 47 | kRequireSpaceAfterPropertyTypeDeclaration 48 | 49 | kAsteriskSpacingRule 50 | 2 51 | kRequireSpaceBeforeProtocolDeclarations 52 | 53 | kRequireSpaceBetweenTernaryOperators 54 | 55 | kRequireSpaceBeforeParameter 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/node-app/Nodelike/cbaacf89c1b2e09c5fd391e9ee05a8de1b8f0b5e/demo.gif -------------------------------------------------------------------------------- /lib/_linklist.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | function init(list) { 23 | list._idleNext = list; 24 | list._idlePrev = list; 25 | } 26 | exports.init = init; 27 | 28 | 29 | // show the most idle item 30 | function peek(list) { 31 | if (list._idlePrev == list) return null; 32 | return list._idlePrev; 33 | } 34 | exports.peek = peek; 35 | 36 | 37 | // remove the most idle item from the list 38 | function shift(list) { 39 | var first = list._idlePrev; 40 | remove(first); 41 | return first; 42 | } 43 | exports.shift = shift; 44 | 45 | 46 | // remove a item from its list 47 | function remove(item) { 48 | if (item._idleNext) { 49 | item._idleNext._idlePrev = item._idlePrev; 50 | } 51 | 52 | if (item._idlePrev) { 53 | item._idlePrev._idleNext = item._idleNext; 54 | } 55 | 56 | item._idleNext = null; 57 | item._idlePrev = null; 58 | } 59 | exports.remove = remove; 60 | 61 | 62 | // remove a item from its list and place at the end. 63 | function append(list, item) { 64 | remove(item); 65 | item._idleNext = list._idleNext; 66 | list._idleNext._idlePrev = item; 67 | item._idlePrev = list; 68 | list._idleNext = item; 69 | } 70 | exports.append = append; 71 | 72 | 73 | function isEmpty(list) { 74 | return list._idleNext === list; 75 | } 76 | exports.isEmpty = isEmpty; 77 | -------------------------------------------------------------------------------- /lib/_stream_passthrough.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // a passthrough stream. 23 | // basically just the most minimal sort of Transform stream. 24 | // Every written chunk gets output as-is. 25 | 26 | module.exports = PassThrough; 27 | 28 | var Transform = require('_stream_transform'); 29 | var util = require('util'); 30 | util.inherits(PassThrough, Transform); 31 | 32 | function PassThrough(options) { 33 | if (!(this instanceof PassThrough)) 34 | return new PassThrough(options); 35 | 36 | Transform.call(this, options); 37 | } 38 | 39 | PassThrough.prototype._transform = function(chunk, encoding, cb) { 40 | cb(null, chunk); 41 | }; 42 | -------------------------------------------------------------------------------- /lib/constants.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | module.exports = process.binding('constants'); 23 | -------------------------------------------------------------------------------- /lib/freelist.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // This is a free list to avoid creating so many of the same object. 23 | exports.FreeList = function(name, max, constructor) { 24 | this.name = name; 25 | this.constructor = constructor; 26 | this.max = max; 27 | this.list = []; 28 | }; 29 | 30 | 31 | exports.FreeList.prototype.alloc = function() { 32 | //debug("alloc " + this.name + " " + this.list.length); 33 | return this.list.length ? this.list.shift() : 34 | this.constructor.apply(this, arguments); 35 | }; 36 | 37 | 38 | exports.FreeList.prototype.free = function(obj) { 39 | //debug("free " + this.name + " " + this.list.length); 40 | if (this.list.length < this.max) { 41 | this.list.push(obj); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /lib/os.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var binding = process.binding('os'); 23 | var util = require('util'); 24 | var isWindows = process.platform === 'win32'; 25 | 26 | exports.endianness = binding.getEndianness; 27 | exports.hostname = binding.getHostname; 28 | exports.loadavg = binding.getLoadAvg; 29 | exports.uptime = binding.getUptime; 30 | exports.freemem = binding.getFreeMem; 31 | exports.totalmem = binding.getTotalMem; 32 | exports.cpus = binding.getCPUs; 33 | exports.type = binding.getOSType; 34 | exports.release = binding.getOSRelease; 35 | exports.networkInterfaces = binding.getInterfaceAddresses; 36 | 37 | exports.arch = function() { 38 | return process.arch; 39 | }; 40 | 41 | exports.platform = function() { 42 | return process.platform; 43 | }; 44 | 45 | exports.tmpdir = function() { 46 | if (isWindows) { 47 | return process.env.TEMP || 48 | process.env.TMP || 49 | (process.env.SystemRoot || process.env.windir) + '\\temp'; 50 | } else { 51 | return process.env.TMPDIR || 52 | process.env.TMP || 53 | process.env.TEMP || 54 | '/tmp'; 55 | } 56 | }; 57 | 58 | exports.tmpDir = exports.tmpdir; 59 | 60 | exports.getNetworkInterfaces = util.deprecate(function() { 61 | return exports.networkInterfaces(); 62 | }, 'getNetworkInterfaces is now called `os.networkInterfaces`.'); 63 | 64 | exports.EOL = isWindows ? '\r\n' : '\n'; 65 | -------------------------------------------------------------------------------- /lib/sys.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // the sys module was renamed to 'util'. 23 | // this shim remains to keep old programs working. 24 | module.exports = require('util'); 25 | --------------------------------------------------------------------------------