From 5d5c8cf04a092cf2eb8093ad525b69e34924c977 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 15 Mar 2010 15:53:44 -0700 Subject: [PATCH 1/9] Fix StatWatcher typo --- src/node_stat_watcher.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index f5fd09c8bc..88ae9c6940 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -21,7 +21,7 @@ void StatWatcher::Initialize(Handle target) { constructor_template = Persistent::New(t); constructor_template->Inherit(EventEmitter::constructor_template); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("StatWatcherWatcher")); + constructor_template->SetClassName(String::NewSymbol("StatWatcher")); change_symbol = NODE_PSYMBOL("change"); stop_symbol = NODE_PSYMBOL("stop"); @@ -29,7 +29,7 @@ void StatWatcher::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", StatWatcher::Start); NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", StatWatcher::Stop); - target->Set(String::NewSymbol("StatWatcherWatcher"), constructor_template->GetFunction()); + target->Set(String::NewSymbol("StatWatcher"), constructor_template->GetFunction()); } From 943b2c61a80d24d67e353c90abd7ec6f1549f6d4 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 15 Mar 2010 23:27:21 -0700 Subject: [PATCH 2/9] Make evalcx work like it's supposed to. 1. Move the context->Enter() call so that the global obj is available for writing. 2. On success, copy the modified global out to the sandbox object. 3. Don't copy functions in either direction. They have scope and closures, and make for craziness when trying to keep contexts separate. 4. Only do the ->ToObject->Clone() on objects, so that simple values stay simple. 5. Update the test so that it tests all this stuff. --- src/node.cc | 24 ++++++++++++++++++++---- test/simple/test-eval-cx.js | 17 +++++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index cedcc64d74..78b0def92e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -862,6 +862,9 @@ Handle EvalCX(const Arguments& args) { // Create the new context Persistent context = Context::New(); + // Enter and compile script + context->Enter(); + // Copy objects from global context, to our brand new context Handle keys = sandbox->GetPropertyNames(); @@ -869,12 +872,13 @@ Handle EvalCX(const Arguments& args) { for (i = 0; i < keys->Length(); i++) { Handle key = keys->Get(Integer::New(i))->ToString(); Handle value = sandbox->Get(key); - context->Global()->Set(key, value->ToObject()->Clone()); + if (value->IsFunction()) continue; + if (value->IsObject()) { + value = value->ToObject()->Clone(); + } + context->Global()->Set(key, value); } - // Enter and compile script - context->Enter(); - // Catch errors TryCatch try_catch; @@ -887,6 +891,18 @@ Handle EvalCX(const Arguments& args) { result = script->Run(); if (result.IsEmpty()) { result = ThrowException(try_catch.Exception()); + } else { + // success! copy changes back onto the sandbox object. + keys = context->Global()->GetPropertyNames(); + for (i = 0; i < keys->Length(); i++) { + Handle key = keys->Get(Integer::New(i))->ToString(); + Handle value = context->Global()->Get(key); + if (value->IsFunction()) continue; + if (value->IsObject()) { + value = value->ToObject()->Clone(); + } + sandbox->Set(key, value); + } } } diff --git a/test/simple/test-eval-cx.js b/test/simple/test-eval-cx.js index 32d5c94436..49b8ca10a0 100644 --- a/test/simple/test-eval-cx.js +++ b/test/simple/test-eval-cx.js @@ -14,14 +14,19 @@ process.evalcx('hello = 2'); assert.equal(5, hello); -code = "foo = 1; bar = 2;"; -foo = 2; -obj = { foo : 0 }; -process.evalcx(code, obj); +code = "foo = 1;" + + "bar = 2;" + + "if (baz !== 3) throw new Error('test fail');" + + "quux.pwned = true;"; -/* TODO? +foo = 2; +var quux = { pwned : false }; +obj = { foo : 0, baz : 3, quux : quux }; +var baz = process.evalcx(code, obj); assert.equal(1, obj.foo); assert.equal(2, obj.bar); -*/ +assert.equal(obj.quux.pwned, true); +assert.equal(quux.pwned, false); +assert.notEqual(quux, obj.quux); assert.equal(2, foo); From 3847add9436ce2eb080b9a91dd6955603ac6a714 Mon Sep 17 00:00:00 2001 From: Krishna Rajendran Date: Tue, 16 Mar 2010 04:18:21 -0400 Subject: [PATCH 3/9] Fix calls to dns bindings in dns.js --- lib/dns.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index dd3770e0fe..cd7bc817d3 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -1,4 +1,4 @@ -process.binding('dns'); +var dns = process.binding('dns'); exports.resolve = function (domain, type_, callback_) { var type, callback; @@ -19,32 +19,32 @@ exports.resolve = function (domain, type_, callback_) { } } -exports.resolve4 = process.dns.resolve4; -exports.resolve6 = process.dns.resolve6; -exports.resolveMx = process.dns.resolveMx; -exports.resolveTxt = process.dns.resolveTxt; -exports.resolveSrv = process.dns.resolveSrv; -exports.reverse = process.dns.reverse; +exports.resolve4 = dns.resolve4; +exports.resolve6 = dns.resolve6; +exports.resolveMx = dns.resolveMx; +exports.resolveTxt = dns.resolveTxt; +exports.resolveSrv = dns.resolveSrv; +exports.reverse = dns.reverse; // ERROR CODES // timeout, SERVFAIL or similar. -exports.TEMPFAIL = process.dns.TEMPFAIL; +exports.TEMPFAIL = dns.TEMPFAIL; // got garbled reply. -exports.PROTOCOL = process.dns.PROTOCOL; +exports.PROTOCOL = dns.PROTOCOL; // domain does not exists. -exports.NXDOMAIN = process.dns.NXDOMAIN; +exports.NXDOMAIN = dns.NXDOMAIN; // domain exists but no data of reqd type. -exports.NODATA = process.dns.NODATA; +exports.NODATA = dns.NODATA; // out of memory while processing. -exports.NOMEM = process.dns.NOMEM; +exports.NOMEM = dns.NOMEM; // the query is malformed. -exports.BADQUERY = process.dns.BADQUERY; +exports.BADQUERY = dns.BADQUERY; var resolveMap = { 'A': exports.resolve4, From 3c97a4391af24aea35cb5efa7a40956f7a51d547 Mon Sep 17 00:00:00 2001 From: Krishna Rajendran Date: Tue, 16 Mar 2010 04:54:47 -0400 Subject: [PATCH 4/9] Update test-dns.js to work with latest api --- test/disabled/test-dns.js | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/test/disabled/test-dns.js b/test/disabled/test-dns.js index 675a2c330d..53bd23604f 100644 --- a/test/disabled/test-dns.js +++ b/test/disabled/test-dns.js @@ -21,22 +21,24 @@ while (i--) { "| sed -E 's/[[:space:]]+/ /g' | cut -d ' ' -f 5- " + "| sed -e 's/\\.$//'"; - sys.exec(hostCmd).addCallback(checkDnsRecord(hosts[i], records[j])); + sys.exec(hostCmd, checkDnsRecord(hosts[i], records[j])); } } function checkDnsRecord(host, record) { var myHost = host, myRecord = record; - return function(stdout) { - var expected = stdout.substr(0, stdout.length - 1).split("\n"); - - var resolution = dns.resolve(myHost, myRecord); + return function(err, stdout) { + var expected = []; + if(stdout.length) + expected = stdout.substr(0, stdout.length - 1).split("\n"); switch (myRecord) { case "A": case "AAAA": - resolution.addCallback(function (result, ttl, cname) { + dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { + if(error) result = []; + cmpResults(expected, result, ttl, cname); // do reverse lookup check @@ -48,12 +50,14 @@ function checkDnsRecord(host, record) { "| cut -d \" \" -f 5-" + "| sed -e 's/\\.$//'"; - sys.exec(reverseCmd).addCallback(checkReverse(ip)); + sys.exec(reverseCmd, checkReverse(ip)); } }); break; case "MX": - resolution.addCallback(function (result, ttl, cname) { + dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { + if(error) result = []; + var strResult = []; var ll = result.length; while (ll--) { @@ -64,7 +68,9 @@ function checkDnsRecord(host, record) { }); break; case "TXT": - resolution.addCallback(function (result, ttl, cname) { + dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { + if(error) result = []; + var strResult = []; var ll = result.length; while (ll--) { @@ -74,7 +80,9 @@ function checkDnsRecord(host, record) { }); break; case "SRV": - resolution.addCallback(function (result, ttl, cname) { + dns.resolve(myHost, myRecord, function (error, result, ttl, cname) { + if(error) result = []; + var strResult = []; var ll = result.length; while (ll--) { @@ -93,15 +101,13 @@ function checkDnsRecord(host, record) { function checkReverse(ip) { var myIp = ip; - return function (stdout) { + return function (errr, stdout) { var expected = stdout.substr(0, stdout.length - 1).split("\n"); - var reversing = dns.reverse(myIp); - - reversing.addCallback( - function (domains, ttl, cname) { - cmpResults(expected, domains, ttl, cname); - }); + reversing = dns.reverse(myIp, function (error, domains, ttl, cname) { + if(error) domains = []; + cmpResults(expected, domains, ttl, cname); + }); } } @@ -114,6 +120,6 @@ function cmpResults(expected, result, ttl, cname) { ll = expected.length; while (ll--) { assert.equal(result[ll], expected[ll]); -// puts("Result " + result[ll] + " was equal to expected " + expected[ll]); + puts("Result " + result[ll] + " was equal to expected " + expected[ll]); } } From 217e4b40d410f1ecedf4bdb412d6b514a98c1eee Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 16 Mar 2010 10:48:14 -0700 Subject: [PATCH 5/9] Check for callback argument in DNS functions --- src/node_dns.cc | 5 +++++ test/disabled/test-dns.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/node_dns.cc b/src/node_dns.cc index d26913d96d..8bb440a258 100644 --- a/src/node_dns.cc +++ b/src/node_dns.cc @@ -332,6 +332,11 @@ static Handle ResolveA(int type, const Arguments& args) { String::New("Argument must be a string."))); } + if (!args[1]->IsFunction()) { + return ThrowException(Exception::Error( + String::New("Missing callback argument"))); + } + String::Utf8Value name(args[0]->ToString()); struct dns_query *query; diff --git a/test/disabled/test-dns.js b/test/disabled/test-dns.js index 53bd23604f..7985728d22 100644 --- a/test/disabled/test-dns.js +++ b/test/disabled/test-dns.js @@ -3,6 +3,14 @@ require("../common"); var dns = require("dns"), sys = require("sys"); + +// Try resolution without callback + +assert.throws(function () { + dns.resolve('google.com', 'A'); +}) + + var hosts = ['example.com', 'example.org', 'ietf.org', // AAAA 'google.com', // MX, multiple A records From 31ed37fdf0a3f650bbd8c4a6c211fa6b78652ae8 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 16 Mar 2010 18:36:42 -0700 Subject: [PATCH 6/9] evalcx shouldn't be too fancy After getting some feedback from Mikeal Rogers and Tim Smart, it was decided that evalcx should not try to do any fancy security stuff, and instead leave that in the hands of the user. To comply more with spidermonkey, everything is passed in, and objects are passed in by reference rather than being cloned. --- src/node.cc | 8 -------- test/simple/test-eval-cx.js | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/node.cc b/src/node.cc index 78b0def92e..79f1405e0e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -872,10 +872,6 @@ Handle EvalCX(const Arguments& args) { for (i = 0; i < keys->Length(); i++) { Handle key = keys->Get(Integer::New(i))->ToString(); Handle value = sandbox->Get(key); - if (value->IsFunction()) continue; - if (value->IsObject()) { - value = value->ToObject()->Clone(); - } context->Global()->Set(key, value); } @@ -897,10 +893,6 @@ Handle EvalCX(const Arguments& args) { for (i = 0; i < keys->Length(); i++) { Handle key = keys->Get(Integer::New(i))->ToString(); Handle value = context->Global()->Get(key); - if (value->IsFunction()) continue; - if (value->IsObject()) { - value = value->ToObject()->Clone(); - } sandbox->Set(key, value); } } diff --git a/test/simple/test-eval-cx.js b/test/simple/test-eval-cx.js index 49b8ca10a0..964512f5cc 100644 --- a/test/simple/test-eval-cx.js +++ b/test/simple/test-eval-cx.js @@ -14,19 +14,24 @@ process.evalcx('hello = 2'); assert.equal(5, hello); +debug("pass values in and out"); code = "foo = 1;" + "bar = 2;" - + "if (baz !== 3) throw new Error('test fail');" - + "quux.pwned = true;"; - + + "if (baz !== 3) throw new Error('test fail');"; foo = 2; -var quux = { pwned : false }; -obj = { foo : 0, baz : 3, quux : quux }; +obj = { foo : 0, baz : 3 }; var baz = process.evalcx(code, obj); assert.equal(1, obj.foo); assert.equal(2, obj.bar); -assert.equal(obj.quux.pwned, true); -assert.equal(quux.pwned, false); -assert.notEqual(quux, obj.quux); - assert.equal(2, foo); + +debug("call a function by reference"); +function changeFoo () { foo = 100 } +process.evalcx("f()", { f : changeFoo }); +assert.equal(foo, 100); + +debug("modify an object by reference"); +var f = { a : 1 }; +process.evalcx("f.a = 2", { f : f }); +assert.equal(f.a, 2); + From 84277ea84544d9999e7fea3eec30abada673f7c8 Mon Sep 17 00:00:00 2001 From: Krishna Rajendran Date: Wed, 17 Mar 2010 01:13:45 -0400 Subject: [PATCH 7/9] Check for callback argument in PTR lookup --- src/node_dns.cc | 5 +++++ test/disabled/test-dns.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node_dns.cc b/src/node_dns.cc index 8bb440a258..3898c1aff0 100644 --- a/src/node_dns.cc +++ b/src/node_dns.cc @@ -443,6 +443,11 @@ static Handle Reverse(const Arguments& args) { String::New("Argument must be a string."))); } + if (!args[1]->IsFunction()) { + return ThrowException(Exception::Error( + String::New("Missing callback argument"))); + } + String::Utf8Value ip_address(args[0]->ToString()); union { diff --git a/test/disabled/test-dns.js b/test/disabled/test-dns.js index 7985728d22..f43ba5b832 100644 --- a/test/disabled/test-dns.js +++ b/test/disabled/test-dns.js @@ -8,7 +8,10 @@ var dns = require("dns"), assert.throws(function () { dns.resolve('google.com', 'A'); -}) +}); +assert.throws(function () { + dns.resolve('127.0.0.1', 'PTR'); +}); var hosts = ['example.com', 'example.org', From 8aaffe71eebd3dbf4e8713c79aea6b4413396f9e Mon Sep 17 00:00:00 2001 From: pyrotechnick Date: Wed, 17 Mar 2010 10:20:36 -0700 Subject: [PATCH 8/9] Fixing a typo in the fs.readFile example. --- doc/api.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api.txt b/doc/api.txt index def050430b..38b4c85469 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -695,7 +695,7 @@ Asynchronously reads the entire contents of a file. Example: -------------------------------- fs.readFile("/etc/passwd", function (err, data) { if (err) throw err; - sys.puts(content); + sys.puts(data); }); -------------------------------- + From 2d7e86ef58ee341e323c65193115c2ad7385f131 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 17 Mar 2010 15:52:57 -0700 Subject: [PATCH 9/9] Upgrade V8 to 2.1.5 --- deps/v8/ChangeLog | 6 + deps/v8/src/SConscript | 2 +- deps/v8/src/api.cc | 10 +- deps/v8/src/arm/codegen-arm.cc | 95 +- deps/v8/src/arm/codegen-arm.h | 33 + deps/v8/src/array.js | 2 +- deps/v8/src/ast.cc | 6 +- deps/v8/src/ast.h | 27 +- deps/v8/src/bootstrapper.cc | 11 +- deps/v8/src/builtins.cc | 62 + deps/v8/src/builtins.h | 1 + deps/v8/src/cached_powers.h | 119 - deps/v8/src/checks.h | 22 - deps/v8/src/compiler.cc | 6 +- deps/v8/src/compiler.h | 3 +- deps/v8/src/conversions-inl.h | 11 +- deps/v8/src/conversions.cc | 16 +- deps/v8/src/data-flow.cc | 209 +- deps/v8/src/data-flow.h | 6 + deps/v8/src/date-delay.js | 39 +- deps/v8/src/debug.cc | 10 +- deps/v8/src/diy_fp.h | 136 - deps/v8/src/double.h | 169 - deps/v8/src/factory.cc | 5 + deps/v8/src/factory.h | 2 + deps/v8/src/flag-definitions.h | 2 +- deps/v8/src/frame-element.h | 15 +- deps/v8/src/globals.h | 9 +- deps/v8/src/grisu3.cc | 494 - deps/v8/src/handles.cc | 2 +- deps/v8/src/heap-inl.h | 22 +- deps/v8/src/heap.cc | 52 + deps/v8/src/heap.h | 17 + deps/v8/src/ia32/assembler-ia32-inl.h | 6 + deps/v8/src/ia32/assembler-ia32.h | 4 + deps/v8/src/ia32/codegen-ia32.cc | 752 +- deps/v8/src/ia32/codegen-ia32.h | 43 +- deps/v8/src/ia32/register-allocator-ia32.cc | 62 +- deps/v8/src/ia32/stub-cache-ia32.cc | 48 +- deps/v8/src/ia32/virtual-frame-ia32.cc | 101 +- deps/v8/src/ia32/virtual-frame-ia32.h | 29 + deps/v8/src/liveedit-delay.js | 5 + deps/v8/src/liveedit.cc | 246 +- deps/v8/src/powers_ten.h | 2461 - deps/v8/src/profile-generator-inl.h | 88 + deps/v8/src/profile-generator.cc | 295 + deps/v8/src/profile-generator.h | 233 + deps/v8/src/regexp-delay.js | 93 +- deps/v8/src/register-allocator.h | 17 +- deps/v8/src/rewriter.cc | 50 +- deps/v8/src/runtime.cc | 332 +- deps/v8/src/runtime.h | 4 +- deps/v8/src/splay-tree-inl.h | 74 +- deps/v8/src/splay-tree.h | 12 + deps/v8/src/string.js | 99 +- deps/v8/src/version.cc | 2 +- deps/v8/src/virtual-frame.cc | 3 + deps/v8/src/x64/codegen-x64.cc | 132 +- deps/v8/src/x64/codegen-x64.h | 33 + deps/v8/src/x64/register-allocator-x64.cc | 2 + deps/v8/test/cctest/SConscript | 5 +- deps/v8/test/cctest/gay_shortest.cc | 100048 --------------- deps/v8/test/cctest/test-assembler-ia32.cc | 8 + deps/v8/test/cctest/test-compiler.cc | 10 +- deps/v8/test/cctest/test-disasm-ia32.cc | 72 +- deps/v8/test/cctest/test-diy_fp.cc | 67 - deps/v8/test/cctest/test-double.cc | 204 - deps/v8/test/cctest/test-grisu3.cc | 116 - deps/v8/test/cctest/test-profile-generator.cc | 362 + deps/v8/test/mjsunit/array-push.js | 37 + .../mjsunit/compiler/loopcount.js} | 56 +- .../debug-liveedit-patch-positions-replace.js | 83 + .../mjsunit/debug-liveedit-patch-positions.js | 93 + .../regexp-cache-replace.js} | 26 +- deps/v8/tools/generate-ten-powers.scm | 286 - deps/v8/tools/gyp/v8.gyp | 9 +- deps/v8/tools/v8.xcodeproj/project.pbxproj | 10 + deps/v8/tools/visual_studio/v8_base.vcproj | 12 + .../v8/tools/visual_studio/v8_base_arm.vcproj | 12 + .../v8/tools/visual_studio/v8_base_x64.vcproj | 12 + 80 files changed, 3678 insertions(+), 104697 deletions(-) delete mode 100644 deps/v8/src/cached_powers.h delete mode 100644 deps/v8/src/diy_fp.h delete mode 100644 deps/v8/src/double.h delete mode 100644 deps/v8/src/grisu3.cc delete mode 100644 deps/v8/src/powers_ten.h create mode 100644 deps/v8/src/profile-generator-inl.h create mode 100644 deps/v8/src/profile-generator.cc create mode 100644 deps/v8/src/profile-generator.h delete mode 100644 deps/v8/test/cctest/gay_shortest.cc delete mode 100644 deps/v8/test/cctest/test-diy_fp.cc delete mode 100644 deps/v8/test/cctest/test-double.cc delete mode 100644 deps/v8/test/cctest/test-grisu3.cc create mode 100644 deps/v8/test/cctest/test-profile-generator.cc rename deps/v8/{src/grisu3.h => test/mjsunit/compiler/loopcount.js} (59%) create mode 100644 deps/v8/test/mjsunit/debug-liveedit-patch-positions-replace.js create mode 100644 deps/v8/test/mjsunit/debug-liveedit-patch-positions.js rename deps/v8/test/{cctest/gay_shortest.h => mjsunit/regexp-cache-replace.js} (80%) delete mode 100644 deps/v8/tools/generate-ten-powers.scm diff --git a/deps/v8/ChangeLog b/deps/v8/ChangeLog index d1c8425a5f..7e8c0deb59 100644 --- a/deps/v8/ChangeLog +++ b/deps/v8/ChangeLog @@ -1,3 +1,9 @@ +2010-03-17: Version 2.1.5 + + Performance improvements for arithmetic operations. + + Performance improvements for string operations. + 2010-03-10: Version 2.1.4 Fixed code cache lookup for keyed IC's (issue http://crbug.com/37853). diff --git a/deps/v8/src/SConscript b/deps/v8/src/SConscript index 44b6b5b4f5..f4bba6beb1 100755 --- a/deps/v8/src/SConscript +++ b/deps/v8/src/SConscript @@ -63,7 +63,6 @@ SOURCES = { full-codegen.cc func-name-inferrer.cc global-handles.cc - grisu3.cc handles.cc hashmap.cc heap-profiler.cc @@ -80,6 +79,7 @@ SOURCES = { objects.cc oprofile-agent.cc parser.cc + profile-generator.cc property.cc regexp-macro-assembler-irregexp.cc regexp-macro-assembler.cc diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index af2e7ad243..b2f0e03406 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -1137,8 +1137,14 @@ Local