Reviewers: ,

Message:
Hey --- I dunno if anything valuable is really gained from the fatal error,
given that you can always break in Isolate::Throw anyways --- and more or less figure out what happened. It might make the bug reporter happier to do it this
way

Description:
[d8] bounds-check before getting Shell::Worker internal field

Prevents fatal error in debug builds

BUG=v8:4271
[email protected]
LOG=N

Please review this at https://codereview.chromium.org/1214053004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+12, -5 lines):
  M src/d8.cc


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 7db6f3ed9e442081528e05140bd25b8911e26cb6..cf3c4897cb8dde1d88f5a621376982e4c01930b5 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -770,9 +770,12 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
   Isolate* isolate = args.GetIsolate();
   HandleScope handle_scope(isolate);
-
-  Local<Value> this_value = args.This()->GetInternalField(0);
-  if (!this_value->IsExternal()) {
+  Local<Value> this_value;
+  // Bounds-check to avoid fatal error in debug mode
+  if (args.This()->InternalFieldCount() > 0) {
+    this_value = args.This()->GetInternalField(0);
+  }
+  if (this_value.IsEmpty() || !this_value->IsExternal()) {
     Throw(isolate, "this is not a Worker");
     return;
   }
@@ -795,8 +798,12 @@ void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) { void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
   Isolate* isolate = args.GetIsolate();
   HandleScope handle_scope(isolate);
-  Local<Value> this_value = args.This()->GetInternalField(0);
-  if (!this_value->IsExternal()) {
+  Local<Value> this_value;
+  // Bounds-check to avoid fatal error in debug mode
+  if (args.This()->InternalFieldCount() > 0) {
+    this_value = args.This()->GetInternalField(0);
+  }
+  if (this_value.IsEmpty() || !this_value->IsExternal()) {
     Throw(isolate, "this is not a Worker");
     return;
   }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to