Upgrade V8 to version 4.9.385.28

https://chromium.googlesource.com/v8/v8/+/4.9.385.28

FPIIM-449

Change-Id: I4b2e74289d4bf3667f2f3dc8aa2e541f63e26eb4
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index d1f23f7..e992f33 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -36,6 +36,7 @@
 
 #include "src/api.h"
 #include "src/factory.h"
+#include "src/messages.h"
 #include "src/objects.h"
 #include "src/unicode-decoder.h"
 #include "test/cctest/cctest.h"
@@ -78,7 +79,7 @@
   }
 
   bool next(double threshold) {
-    DCHECK(threshold >= 0.0 && threshold <= 1.0);
+    CHECK(threshold >= 0.0 && threshold <= 1.0);
     if (threshold == 1.0) return true;
     if (threshold == 0.0) return false;
     uint32_t value = next() % 100000;
@@ -190,9 +191,9 @@
           buf[j] = rng->next(0x10000);
         }
         Resource* resource = new Resource(buf, len);
-        building_blocks[i] =
-            v8::Utils::OpenHandle(
-                *v8::String::NewExternal(CcTest::isolate(), resource));
+        building_blocks[i] = v8::Utils::OpenHandle(
+            *v8::String::NewExternalTwoByte(CcTest::isolate(), resource)
+                 .ToLocalChecked());
         for (int j = 0; j < len; j++) {
           CHECK_EQ(buf[j], building_blocks[i]->Get(j));
         }
@@ -204,9 +205,9 @@
           buf[j] = rng->next(0x80);
         }
         OneByteResource* resource = new OneByteResource(buf, len);
-        building_blocks[i] =
-            v8::Utils::OpenHandle(
-                *v8::String::NewExternal(CcTest::isolate(), resource));
+        building_blocks[i] = v8::Utils::OpenHandle(
+            *v8::String::NewExternalOneByte(CcTest::isolate(), resource)
+                 .ToLocalChecked());
         for (int j = 0; j < len; j++) {
           CHECK_EQ(buf[j], building_blocks[i]->Get(j));
         }
@@ -641,6 +642,7 @@
 
 template<typename BuildString>
 void TestStringCharacterStream(BuildString build, int test_cases) {
+  FLAG_gc_global = true;
   CcTest::InitializeVM();
   Isolate* isolate = CcTest::i_isolate();
   HandleScope outer_scope(isolate);
@@ -878,8 +880,10 @@
   // A simple one-byte string
   const char* one_byte_string = "abcdef12345";
   int len = v8::String::NewFromUtf8(CcTest::isolate(), one_byte_string,
-                                    v8::String::kNormalString,
-                                    StrLength(one_byte_string))->Utf8Length();
+                                    v8::NewStringType::kNormal,
+                                    StrLength(one_byte_string))
+                .ToLocalChecked()
+                ->Utf8Length();
   CHECK_EQ(StrLength(one_byte_string), len);
   // A mixed one-byte and two-byte string
   // U+02E4 -> CB A4
@@ -894,8 +898,10 @@
   // The number of bytes expected to be written for each length
   const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11};
   const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5};
-  v8::Handle<v8::String> mixed = v8::String::NewFromTwoByte(
-      CcTest::isolate(), mixed_string, v8::String::kNormalString, 5);
+  v8::Local<v8::String> mixed =
+      v8::String::NewFromTwoByte(CcTest::isolate(), mixed_string,
+                                 v8::NewStringType::kNormal, 5)
+          .ToLocalChecked();
   CHECK_EQ(10, mixed->Utf8Length());
   // Try encoding the string with all capacities
   char buffer[11];
@@ -927,9 +933,9 @@
   CHECK_GT(kMaxLength, i::ConsString::kMinLength);
 
   // Allocate two JavaScript arrays for holding short strings.
-  v8::Handle<v8::Array> one_byte_external_strings =
+  v8::Local<v8::Array> one_byte_external_strings =
       v8::Array::New(CcTest::isolate(), kMaxLength + 1);
-  v8::Handle<v8::Array> non_one_byte_external_strings =
+  v8::Local<v8::Array> non_one_byte_external_strings =
       v8::Array::New(CcTest::isolate(), kMaxLength + 1);
 
   // Generate short one-byte and two-byte external strings.
@@ -942,10 +948,13 @@
     // string data.
     OneByteResource* one_byte_resource = new OneByteResource(one_byte, i);
     v8::Local<v8::String> one_byte_external_string =
-        v8::String::NewExternal(CcTest::isolate(), one_byte_resource);
+        v8::String::NewExternalOneByte(CcTest::isolate(), one_byte_resource)
+            .ToLocalChecked();
 
-    one_byte_external_strings->Set(v8::Integer::New(CcTest::isolate(), i),
-                                   one_byte_external_string);
+    one_byte_external_strings->Set(context.local(),
+                                   v8::Integer::New(CcTest::isolate(), i),
+                                   one_byte_external_string)
+        .FromJust();
     uc16* non_one_byte = NewArray<uc16>(i + 1);
     for (int j = 0; j < i; j++) {
       non_one_byte[j] = 0x1234;
@@ -954,17 +963,25 @@
     // string data.
     Resource* resource = new Resource(non_one_byte, i);
     v8::Local<v8::String> non_one_byte_external_string =
-        v8::String::NewExternal(CcTest::isolate(), resource);
-    non_one_byte_external_strings->Set(v8::Integer::New(CcTest::isolate(), i),
-                                       non_one_byte_external_string);
+        v8::String::NewExternalTwoByte(CcTest::isolate(), resource)
+            .ToLocalChecked();
+    non_one_byte_external_strings->Set(context.local(),
+                                       v8::Integer::New(CcTest::isolate(), i),
+                                       non_one_byte_external_string)
+        .FromJust();
   }
 
   // Add the arrays with the short external strings in the global object.
-  v8::Handle<v8::Object> global = context->Global();
-  global->Set(v8_str("external_one_byte"), one_byte_external_strings);
-  global->Set(v8_str("external_non_one_byte"), non_one_byte_external_strings);
-  global->Set(v8_str("max_length"),
-              v8::Integer::New(CcTest::isolate(), kMaxLength));
+  v8::Local<v8::Object> global = context->Global();
+  global->Set(context.local(), v8_str("external_one_byte"),
+              one_byte_external_strings)
+      .FromJust();
+  global->Set(context.local(), v8_str("external_non_one_byte"),
+              non_one_byte_external_strings)
+      .FromJust();
+  global->Set(context.local(), v8_str("max_length"),
+              v8::Integer::New(CcTest::isolate(), kMaxLength))
+      .FromJust();
 
   // Add short external one-byte and two-byte strings checking the result.
   static const char* source =
@@ -1010,7 +1027,7 @@
       "  return 0;"
       "};"
       "test()";
-  CHECK_EQ(0, CompileRun(source)->Int32Value());
+  CHECK_EQ(0, CompileRun(source)->Int32Value(context.local()).FromJust());
 }
 
 
@@ -1019,14 +1036,19 @@
   // Create a sliced string from a one-byte string.  The latter is turned
   // into a two-byte external string.  Check that JSON.stringify works.
   v8::HandleScope handle_scope(CcTest::isolate());
-  v8::Handle<v8::String> underlying =
+  v8::Local<v8::String> underlying =
       CompileRun(
           "var underlying = 'abcdefghijklmnopqrstuvwxyz';"
-          "underlying")->ToString(CcTest::isolate());
-  v8::Handle<v8::String> slice = CompileRun(
-                                     "var slice = '';"
-                                     "slice = underlying.slice(1);"
-                                     "slice")->ToString(CcTest::isolate());
+          "underlying")
+          ->ToString(CcTest::isolate()->GetCurrentContext())
+          .ToLocalChecked();
+  v8::Local<v8::String> slice =
+      CompileRun(
+          "var slice = '';"
+          "slice = underlying.slice(1);"
+          "slice")
+          ->ToString(CcTest::isolate()->GetCurrentContext())
+          .ToLocalChecked();
   CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
   CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString());
 
@@ -1038,8 +1060,9 @@
   CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
   CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString());
 
-  CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"",
-           *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)")));
+  CHECK_EQ(0,
+           strcmp("\"bcdefghijklmnopqrstuvwxyz\"",
+                  *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)"))));
 }
 
 
@@ -1076,15 +1099,23 @@
   };
 
   const char* line;
+  v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
   for (int i = 0; (line = lines[i]); i++) {
     printf("%s\n", line);
-    v8::Local<v8::Value> result = v8::Script::Compile(
-        v8::String::NewFromUtf8(CcTest::isolate(), line))->Run();
+    v8::Local<v8::Value> result =
+        v8::Script::Compile(context,
+                            v8::String::NewFromUtf8(CcTest::isolate(), line,
+                                                    v8::NewStringType::kNormal)
+                                .ToLocalChecked())
+            .ToLocalChecked()
+            ->Run(context)
+            .ToLocalChecked();
     CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined());
     CHECK_EQ(results[i]->IsNumber(), result->IsNumber());
     if (result->IsNumber()) {
-      CHECK_EQ(Object::ToSmi(isolate, results[i]).ToHandleChecked()->value(),
-               result->ToInt32(CcTest::isolate())->Value());
+      int32_t value = 0;
+      CHECK(results[i]->ToInt32(&value));
+      CHECK_EQ(value, result->ToInt32(context).ToLocalChecked()->Value());
     }
   }
 }
@@ -1171,7 +1202,7 @@
   CHECK(result->IsString());
   string = v8::Utils::OpenHandle(v8::String::Cast(*result));
   CHECK(string->IsSlicedString());
-  CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get());
+  CHECK_EQ(0, strcmp("bcdefghijklmnopqrstuvwxy", string->ToCString().get()));
 }
 
 
@@ -1193,22 +1224,23 @@
   string = v8::Utils::OpenHandle(v8::String::Cast(*result));
   CHECK(string->IsSlicedString());
   CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
-  CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get());
+  CHECK_EQ(0, strcmp("bcdefghijklmnopqrstuvwxy", string->ToCString().get()));
 
   result = CompileRun(slice_from_slice);
   CHECK(result->IsString());
   string = v8::Utils::OpenHandle(v8::String::Cast(*result));
   CHECK(string->IsSlicedString());
   CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
-  CHECK_EQ("cdefghijklmnopqrstuvwx", string->ToCString().get());
+  CHECK_EQ(0, strcmp("cdefghijklmnopqrstuvwx", string->ToCString().get()));
 }
 
 
 UNINITIALIZED_TEST(OneByteArrayJoin) {
   v8::Isolate::CreateParams create_params;
   // Set heap limits.
-  create_params.constraints.set_max_semi_space_size(1);
-  create_params.constraints.set_max_old_space_size(4);
+  create_params.constraints.set_max_semi_space_size(1 * Page::kPageSize / MB);
+  create_params.constraints.set_max_old_space_size(6 * Page::kPageSize / MB);
+  create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
   v8::Isolate* isolate = v8::Isolate::New(create_params);
   isolate->Enter();
 
@@ -1219,7 +1251,7 @@
     // summing the lengths of the strings (as Smis) overflows and wraps.
     LocalContext context(isolate);
     v8::HandleScope scope(isolate);
-    v8::TryCatch try_catch;
+    v8::TryCatch try_catch(isolate);
     CHECK(CompileRun(
               "var two_14 = Math.pow(2, 14);"
               "var two_17 = Math.pow(2, 17);"
@@ -1263,7 +1295,7 @@
   // Ordinary HeapNumbers can be handled (in runtime).
   result = CompileRun("%_SubString(short, Math.sqrt(4), 5.1);");
   string = v8::Utils::OpenHandle(v8::String::Cast(*result));
-  CHECK_EQ("cde", string->ToCString().get());
+  CHECK_EQ(0, strcmp("cde", string->ToCString().get()));
 
   CompileRun("var long = 'abcdefghijklmnopqrstuvwxyz';");
   // Invalid indices.
@@ -1278,7 +1310,7 @@
   // Ordinary HeapNumbers within bounds can be handled (in runtime).
   result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);");
   string = v8::Utils::OpenHandle(v8::String::Cast(*result));
-  CHECK_EQ("cdefghijklmnopq", string->ToCString().get());
+  CHECK_EQ(0, strcmp("cdefghijklmnopq", string->ToCString().get()));
 
   // Test that out-of-bounds substring of a slice fails when the indices
   // would have been valid for the underlying string.
@@ -1315,7 +1347,8 @@
       "  return iterator.next();"
       "})();");
   CHECK(result->IsNumber());
-  int uses = result->ToInt32(CcTest::isolate())->Value() == 0 ? 0 : 1;
+  int uses =
+      result->ToInt32(context.local()).ToLocalChecked()->Value() == 0 ? 0 : 1;
   CHECK_EQ(uses, use_counts[v8::Isolate::kBreakIterator]);
   // Make sure GC cleans up the break iterator, so we don't get a memory leak
   // reported by ASAN.
@@ -1336,7 +1369,7 @@
   CHECK(string->IsSeqTwoByteString());
 
   v8::Local<v8::String> expected = v8_str("one_byte\x80only\x80string\x80");
-  CHECK(expected->Equals(result));
+  CHECK(expected->Equals(context.local(), result).FromJust());
 }
 
 
@@ -1445,6 +1478,7 @@
     static const int invalid = String::kMaxLength + 1;                         \
     HandleScope scope(isolate);                                                \
     Vector<TYPE> dummy = Vector<TYPE>::New(invalid);                           \
+    memset(dummy.start(), 0x0, dummy.length() * sizeof(TYPE));                 \
     CHECK(isolate->factory()->FUN(Vector<const TYPE>::cast(dummy)).is_null()); \
     memset(dummy.start(), 0x20, dummy.length() * sizeof(TYPE));                \
     CHECK(isolate->has_pending_exception());                                   \
@@ -1457,3 +1491,20 @@
 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t)
 
 #undef INVALID_STRING_TEST
+
+
+TEST(FormatMessage) {
+  CcTest::InitializeVM();
+  LocalContext context;
+  Isolate* isolate = CcTest::i_isolate();
+  HandleScope scope(isolate);
+  Handle<String> arg0 = isolate->factory()->NewStringFromAsciiChecked("arg0");
+  Handle<String> arg1 = isolate->factory()->NewStringFromAsciiChecked("arg1");
+  Handle<String> arg2 = isolate->factory()->NewStringFromAsciiChecked("arg2");
+  Handle<String> result =
+      MessageTemplate::FormatMessage(MessageTemplate::kPropertyNotFunction,
+                                     arg0, arg1, arg2).ToHandleChecked();
+  Handle<String> expected = isolate->factory()->NewStringFromAsciiChecked(
+      "'arg0' returned for property 'arg1' of object 'arg2' is not a function");
+  CHECK(String::Equals(result, expected));
+}