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/src/d8-posix.cc b/src/d8-posix.cc
index 9a20b06..36d83b5 100644
--- a/src/d8-posix.cc
+++ b/src/d8-posix.cc
@@ -89,8 +89,9 @@
   if (total_timeout != -1) {
     struct timeval time_now;
     gettimeofday(&time_now, NULL);
-    int seconds = time_now.tv_sec - start_time.tv_sec;
-    gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000;
+    time_t seconds = time_now.tv_sec - start_time.tv_sec;
+    gone = static_cast<int>(seconds * 1000 +
+                            (time_now.tv_usec - start_time.tv_usec) / 1000);
     if (gone >= total_timeout) return false;
   }
   FD_ZERO(&readfds);
@@ -125,12 +126,12 @@
   struct timeval time_now;
   gettimeofday(&time_now, NULL);
   // Careful about overflow.
-  int seconds = time_now.tv_sec - start_time.tv_sec;
+  int seconds = static_cast<int>(time_now.tv_sec - start_time.tv_sec);
   if (seconds > 100) {
     if (seconds * 1000 > total_time) return true;
     return false;
   }
-  int useconds = time_now.tv_usec - start_time.tv_usec;
+  int useconds = static_cast<int>(time_now.tv_usec - start_time.tv_usec);
   if (seconds * 1000000 + useconds > total_time * 1000) {
     return true;
   }
@@ -169,12 +170,14 @@
   ExecArgs() {
     exec_args_[0] = NULL;
   }
-  bool Init(Isolate* isolate, Handle<Value> arg0, Handle<Array> command_args) {
+  bool Init(Isolate* isolate, Local<Value> arg0, Local<Array> command_args) {
     String::Utf8Value prog(arg0);
     if (*prog == NULL) {
       const char* message =
           "os.system(): String conversion of program name failed";
-      isolate->ThrowException(String::NewFromUtf8(isolate, message));
+      isolate->ThrowException(
+          String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+              .ToLocalChecked());
       return false;
     }
     int len = prog.length() + 3;
@@ -183,13 +186,17 @@
     exec_args_[0] = c_arg;
     int i = 1;
     for (unsigned j = 0; j < command_args->Length(); i++, j++) {
-      Handle<Value> arg(command_args->Get(Integer::New(isolate, j)));
+      Local<Value> arg(
+          command_args->Get(isolate->GetCurrentContext(),
+                            Integer::New(isolate, j)).ToLocalChecked());
       String::Utf8Value utf8_arg(arg);
       if (*utf8_arg == NULL) {
         exec_args_[i] = NULL;  // Consistent state for destructor.
         const char* message =
             "os.system(): String conversion of argument failed.";
-        isolate->ThrowException(String::NewFromUtf8(isolate, message));
+        isolate->ThrowException(
+            String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+                .ToLocalChecked());
         return false;
       }
       int len = utf8_arg.length() + 1;
@@ -224,19 +231,27 @@
                         int* total_timeout) {
   if (args.Length() > 3) {
     if (args[3]->IsNumber()) {
-      *total_timeout = args[3]->Int32Value();
+      *total_timeout = args[3]
+                           ->Int32Value(args.GetIsolate()->GetCurrentContext())
+                           .FromJust();
     } else {
-      args.GetIsolate()->ThrowException(String::NewFromUtf8(
-          args.GetIsolate(), "system: Argument 4 must be a number"));
+      args.GetIsolate()->ThrowException(
+          String::NewFromUtf8(args.GetIsolate(),
+                              "system: Argument 4 must be a number",
+                              NewStringType::kNormal).ToLocalChecked());
       return false;
     }
   }
   if (args.Length() > 2) {
     if (args[2]->IsNumber()) {
-      *read_timeout = args[2]->Int32Value();
+      *read_timeout = args[2]
+                          ->Int32Value(args.GetIsolate()->GetCurrentContext())
+                          .FromJust();
     } else {
-      args.GetIsolate()->ThrowException(String::NewFromUtf8(
-          args.GetIsolate(), "system: Argument 3 must be a number"));
+      args.GetIsolate()->ThrowException(
+          String::NewFromUtf8(args.GetIsolate(),
+                              "system: Argument 3 must be a number",
+                              NewStringType::kNormal).ToLocalChecked());
       return false;
     }
   }
@@ -264,7 +279,7 @@
   // Only get here if the exec failed.  Write errno to the parent to tell
   // them it went wrong.  If it went well the pipe is closed.
   int err = errno;
-  int bytes_written;
+  ssize_t bytes_written;
   do {
     bytes_written = write(exec_error_fds[kWriteFD], &err, sizeof(err));
   } while (bytes_written == -1 && errno == EINTR);
@@ -275,13 +290,15 @@
 // Runs in the parent process.  Checks that the child was able to exec (closing
 // the file desriptor), or reports an error if it failed.
 static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
-  int bytes_read;
+  ssize_t bytes_read;
   int err;
   do {
     bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
   } while (bytes_read == -1 && errno == EINTR);
   if (bytes_read != 0) {
-    isolate->ThrowException(String::NewFromUtf8(isolate, strerror(err)));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, strerror(err), NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
   return true;
@@ -290,12 +307,10 @@
 
 // Accumulates the output from the child in a string handle.  Returns true if it
 // succeeded or false if an exception was thrown.
-static Handle<Value> GetStdout(Isolate* isolate,
-                               int child_fd,
-                               const struct timeval& start_time,
-                               int read_timeout,
-                               int total_timeout) {
-  Handle<String> accumulator = String::Empty(isolate);
+static Local<Value> GetStdout(Isolate* isolate, int child_fd,
+                              const struct timeval& start_time,
+                              int read_timeout, int total_timeout) {
+  Local<String> accumulator = String::Empty(isolate);
 
   int fullness = 0;
   static const int kStdoutReadBufferSize = 4096;
@@ -303,14 +318,14 @@
 
   if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
     return isolate->ThrowException(
-        String::NewFromUtf8(isolate, strerror(errno)));
+        String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
+            .ToLocalChecked());
   }
 
   int bytes_read;
   do {
-    bytes_read = read(child_fd,
-                      buffer + fullness,
-                      kStdoutReadBufferSize - fullness);
+    bytes_read = static_cast<int>(
+        read(child_fd, buffer + fullness, kStdoutReadBufferSize - fullness));
     if (bytes_read == -1) {
       if (errno == EAGAIN) {
         if (!WaitOnFD(child_fd,
@@ -319,7 +334,8 @@
                       start_time) ||
             (TimeIsOut(start_time, total_timeout))) {
           return isolate->ThrowException(
-              String::NewFromUtf8(isolate, "Timed out waiting for output"));
+              String::NewFromUtf8(isolate, "Timed out waiting for output",
+                                  NewStringType::kNormal).ToLocalChecked());
         }
         continue;
       } else if (errno == EINTR) {
@@ -332,8 +348,9 @@
       int length = bytes_read == 0 ?
                    bytes_read + fullness :
                    LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
-      Handle<String> addition =
-          String::NewFromUtf8(isolate, buffer, String::kNormalString, length);
+      Local<String> addition =
+          String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
+              .ToLocalChecked();
       accumulator = String::Concat(accumulator, addition);
       fullness = bytes_read + fullness - length;
       memcpy(buffer, buffer + length, fullness);
@@ -380,8 +397,10 @@
     if (useconds < 1000000) useconds <<= 1;
     if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
         (TimeIsOut(start_time, total_timeout))) {
-      isolate->ThrowException(String::NewFromUtf8(
-          isolate, "Timed out waiting for process to terminate"));
+      isolate->ThrowException(
+          String::NewFromUtf8(isolate,
+                              "Timed out waiting for process to terminate",
+                              NewStringType::kNormal).ToLocalChecked());
       kill(pid, SIGINT);
       return false;
     }
@@ -392,7 +411,9 @@
              sizeof(message),
              "Child killed by signal %d",
              child_info.si_status);
-    isolate->ThrowException(String::NewFromUtf8(isolate, message));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
   if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) {
@@ -401,7 +422,9 @@
              sizeof(message),
              "Child exited with status %d",
              child_info.si_status);
-    isolate->ThrowException(String::NewFromUtf8(isolate, message));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
 
@@ -416,7 +439,9 @@
              sizeof(message),
              "Child killed by signal %d",
              WTERMSIG(child_status));
-    isolate->ThrowException(String::NewFromUtf8(isolate, message));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
   if (WEXITSTATUS(child_status) != 0) {
@@ -426,7 +451,9 @@
              sizeof(message),
              "Child exited with status %d",
              exit_status);
-    isolate->ThrowException(String::NewFromUtf8(isolate, message));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, message, NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
 
@@ -442,25 +469,29 @@
   int read_timeout = -1;
   int total_timeout = -1;
   if (!GetTimeouts(args, &read_timeout, &total_timeout)) return;
-  Handle<Array> command_args;
+  Local<Array> command_args;
   if (args.Length() > 1) {
     if (!args[1]->IsArray()) {
-      args.GetIsolate()->ThrowException(String::NewFromUtf8(
-          args.GetIsolate(), "system: Argument 2 must be an array"));
+      args.GetIsolate()->ThrowException(
+          String::NewFromUtf8(args.GetIsolate(),
+                              "system: Argument 2 must be an array",
+                              NewStringType::kNormal).ToLocalChecked());
       return;
     }
-    command_args = Handle<Array>::Cast(args[1]);
+    command_args = Local<Array>::Cast(args[1]);
   } else {
     command_args = Array::New(args.GetIsolate(), 0);
   }
   if (command_args->Length() > ExecArgs::kMaxArgs) {
-    args.GetIsolate()->ThrowException(String::NewFromUtf8(
-        args.GetIsolate(), "Too many arguments to system()"));
+    args.GetIsolate()->ThrowException(
+        String::NewFromUtf8(args.GetIsolate(), "Too many arguments to system()",
+                            NewStringType::kNormal).ToLocalChecked());
     return;
   }
   if (args.Length() < 1) {
-    args.GetIsolate()->ThrowException(String::NewFromUtf8(
-        args.GetIsolate(), "Too few arguments to system()"));
+    args.GetIsolate()->ThrowException(
+        String::NewFromUtf8(args.GetIsolate(), "Too few arguments to system()",
+                            NewStringType::kNormal).ToLocalChecked());
     return;
   }
 
@@ -476,12 +507,14 @@
 
   if (pipe(exec_error_fds) != 0) {
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
+        String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
+                            NewStringType::kNormal).ToLocalChecked());
     return;
   }
   if (pipe(stdout_fds) != 0) {
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed."));
+        String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
+                            NewStringType::kNormal).ToLocalChecked());
     return;
   }
 
@@ -500,11 +533,8 @@
 
   if (!ChildLaunchedOK(args.GetIsolate(), exec_error_fds)) return;
 
-  Handle<Value> accumulator = GetStdout(args.GetIsolate(),
-                                        stdout_fds[kReadFD],
-                                        start_time,
-                                        read_timeout,
-                                        total_timeout);
+  Local<Value> accumulator = GetStdout(args.GetIsolate(), stdout_fds[kReadFD],
+                                       start_time, read_timeout, total_timeout);
   if (accumulator->IsUndefined()) {
     kill(pid, SIGINT);  // On timeout, kill the subprocess.
     args.GetReturnValue().Set(accumulator);
@@ -528,19 +558,22 @@
   if (args.Length() != 1) {
     const char* message = "chdir() takes one argument";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   String::Utf8Value directory(args[0]);
   if (*directory == NULL) {
     const char* message = "os.chdir(): String conversion of argument failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   if (chdir(*directory) != 0) {
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), strerror(errno)));
+        String::NewFromUtf8(args.GetIsolate(), strerror(errno),
+                            NewStringType::kNormal).ToLocalChecked());
     return;
   }
 }
@@ -550,7 +583,8 @@
   if (args.Length() != 1) {
     const char* message = "umask() takes one argument";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   if (args[0]->IsNumber()) {
@@ -558,14 +592,16 @@
     // PNaCL has no support for umask.
     int previous = 0;
 #else
-    int previous = umask(args[0]->Int32Value());
+    int previous = umask(
+        args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust());
 #endif
     args.GetReturnValue().Set(previous);
     return;
   } else {
     const char* message = "umask() argument must be numeric";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
 }
@@ -575,11 +611,15 @@
   struct stat stat_buf;
   int stat_result = stat(directory, &stat_buf);
   if (stat_result != 0) {
-    isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
   if ((stat_buf.st_mode & S_IFDIR) != 0) return true;
-  isolate->ThrowException(String::NewFromUtf8(isolate, strerror(EEXIST)));
+  isolate->ThrowException(
+      String::NewFromUtf8(isolate, strerror(EEXIST), NewStringType::kNormal)
+          .ToLocalChecked());
   return false;
 }
 
@@ -594,7 +634,9 @@
   } else if (errno == ENOENT) {  // Intermediate path element is missing.
     char* last_slash = strrchr(directory, '/');
     if (last_slash == NULL) {
-      isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
+      isolate->ThrowException(
+          String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
+              .ToLocalChecked());
       return false;
     }
     *last_slash = 0;
@@ -605,10 +647,14 @@
     if (errno == EEXIST) {
       return CheckItsADirectory(isolate, directory);
     }
-    isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   } else {
-    isolate->ThrowException(String::NewFromUtf8(isolate, strerror(errno)));
+    isolate->ThrowException(
+        String::NewFromUtf8(isolate, strerror(errno), NewStringType::kNormal)
+            .ToLocalChecked());
     return false;
   }
 }
@@ -618,24 +664,29 @@
   mode_t mask = 0777;
   if (args.Length() == 2) {
     if (args[1]->IsNumber()) {
-      mask = args[1]->Int32Value();
+      mask = args[1]
+                 ->Int32Value(args.GetIsolate()->GetCurrentContext())
+                 .FromJust();
     } else {
       const char* message = "mkdirp() second argument must be numeric";
       args.GetIsolate()->ThrowException(
-          String::NewFromUtf8(args.GetIsolate(), message));
+          String::NewFromUtf8(args.GetIsolate(), message,
+                              NewStringType::kNormal).ToLocalChecked());
       return;
     }
   } else if (args.Length() != 1) {
     const char* message = "mkdirp() takes one or two arguments";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   String::Utf8Value directory(args[0]);
   if (*directory == NULL) {
     const char* message = "os.mkdirp(): String conversion of argument failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   mkdirp(args.GetIsolate(), *directory, mask);
@@ -646,14 +697,16 @@
   if (args.Length() != 1) {
     const char* message = "rmdir() takes one or two arguments";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   String::Utf8Value directory(args[0]);
   if (*directory == NULL) {
     const char* message = "os.rmdir(): String conversion of argument failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   rmdir(*directory);
@@ -664,7 +717,8 @@
   if (args.Length() != 2) {
     const char* message = "setenv() takes two arguments";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   String::Utf8Value var(args[0]);
@@ -673,14 +727,16 @@
     const char* message =
         "os.setenv(): String conversion of variable name failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   if (*value == NULL) {
     const char* message =
         "os.setenv(): String conversion of variable contents failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   setenv(*var, *value, 1);
@@ -691,7 +747,8 @@
   if (args.Length() != 1) {
     const char* message = "unsetenv() takes one argument";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   String::Utf8Value var(args[0]);
@@ -699,27 +756,35 @@
     const char* message =
         "os.setenv(): String conversion of variable name failed.";
     args.GetIsolate()->ThrowException(
-        String::NewFromUtf8(args.GetIsolate(), message));
+        String::NewFromUtf8(args.GetIsolate(), message, NewStringType::kNormal)
+            .ToLocalChecked());
     return;
   }
   unsetenv(*var);
 }
 
 
-void Shell::AddOSMethods(Isolate* isolate, Handle<ObjectTemplate> os_templ) {
-  os_templ->Set(String::NewFromUtf8(isolate, "system"),
+void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {
+  os_templ->Set(String::NewFromUtf8(isolate, "system", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, System));
-  os_templ->Set(String::NewFromUtf8(isolate, "chdir"),
+  os_templ->Set(String::NewFromUtf8(isolate, "chdir", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, ChangeDirectory));
-  os_templ->Set(String::NewFromUtf8(isolate, "setenv"),
+  os_templ->Set(String::NewFromUtf8(isolate, "setenv", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, SetEnvironment));
-  os_templ->Set(String::NewFromUtf8(isolate, "unsetenv"),
+  os_templ->Set(String::NewFromUtf8(isolate, "unsetenv", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, UnsetEnvironment));
-  os_templ->Set(String::NewFromUtf8(isolate, "umask"),
+  os_templ->Set(String::NewFromUtf8(isolate, "umask", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, SetUMask));
-  os_templ->Set(String::NewFromUtf8(isolate, "mkdirp"),
+  os_templ->Set(String::NewFromUtf8(isolate, "mkdirp", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, MakeDirectory));
-  os_templ->Set(String::NewFromUtf8(isolate, "rmdir"),
+  os_templ->Set(String::NewFromUtf8(isolate, "rmdir", NewStringType::kNormal)
+                    .ToLocalChecked(),
                 FunctionTemplate::New(isolate, RemoveDirectory));
 }