Reviewers: dcarney,

Message:
Hi Dan,

I'm not sure who is the best person to review FunctionTemplate changes. If there
is someone else that is more suitable feel free to change the reviewers.

Thanks

Description:
Add RemovePrototype to FunctionTemplate

This allows functions created from a FunctionTemplate to not have a
prototype property, which is required by DOM methods.

BUG=https://code.google.com/p/chromium/issues/detail?id=272440

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

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M include/v8.h
  M src/api.cc
  M src/apinatives.js
  M src/macros.py
  M src/objects-inl.h
  M src/objects.h
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 24ee60f1bb4dcec1934b5d1a486f41bc734dd2f0..56422cdda6c6fbccc5cc2b8d4d8dc1f15453873e 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3418,6 +3418,12 @@ class V8_EXPORT FunctionTemplate : public Template {
   void ReadOnlyPrototype();

   /**
+   * Removes the prototype property from functions created from this
+   * FunctionTemplate.
+   */
+  void RemovePrototype();
+
+  /**
    * Returns true if the given object is an instance of this function
    * template.
    */
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index c80162aa85e2333ff7db6f0552aa479c66da0a2c..78303c16f2dc55164fb882cbe89238831221dba9 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1407,6 +1407,17 @@ void FunctionTemplate::ReadOnlyPrototype() {
   Utils::OpenHandle(this)->set_read_only_prototype(true);
 }

+
+void FunctionTemplate::RemovePrototype() {
+  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+  if (IsDeadCheck(isolate, "v8::FunctionTemplate::RemovePrototype()")) {
+    return;
+  }
+  ENTER_V8(isolate);
+  Utils::OpenHandle(this)->set_remove_prototype(true);
+}
+
+
 template<
     typename Getter,
     typename Setter,
Index: src/apinatives.js
diff --git a/src/apinatives.js b/src/apinatives.js
index ccbedd6d397455aa18f2b26bcda172683ba750c7..d93ed80374e7bb51eef94915f1f7e09f7f05a1a3 100644
--- a/src/apinatives.js
+++ b/src/apinatives.js
@@ -75,22 +75,26 @@ function InstantiateFunction(data, name) {
       var fun = %CreateApiFunction(data);
       if (name) %FunctionSetName(fun, name);
       cache[serialNumber] = fun;
-      var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
       var flags = %GetTemplateField(data, kApiFlagOffset);
-      // Note: Do not directly use an object template as a condition, our
-      // internal ToBoolean doesn't handle that!
-      fun.prototype = typeof prototype === 'undefined' ?
-          {} : Instantiate(prototype);
-      if (flags & (1 << kReadOnlyPrototypeBit)) {
-        %FunctionSetReadOnlyPrototype(fun);
-      }
-      %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
-      var parent = %GetTemplateField(data, kApiParentTemplateOffset);
-      // Note: Do not directly use a function template as a condition, our
-      // internal ToBoolean doesn't handle that!
-      if (!(typeof parent === 'undefined')) {
-        var parent_fun = Instantiate(parent);
-        %SetPrototype(fun.prototype, parent_fun.prototype);
+      if (flags & (1 << kRemovePrototypeBit)) {
+        %FunctionRemovePrototype(fun);
+      } else {
+ var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
+        // Note: Do not directly use an object template as a condition, our
+        // internal ToBoolean doesn't handle that!
+        fun.prototype = typeof prototype === 'undefined' ?
+            {} : Instantiate(prototype);
+        if (flags & (1 << kReadOnlyPrototypeBit)) {
+          %FunctionSetReadOnlyPrototype(fun);
+        }
+        %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
+        var parent = %GetTemplateField(data, kApiParentTemplateOffset);
+ // Note: Do not directly use a function template as a condition, our
+        // internal ToBoolean doesn't handle that!
+        if (!(typeof parent === 'undefined')) {
+          var parent_fun = Instantiate(parent);
+          %SetPrototype(fun.prototype, parent_fun.prototype);
+        }
       }
       ConfigureTemplateInstance(fun, data);
     } catch (e) {
Index: src/macros.py
diff --git a/src/macros.py b/src/macros.py
index d50231dcefc39ab266a049ea75140117ea34a761..f1a21305ba98534e21bd222be954bfb7cb7069fc 100644
--- a/src/macros.py
+++ b/src/macros.py
@@ -67,7 +67,8 @@ const msPerMonth       = 2592000000;

 # For apinatives.js
 const kUninitialized = -1;
-const kReadOnlyPrototypeBit = 3; # For FunctionTemplateInfo, matches objects.h
+const kReadOnlyPrototypeBit = 3;
+const kRemovePrototypeBit = 4; # For FunctionTemplateInfo, matches objects.h

 # Note: kDayZeroInJulianDay = ToJulianDay(1970, 0, 1).
 const kInvalidDate        = 'Invalid Date';
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 169475791d05ff9672dfff163ba14dde0506bea5..7b649a9fe6ee3b2f56008b1fbb7caf17f142585a 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -4560,6 +4560,8 @@ BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
                kNeedsAccessCheckBit)
 BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
                kReadOnlyPrototypeBit)
+BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
+               kRemovePrototypeBit)
 BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression,
                kIsExpressionBit)
 BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index b2dc1816f8ef6ceb4bd25ef6572c6c04d0c8b399..521ac685f4401b37625f0c38547c94b22899172a 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -9839,6 +9839,7 @@ class FunctionTemplateInfo: public TemplateInfo {
   // requires access check.
   DECL_BOOLEAN_ACCESSORS(needs_access_check)
   DECL_BOOLEAN_ACCESSORS(read_only_prototype)
+  DECL_BOOLEAN_ACCESSORS(remove_prototype)

   static inline FunctionTemplateInfo* cast(Object* obj);

@@ -9874,6 +9875,7 @@ class FunctionTemplateInfo: public TemplateInfo {
   static const int kUndetectableBit      = 1;
   static const int kNeedsAccessCheckBit  = 2;
   static const int kReadOnlyPrototypeBit = 3;
+  static const int kRemovePrototypeBit   = 4;

   DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
 };
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 3be500814533e45ee0b6273f45577438fa35019f..66d5cc838f33a4b061921fd4b2ced714e27e0fcc 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -9522,6 +9522,17 @@ THREADED_TEST(SetPrototypeThrows) {
 }


+THREADED_TEST(FunctionRemovePrototype) {
+  LocalContext context;
+  v8::HandleScope handle_scope(context->GetIsolate());
+
+  Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
+  t1->RemovePrototype();
+  context->Global()->Set(v8_str("fun"), t1->GetFunction());
+  CHECK(!CompileRun("'prototype' in fun")->BooleanValue());
+}
+
+
 THREADED_TEST(GetterSetterExceptions) {
   LocalContext context;
   v8::HandleScope handle_scope(context->GetIsolate());


--
--
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/groups/opt_out.

Reply via email to