Revision: 14397
Author:   [email protected]
Date:     Tue Apr 23 09:30:51 2013
Log: Expose the GC under a name that is less collision prone than window.gc.

This also keeps backwards compatibility (window.gc() still works).

BUG=2641

Review URL: https://codereview.chromium.org/14075012

Patch from Marja Hölttä <[email protected]>.
http://code.google.com/p/v8/source/detail?r=14397

Modified:
 /branches/bleeding_edge/src/extensions/gc-extension.cc
 /branches/bleeding_edge/src/extensions/gc-extension.h
 /branches/bleeding_edge/src/flag-definitions.h

=======================================
--- /branches/bleeding_edge/src/extensions/gc-extension.cc Fri Nov 30 01:42:20 2012 +++ /branches/bleeding_edge/src/extensions/gc-extension.cc Tue Apr 23 09:30:51 2013
@@ -26,12 +26,11 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 #include "gc-extension.h"
+#include "platform.h"

 namespace v8 {
 namespace internal {

-const char* const GCExtension::kSource = "native function gc();";
-

 v8::Handle<v8::FunctionTemplate> GCExtension::GetNativeFunction(
     v8::Handle<v8::String> str) {
@@ -50,7 +49,15 @@


 void GCExtension::Register() {
-  static GCExtension gc_extension;
+  static char buffer[50];
+  Vector<char> temp_vector(buffer, sizeof(buffer));
+  if (FLAG_expose_gc_as != NULL && strlen(FLAG_expose_gc_as) != 0) {
+    OS::SNPrintF(temp_vector, "native function %s();", FLAG_expose_gc_as);
+  } else {
+    OS::SNPrintF(temp_vector, "native function gc();");
+  }
+
+  static GCExtension gc_extension(buffer);
   static v8::DeclareExtension declaration(&gc_extension);
 }

=======================================
--- /branches/bleeding_edge/src/extensions/gc-extension.h Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/src/extensions/gc-extension.h Tue Apr 23 09:30:51 2013
@@ -35,13 +35,11 @@

 class GCExtension : public v8::Extension {
  public:
-  GCExtension() : v8::Extension("v8/gc", kSource) {}
+ explicit GCExtension(const char* source) : v8::Extension("v8/gc", source) {}
   virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
       v8::Handle<v8::String> name);
   static v8::Handle<v8::Value> GC(const v8::Arguments& args);
   static void Register();
- private:
-  static const char* const kSource;
 };

 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Tue Apr 23 08:21:11 2013
+++ /branches/bleeding_edge/src/flag-definitions.h      Tue Apr 23 09:30:51 2013
@@ -347,6 +347,10 @@
 DEFINE_string(expose_natives_as, NULL, "expose natives in global object")
 DEFINE_string(expose_debug_as, NULL, "expose debug in global object")
 DEFINE_bool(expose_gc, false, "expose gc extension")
+DEFINE_string(expose_gc_as,
+              NULL,
+              "expose gc extension under the specified name")
+DEFINE_implication(expose_gc_as, expose_gc)
 DEFINE_bool(expose_externalize_string, false,
             "expose externalize string extension")
 DEFINE_int(stack_trace_limit, 10, "number of stack frames to capture")

--
--
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