Version 3.24.11

Remove generated makefiles on linux when running gyp_v8 (Chromium issue 331475)

Fix building d8 with readline support due to API changes

Performance and stability improvements on all platforms.

git-svn-id: http://v8.googlecode.com/svn/trunk@18467 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index eeb7865..372c70d 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -8704,12 +8704,23 @@
 }
 
 
+void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) {
+  info.GetReturnValue().Set(
+      info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x")));
+}
+
+
 TEST(DetachedAccesses) {
   LocalContext env1;
   v8::HandleScope scope(env1->GetIsolate());
 
   // Create second environment.
-  v8::Handle<Context> env2 = Context::New(env1->GetIsolate());
+  Local<ObjectTemplate> inner_global_template =
+      FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate();
+  inner_global_template ->SetAccessorProperty(
+      v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX));
+  v8::Local<Context> env2 =
+      Context::New(env1->GetIsolate(), NULL, inner_global_template);
 
   Local<Value> foo = v8_str("foo");
 
@@ -8717,15 +8728,21 @@
   env1->SetSecurityToken(foo);
   env2->SetSecurityToken(foo);
 
+  env1->Global()->Set(v8_str("x"), v8_str("env1_x"));
+
   {
     v8::Context::Scope scope(env2);
+    env2->Global()->Set(v8_str("x"), v8_str("env2_x"));
     CompileRun(
-        "var x = 'x';"
-        "function get_x() { return this.x; }"
-        "function get_x_w() { return get_x(); }"
-        "");
+        "function bound_x() { return x; }"
+        "function get_x()   { return this.x; }"
+        "function get_x_w() { return (function() {return this.x;})(); }");
+    env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x"));
     env1->Global()->Set(v8_str("get_x"), CompileRun("get_x"));
     env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w"));
+    env1->Global()->Set(
+        v8_str("this_x"),
+        CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get"));
   }
 
   Local<Object> env2_global = env2->Global();
@@ -8733,10 +8750,14 @@
   env2->DetachGlobal();
 
   Local<Value> result;
+  result = CompileRun("bound_x()");
+  CHECK_EQ(v8_str("env2_x"), result);
   result = CompileRun("get_x()");
   CHECK(result->IsUndefined());
   result = CompileRun("get_x_w()");
   CHECK(result->IsUndefined());
+  result = CompileRun("this_x()");
+  CHECK_EQ(v8_str("env2_x"), result);
 
   // Reattach env2's proxy
   env2 = Context::New(env1->GetIsolate(),
@@ -8746,13 +8767,62 @@
   env2->SetSecurityToken(foo);
   {
     v8::Context::Scope scope(env2);
-    CompileRun("var x = 'x2';");
+    env2->Global()->Set(v8_str("x"), v8_str("env3_x"));
+    env2->Global()->Set(v8_str("env1"), env1->Global());
+    result = CompileRun(
+        "results = [];"
+        "for (var i = 0; i < 4; i++ ) {"
+        "  results.push(env1.bound_x());"
+        "  results.push(env1.get_x());"
+        "  results.push(env1.get_x_w());"
+        "  results.push(env1.this_x());"
+        "}"
+        "results");
+    Local<v8::Array> results = Local<v8::Array>::Cast(result);
+    CHECK_EQ(16, results->Length());
+    for (int i = 0; i < 16; i += 4) {
+      CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+      CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
+      CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+      CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
+    }
   }
 
-  result = CompileRun("get_x()");
-  CHECK(result->IsUndefined());
-  result = CompileRun("get_x_w()");
-  CHECK_EQ(v8_str("x2"), result);
+  result = CompileRun(
+      "results = [];"
+      "for (var i = 0; i < 4; i++ ) {"
+      "  results.push(bound_x());"
+      "  results.push(get_x());"
+      "  results.push(get_x_w());"
+      "  results.push(this_x());"
+      "}"
+      "results");
+  Local<v8::Array> results = Local<v8::Array>::Cast(result);
+  CHECK_EQ(16, results->Length());
+  for (int i = 0; i < 16; i += 4) {
+    CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+    CHECK_EQ(v8_str("env3_x"), results->Get(i + 1));
+    CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+    CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
+  }
+
+  result = CompileRun(
+      "results = [];"
+      "for (var i = 0; i < 4; i++ ) {"
+      "  results.push(this.bound_x());"
+      "  results.push(this.get_x());"
+      "  results.push(this.get_x_w());"
+      "  results.push(this.this_x());"
+      "}"
+      "results");
+  results = Local<v8::Array>::Cast(result);
+  CHECK_EQ(16, results->Length());
+  for (int i = 0; i < 16; i += 4) {
+    CHECK_EQ(v8_str("env2_x"), results->Get(i + 0));
+    CHECK_EQ(v8_str("env1_x"), results->Get(i + 1));
+    CHECK_EQ(v8_str("env3_x"), results->Get(i + 2));
+    CHECK_EQ(v8_str("env2_x"), results->Get(i + 3));
+  }
 }
 
 
@@ -20110,11 +20180,10 @@
   CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[1]")));
   CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
 
-  // TODO(1547): Make the following also return "i".
   // Calling with environment record as base.
-  TestReceiver(o, context->Global(), "func()");
+  TestReceiver(i, foreign_context->Global(), "func()");
   // Calling with no base.
-  TestReceiver(o, context->Global(), "(1,func)()");
+  TestReceiver(i, foreign_context->Global(), "(1,func)()");
 }
 
 
diff --git a/test/mjsunit/contextual-calls.js b/test/mjsunit/contextual-calls.js
new file mode 100644
index 0000000..10c3e8d
--- /dev/null
+++ b/test/mjsunit/contextual-calls.js
@@ -0,0 +1,103 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+var realms = [Realm.current(), Realm.create()];
+globals = [Realm.global(0), Realm.global(1)];
+Realm.shared = {}
+
+function install(name, value) {
+  Realm.shared[name] = value;
+  for (i in realms) {
+    Realm.eval(realms[i], name + " = Realm.shared['" + name + "'];");
+  }
+}
+
+install('return_this', function() { return this; });
+install('return_this_strict', function () { 'use strict'; return this; });
+
+// test behaviour of 'with' scope
+for (i in realms) {
+  Realm.shared.results = [];
+  // in the second case, 'this' is found in the with scope,
+  // so the receiver is 'this'
+  Realm.eval(realms[i],"                                                       \
+      with('irrelevant') {                                                     \
+        Realm.shared.results.push(return_this());                              \
+        Realm.shared.results.push(return_this_strict());                       \
+      }                                                                        \
+      with(this) {                                                             \
+        Realm.shared.results.push(return_this());                              \
+        Realm.shared.results.push(return_this_strict());                       \
+      }                                                                        \
+    ");
+  assertSame(globals[0], Realm.shared.results[0]);
+  assertSame(undefined, Realm.shared.results[1]);
+  assertSame(globals[i], Realm.shared.results[2]);
+  assertSame(globals[i], Realm.shared.results[3]);
+}
+
+// test 'apply' and 'call'
+for (i in realms) {
+  // 'apply' without a receiver is a contextual call
+  assertSame(globals[0], Realm.eval(realms[i],'return_this.apply()')) ;
+  assertSame(undefined, Realm.eval(realms[i],'return_this_strict.apply()'));
+  assertSame(globals[0], Realm.eval(realms[i],'return_this.apply(null)')) ;
+  assertSame(null, Realm.eval(realms[i],'return_this_strict.apply(null)'));
+  // 'call' without a receiver is a contextual call
+  assertSame(globals[0], Realm.eval(realms[i],'return_this.call()')) ;
+  assertSame(undefined, Realm.eval(realms[i],'return_this_strict.call()'));
+  assertSame(globals[0], Realm.eval(realms[i],'return_this.call(null)')) ;
+  assertSame(null, Realm.eval(realms[i],'return_this_strict.call(null)'));
+}
+
+// test ics
+for (var i = 0; i < 4; i++) {
+  assertSame(globals[0], return_this());
+  assertSame(undefined, return_this_strict());
+}
+
+// BUG(1547)
+
+Realm.eval(realms[0], "var name = 'o'");
+Realm.eval(realms[1], "var name = 'i'");
+
+install('f', function() { return this.name; });
+install('g', function() { "use strict"; return this ? this.name : "u"; });
+
+for (i in realms) {
+  result = Realm.eval(realms[i], "                                             \
+      (function(){return f();})() +                                            \
+      (function(){return (1,f)();})() +                                        \
+      (function(){'use strict'; return f();})() +                              \
+      (function(){'use strict'; return (1,f)();})() +                          \
+      (function(){return g();})() +                                            \
+      (function(){return (1,g)();})() +                                        \
+      (function(){'use strict'; return g();})() +                              \
+      (function(){'use strict'; return (1,g)();})();                           \
+    ");
+  assertSame("oooouuuu", result);
+}
diff --git a/test/mjsunit/harmony/proxies-function.js b/test/mjsunit/harmony/proxies-function.js
index 6b8d098..8c91e9b 100644
--- a/test/mjsunit/harmony/proxies-function.js
+++ b/test/mjsunit/harmony/proxies-function.js
@@ -53,8 +53,7 @@
 
 function TestCall(isStrict, callTrap) {
   assertEquals(42, callTrap(5, 37))
-  // TODO(rossberg): strict mode seems to be broken on x64...
-  // assertSame(isStrict ? undefined : global_object, receiver)
+  assertSame(isStrict ? undefined : global_object, receiver)
 
   var handler = {
     get: function(r, k) {
@@ -67,8 +66,7 @@
 
   receiver = 333
   assertEquals(42, f(11, 31))
-  // TODO(rossberg): strict mode seems to be broken on x64...
-  // assertSame(isStrict ? undefined : global_object, receiver)
+  assertSame(isStrict ? undefined : global_object, receiver)
   receiver = 333
   assertEquals(42, o.f(10, 32))
   assertSame(o, receiver)
@@ -746,3 +744,31 @@
 
 TestCalls()
 */
+
+var realms = [Realm.create(), Realm.create()];
+Realm.shared = {};
+
+Realm.eval(realms[0], "function f() { return this; };");
+Realm.eval(realms[0], "Realm.shared.f = f;");
+Realm.eval(realms[0], "Realm.shared.fg = this;");
+Realm.eval(realms[1], "function g() { return this; };");
+Realm.eval(realms[1], "Realm.shared.g = g;");
+Realm.eval(realms[1], "Realm.shared.gg = this;");
+
+var fp = Proxy.createFunction({}, Realm.shared.f);
+var gp = Proxy.createFunction({}, Realm.shared.g);
+
+for (var i = 0; i < 10; i++) {
+  assertEquals(Realm.shared.fg, fp());
+  assertEquals(Realm.shared.gg, gp());
+
+  with (this) {
+    assertEquals(Realm.shared.fg, fp());
+    assertEquals(Realm.shared.gg, gp());
+  }
+
+  with ({}) {
+    assertEquals(Realm.shared.fg, fp());
+    assertEquals(Realm.shared.gg, gp());
+  }
+}