Author: [EMAIL PROTECTED]
Date: Fri Nov  7 05:34:56 2008
New Revision: 714

Modified:
    branches/experimental/toiger/samples/shell.cc
    branches/experimental/toiger/src/d8.cc
    branches/experimental/toiger/src/flag-definitions.h
    branches/experimental/toiger/src/flags.cc
    branches/experimental/toiger/src/mksnapshot.cc
    branches/experimental/toiger/src/objects.cc
    branches/experimental/toiger/src/objects.h
    branches/experimental/toiger/test/cctest/test-api.cc

Log:
Merging in some files that slipped through the cracks.  Experimental
code generator branch should be merged up to r713.

Modified: branches/experimental/toiger/samples/shell.cc
==============================================================================
--- branches/experimental/toiger/samples/shell.cc       (original)
+++ branches/experimental/toiger/samples/shell.cc       Fri Nov  7 05:34:56 2008
@@ -72,7 +72,7 @@
        // alone JavaScript engines.
        continue;
      } else if (strncmp(str, "--", 2) == 0) {
-      printf("Warning: unknown flag %s.\n", str);
+      printf("Warning: unknown flag %s.\nTry --help for options\n", str);
      } else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
        // Execute argument given to -e option directly
        v8::HandleScope handle_scope;

Modified: branches/experimental/toiger/src/d8.cc
==============================================================================
--- branches/experimental/toiger/src/d8.cc      (original)
+++ branches/experimental/toiger/src/d8.cc      Fri Nov  7 05:34:56 2008
@@ -318,6 +318,9 @@

  int Shell::Main(int argc, char* argv[]) {
    i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
+  if (i::FLAG_help) {
+    return 1;
+  }
    Initialize();
    bool run_shell = (argc == 1);
    Context::Scope context_scope(evaluation_context_);

Modified: branches/experimental/toiger/src/flag-definitions.h
==============================================================================
--- branches/experimental/toiger/src/flag-definitions.h (original)
+++ branches/experimental/toiger/src/flag-definitions.h Fri Nov  7 05:34:56  
2008
@@ -200,6 +200,7 @@
  // Dev shell flags
  //

+DEFINE_bool(help, false, "Print usage message, including flags, on  
console")
  DEFINE_bool(dump_counters, false, "Dump counters on exit")

  //

Modified: branches/experimental/toiger/src/flags.cc
==============================================================================
--- branches/experimental/toiger/src/flags.cc   (original)
+++ branches/experimental/toiger/src/flags.cc   Fri Nov  7 05:34:56 2008
@@ -317,7 +317,8 @@
            // sense there.
            continue;
          } else {
-          fprintf(stderr, "Error: unrecognized flag %s\n", arg);
+          fprintf(stderr, "Error: unrecognized flag %s\n"
+                  "Try --help for options\n", arg);
            return j;
          }
        }
@@ -327,7 +328,8 @@
          if (i < *argc) {
            value = argv[i++];
          } else {
-          fprintf(stderr, "Error: missing value for flag %s of type %s\n",
+          fprintf(stderr, "Error: missing value for flag %s of type %s\n"
+                  "Try --help for options\n",
                    arg, Type2String(flag->type()));
            return j;
          }
@@ -354,7 +356,8 @@
        if ((flag->type() == Flag::TYPE_BOOL && value != NULL) ||
            (flag->type() != Flag::TYPE_BOOL && is_bool) ||
            *endp != '\0') {
-        fprintf(stderr, "Error: illegal value for flag %s of type %s\n",
+        fprintf(stderr, "Error: illegal value for flag %s of type %s\n"
+                "Try --help for options\n",
                  arg, Type2String(flag->type()));
          return j;
        }
@@ -376,6 +379,9 @@
      *argc = j;
    }

+  if (FLAG_help) {
+    PrintHelp();
+  }
    // parsed all flags successfully
    return 0;
  }
@@ -447,10 +453,22 @@

  // static
  void FlagList::PrintHelp() {
+  printf("Usage:\n");
+  printf("  shell [options] -e string\n");
+  printf("    execute string in V8\n");
+  printf("  shell [options] file1 file2 ... filek\n");
+  printf("    run JavaScript scripts in file1, file2, ..., filek\n");
+  printf("  shell [options]\n");
+  printf("  shell [options] --shell\n");
+  printf("    run an interactive JavaScript shell");
+  printf("  d8 [options] file\n");
+  printf("  d8 [options]\n");
+  printf("    run the new debugging shell\n\n");
+  printf("Options:\n");
    for (size_t i = 0; i < num_flags; ++i) {
      Flag* f = &flags[i];
      char* value = ToString(f);
-    printf("  --%s (%s)  type: %s  default: %s\n",
+    printf("  --%s (%s)\n        type: %s  default: %s\n",
             f->name(), f->comment(), Type2String(f->type()), value);
      DeleteArray(value);
    }

Modified: branches/experimental/toiger/src/mksnapshot.cc
==============================================================================
--- branches/experimental/toiger/src/mksnapshot.cc      (original)
+++ branches/experimental/toiger/src/mksnapshot.cc      Fri Nov  7 05:34:56 2008
@@ -150,10 +150,10 @@
    // Print the usage if an error occurs when parsing the command line
    // flags or if the help flag is set.
    int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
-  if (result > 0 || argc != 2 || i::FLAG_h) {
+  if (result > 0 || argc != 2 || i::FLAG_help) {
      ::printf("Usage: %s [flag] ... outfile\n", argv[0]);
      i::FlagList::PrintHelp();
-    return !i::FLAG_h;
+    return !i::FLAG_help;
    }

    v8::V8::SetCounterFunction(counter_callback);

Modified: branches/experimental/toiger/src/objects.cc
==============================================================================
--- branches/experimental/toiger/src/objects.cc (original)
+++ branches/experimental/toiger/src/objects.cc Fri Nov  7 05:34:56 2008
@@ -266,6 +266,70 @@
  }


+PropertyAttributes JSObject::GetPropertyAttributeWithFailedAccessCheck(
+    Object* receiver,
+    LookupResult* result,
+    String* name,
+    bool continue_search) {
+  if (result->IsValid()) {
+    switch (result->type()) {
+      case CALLBACKS: {
+        // Only allow API accessors.
+        Object* obj = result->GetCallbackObject();
+        if (obj->IsAccessorInfo()) {
+          AccessorInfo* info = AccessorInfo::cast(obj);
+          if (info->all_can_read()) {
+            return result->GetAttributes();
+          }
+        }
+        break;
+      }
+
+      case NORMAL:
+      case FIELD:
+      case CONSTANT_FUNCTION: {
+        if (!continue_search) break;
+        // Search ALL_CAN_READ accessors in prototype chain.
+        LookupResult r;
+        result->holder()->LookupRealNamedPropertyInPrototypes(name, &r);
+        if (r.IsValid()) {
+          return GetPropertyAttributeWithFailedAccessCheck(receiver,
+                                                           &r,
+                                                           name,
+                                                            
continue_search);
+        }
+        break;
+      }
+
+      case INTERCEPTOR: {
+        // If the object has an interceptor, try real named properties.
+        // No access check in GetPropertyAttributeWithInterceptor.
+        LookupResult r;
+        if (continue_search) {
+          result->holder()->LookupRealNamedProperty(name, &r);
+        } else {
+          result->holder()->LocalLookupRealNamedProperty(name, &r);
+        }
+        if (r.IsValid()) {
+          return GetPropertyAttributeWithFailedAccessCheck(receiver,
+                                                           &r,
+                                                           name,
+                                                            
continue_search);
+        }
+        break;
+      }
+
+      default: {
+        break;
+      }
+    }
+  }
+
+  Top::ReportFailedAccessCheck(this, v8::ACCESS_HAS);
+  return ABSENT;
+}
+
+
  Object* JSObject::GetLazyProperty(Object* receiver,
                                    LookupResult* result,
                                    String* name,
@@ -1729,8 +1793,10 @@
    // Check access rights if needed.
    if (IsAccessCheckNeeded() &&
        !Top::MayNamedAccess(this, name, v8::ACCESS_HAS)) {
-    Top::ReportFailedAccessCheck(this, v8::ACCESS_HAS);
-    return ABSENT;
+    return GetPropertyAttributeWithFailedAccessCheck(receiver,
+                                                     result,
+                                                     name,
+                                                     continue_search);
    }
    if (result->IsValid()) {
      switch (result->type()) {

Modified: branches/experimental/toiger/src/objects.h
==============================================================================
--- branches/experimental/toiger/src/objects.h  (original)
+++ branches/experimental/toiger/src/objects.h  Fri Nov  7 05:34:56 2008
@@ -1449,6 +1449,11 @@
    PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject*  
receiver,
                                                           String* name,
                                                           bool  
continue_search);
+  PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
+      Object* receiver,
+      LookupResult* result,
+      String* name,
+      bool continue_search);
    PropertyAttributes GetPropertyAttribute(JSObject* receiver,
                                            LookupResult* result,
                                            String* name,

Modified: branches/experimental/toiger/test/cctest/test-api.cc
==============================================================================
--- branches/experimental/toiger/test/cctest/test-api.cc        (original)
+++ branches/experimental/toiger/test/cctest/test-api.cc        Fri Nov  7  
05:34:56 2008
@@ -3195,6 +3195,41 @@
  }


+THREADED_TEST(CrossDomainIsPropertyEnumerable) {
+  v8::HandleScope handle_scope;
+  LocalContext env1;
+  v8::Persistent<Context> env2 = Context::New();
+
+  Local<Value> foo = v8_str("foo");
+  Local<Value> bar = v8_str("bar");
+
+  // Set to the same domain.
+  env1->SetSecurityToken(foo);
+  env2->SetSecurityToken(foo);
+
+  env1->Global()->Set(v8_str("prop"), v8_num(3));
+  env2->Global()->Set(v8_str("env1"), env1->Global());
+
+  // env1.prop is enumerable in env2.
+  Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')");
+  {
+    Context::Scope scope_env2(env2);
+    Local<Value> result = Script::Compile(test)->Run();
+    CHECK(result->IsTrue());
+  }
+
+  // Change env2 to a different domain and test again.
+  env2->SetSecurityToken(bar);
+  {
+    Context::Scope scope_env2(env2);
+    Local<Value> result = Script::Compile(test)->Run();
+    CHECK(result->IsFalse());
+  }
+
+  env2.Dispose();
+}
+
+
  THREADED_TEST(CrossDomainForIn) {
    v8::HandleScope handle_scope;
    LocalContext env1;
@@ -3351,7 +3386,7 @@
        v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));

    // Add an accessor that is not accessible by cross-domain JS code.
-  global_template->SetAccessor(v8_str("blocked_access_prop"),
+  global_template->SetAccessor(v8_str("blocked_prop"),
                                 UnreachableGetter, UnreachableSetter,
                                 v8::Handle<Value>(),
                                 v8::DEFAULT);
@@ -3377,6 +3412,9 @@
    value = v8_compile("other.blocked_prop")->Run();
    CHECK(value->IsUndefined());

+  value =  
v8_compile("propertyIsEnumerable.call(other, 'blocked_prop')")->Run();
+  CHECK(value->IsFalse());
+
    // Access accessible property
    value = v8_compile("other.accessible_prop = 3")->Run();
    CHECK(value->IsNumber());
@@ -3385,6 +3423,21 @@
    value = v8_compile("other.accessible_prop")->Run();
    CHECK(value->IsNumber());
    CHECK_EQ(3, value->Int32Value());
+
+  value =
+     
v8_compile("propertyIsEnumerable.call(other, 'accessible_prop')")->Run();
+  CHECK(value->IsTrue());
+
+  // Enumeration doesn't enumerate accessors from inaccessible objects in
+  // the prototype chain even if the accessors are in themselves  
accessible.
+  Local<Value> result =
+      CompileRun("(function(){var obj = {'__proto__':other};"
+                 "for (var p in obj)"
+                 "   if (p == 'accessible_prop' || p == 'blocked_prop') {"
+                 "     return false;"
+                 "   }"
+                 "return true;})()");
+  CHECK(result->IsTrue());

    context1->Exit();
    context0->Exit();

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to