Author: [EMAIL PROTECTED]
Date: Fri Oct  3 01:30:22 2008
New Revision: 417

Modified:
    branches/bleeding_edge/src/execution.cc
    branches/bleeding_edge/src/execution.h
    branches/bleeding_edge/src/serialize.cc
    branches/bleeding_edge/test/cctest/test-api.cc
    branches/bleeding_edge/test/cctest/test-compiler.cc
    branches/bleeding_edge/test/cctest/test-serialize.cc

Log:
Removed the print, load, quit and version extensions from the VM. Moved the  
print extension to the compiler test as it was used there. Changed the  
serializer tests to only use the gc extension.

This also gets rid of 8 static initializers.
Review URL: http://codereview.chromium.org/6233

Modified: branches/bleeding_edge/src/execution.cc
==============================================================================
--- branches/bleeding_edge/src/execution.cc     (original)
+++ branches/bleeding_edge/src/execution.cc     Fri Oct  3 01:30:22 2008
@@ -504,146 +504,6 @@
  }


-// --- P r i n t   E x t e n s i o n ---
-
-const char* PrintExtension::kSource = "native function print();";
-
-
-v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction(
-    v8::Handle<v8::String> str) {
-  return v8::FunctionTemplate::New(PrintExtension::Print);
-}
-
-
-v8::Handle<v8::Value> PrintExtension::Print(const v8::Arguments& args) {
-  for (int i = 0; i < args.Length(); i++) {
-    if (i != 0) printf(" ");
-    v8::HandleScope scope;
-    v8::Handle<v8::Value> arg = args[i];
-    v8::Handle<v8::String> string_obj = arg->ToString();
-    if (string_obj.IsEmpty()) return string_obj;
-    int length = string_obj->Length();
-    uint16_t* string = NewArray<uint16_t>(length + 1);
-    string_obj->Write(string);
-    for (int j = 0; j < length; j++)
-      printf("%lc", string[j]);
-    DeleteArray(string);
-  }
-  printf("\n");
-  return v8::Undefined();
-}
-
-
-static PrintExtension kPrintExtension;
-v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension);
-
-
-// --- L o a d   E x t e n s i o n ---
-
-const char* LoadExtension::kSource = "native function load();";
-
-
-v8::Handle<v8::FunctionTemplate> LoadExtension::GetNativeFunction(
-    v8::Handle<v8::String> str) {
-  return v8::FunctionTemplate::New(LoadExtension::Load);
-}
-
-
-v8::Handle<v8::Value> LoadExtension::Load(const v8::Arguments& args) {
-  v8::Handle<v8::String> path = args[0]->ToString();
-
-  // Create a handle for the result. Keep the result empty to be
-  // useful as the return value in case of exceptions.
-  v8::Handle<Value> result;
-
-  if (path.IsEmpty()) return result;  // Exception was thrown in ToString.
-
-  // Check that the length of the file name is within bounds.
-  static const int kMaxPathLength = 255;
-  if (path->Length() > kMaxPathLength) {
-    v8::Handle<v8::String> message = v8::String::New("Path name too long");
-    v8::ThrowException(v8::Exception::RangeError(message));
-    return result;
-  }
-
-  // Convert the JavaScript string path into a C string and read the
-  // corresponding script from the file system.
-  char path_buffer[kMaxPathLength + 1];
-  path->WriteAscii(path_buffer);
-  bool exists;
-  Vector<const char> script = ReadFile(path_buffer, &exists, false);
-
-  // Find the base file name from the path.
-  char* file_name_buffer = path_buffer;
-  for (char* p = path_buffer; *p; p++) {
-    if (*p == '/' || *p == '\\') file_name_buffer = p + 1;
-  }
-
-  // Throw an exception in case the script couldn't be read.
-  if (script.is_empty()) {
-    static const char* kErrorPrefix = "Unable to read from file ";
-    static const size_t kErrorPrefixLength = 25;  // strlen is not constant
-    ASSERT(strlen(kErrorPrefix) == kErrorPrefixLength);
-    static const int kMaxErrorLength = kMaxPathLength + kErrorPrefixLength;
-    EmbeddedVector<char, kMaxErrorLength + 1> error_buffer;
-    OS::SNPrintF(error_buffer, "%s%s", kErrorPrefix, file_name_buffer);
-    v8::Handle<v8::String> error =
-        v8::String::New(error_buffer.start(), error_buffer.length());
-    v8::ThrowException(v8::Exception::Error(error));
-    return result;
-  }
-
-  // Convert the file name buffer into a script origin
-  v8::ScriptOrigin origin =
-      v8::ScriptOrigin(v8::String::New(file_name_buffer));
-
-  // Compile and run script.
-  v8::Handle<v8::String> source =
-      v8::String::New(script.start(), script.length());
-  v8::Handle<v8::Script> code =
-      v8::Script::Compile(source, &origin);
-
-  // Run the code if no exception occurred during the compilation. In
-  // case of syntax errors, the code is empty and the exception is
-  // scheduled and will be thrown when returning to JavaScript.
-  if (!code.IsEmpty()) result = code->Run();
-  script.Dispose();
-  return result;
-}
-
-
-static LoadExtension kLoadExtension;
-v8::DeclareExtension kLoadExtensionDeclaration(&kLoadExtension);
-
-
-// --- Q u i t   E x t e n s i o n ---
-
-const char* QuitExtension::kSource = "native function quit();";
-
-
-v8::Handle<v8::FunctionTemplate> QuitExtension::GetNativeFunction(
-    v8::Handle<v8::String> str) {
-  return v8::FunctionTemplate::New(QuitExtension::Quit);
-}
-
-
-v8::Handle<v8::Value> QuitExtension::Quit(const v8::Arguments& args) {
-  exit(args.Length() == 0 ? 0 : args[0]->Int32Value());
-  return v8::Undefined();
-}
-
-
-static QuitExtension kQuitExtension;
-v8::DeclareExtension kQuitExtensionDeclaration(&kQuitExtension);
-
-
-// --- V e r s i o n   E x t e n s i o n ---
-
-static Extension kVersionExtension("v8/version",
-                                   "function version(){ return 150; }");
-v8::DeclareExtension kVersionExtensionDeclaration(&kVersionExtension);
-
-
  // --- G C   E x t e n s i o n ---

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

Modified: branches/bleeding_edge/src/execution.h
==============================================================================
--- branches/bleeding_edge/src/execution.h      (original)
+++ branches/bleeding_edge/src/execution.h      Fri Oct  3 01:30:22 2008
@@ -246,39 +246,6 @@
  };


-class PrintExtension : public v8::Extension {
- public:
-  PrintExtension() : v8::Extension("v8/print", kSource) { }
-  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
-      v8::Handle<v8::String> name);
-  static v8::Handle<v8::Value> Print(const v8::Arguments& args);
- private:
-  static const char* kSource;
-};
-
-
-class LoadExtension : public v8::Extension {
- public:
-  LoadExtension() : v8::Extension("v8/load", kSource) { }
-  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
-      v8::Handle<v8::String> name);
-  static v8::Handle<v8::Value> Load(const v8::Arguments& args);
- private:
-  static const char* kSource;
-};
-
-
-class QuitExtension : public v8::Extension {
- public:
-  QuitExtension() : v8::Extension("v8/quit", kSource) {}
-  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
-      v8::Handle<v8::String> name);
-  static v8::Handle<v8::Value> Quit(const v8::Arguments& args);
- private:
-  static const char* kSource;
-};
-
-
  class GCExtension : public v8::Extension {
   public:
    GCExtension() : v8::Extension("v8/gc", kSource) {}

Modified: branches/bleeding_edge/src/serialize.cc
==============================================================================
--- branches/bleeding_edge/src/serialize.cc     (original)
+++ branches/bleeding_edge/src/serialize.cc     Fri Oct  3 01:30:22 2008
@@ -537,12 +537,6 @@
    // Extensions
    Add(FUNCTION_ADDR(GCExtension::GC), EXTENSION, 1,
        "GCExtension::GC");
-  Add(FUNCTION_ADDR(PrintExtension::Print), EXTENSION, 2,
-      "PrintExtension::Print");
-  Add(FUNCTION_ADDR(LoadExtension::Load), EXTENSION, 3,
-      "LoadExtension::Load");
-  Add(FUNCTION_ADDR(QuitExtension::Quit), EXTENSION, 4,
-      "QuitExtension::Quit");

    // Accessors
  #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \

Modified: branches/bleeding_edge/test/cctest/test-api.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-api.cc      (original)
+++ branches/bleeding_edge/test/cctest/test-api.cc      Fri Oct  3 01:30:22 2008
@@ -4774,14 +4774,6 @@
        v8_compile("gc();")->Run();
      }
      CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
-
-    { v8::HandleScope scope;
-      const char* extension_list[] = { "v8/print" };
-      v8::ExtensionConfiguration extensions(1, extension_list);
-      LocalContext context(&extensions);
-      v8_compile("print('hest');")->Run();
-    }
-    CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
    }
  }


Modified: branches/bleeding_edge/test/cctest/test-compiler.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-compiler.cc (original)
+++ branches/bleeding_edge/test/cctest/test-compiler.cc Fri Oct  3 01:30:22  
2008
@@ -40,6 +40,51 @@

  static v8::Persistent<v8::Context> env;

+// --- P r i n t   E x t e n s i o n ---
+
+class PrintExtension : public v8::Extension {
+ public:
+  PrintExtension() : v8::Extension("v8/print", kSource) { }
+  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
+      v8::Handle<v8::String> name);
+  static v8::Handle<v8::Value> Print(const v8::Arguments& args);
+ private:
+  static const char* kSource;
+};
+
+
+const char* PrintExtension::kSource = "native function print();";
+
+
+v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction(
+    v8::Handle<v8::String> str) {
+  return v8::FunctionTemplate::New(PrintExtension::Print);
+}
+
+
+v8::Handle<v8::Value> PrintExtension::Print(const v8::Arguments& args) {
+  for (int i = 0; i < args.Length(); i++) {
+    if (i != 0) printf(" ");
+    v8::HandleScope scope;
+    v8::Handle<v8::Value> arg = args[i];
+    v8::Handle<v8::String> string_obj = arg->ToString();
+    if (string_obj.IsEmpty()) return string_obj;
+    int length = string_obj->Length();
+    uint16_t* string = NewArray<uint16_t>(length + 1);
+    string_obj->Write(string);
+    for (int j = 0; j < length; j++)
+      printf("%lc", string[j]);
+    DeleteArray(string);
+  }
+  printf("\n");
+  return v8::Undefined();
+}
+
+
+static PrintExtension kPrintExtension;
+v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension);
+
+
  static void InitializeVM() {
    if (env.IsEmpty()) {
      v8::HandleScope scope;

Modified: branches/bleeding_edge/test/cctest/test-serialize.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-serialize.cc        (original)
+++ branches/bleeding_edge/test/cctest/test-serialize.cc        Fri Oct  3  
01:30:22 2008
@@ -154,9 +154,8 @@
    StatsTable::SetCounterFunction(counter_function);

    v8::HandleScope scope;
-  const int kExtensionCount = 5;
-  const char* extension_list[kExtensionCount] =
-    { "v8/print", "v8/load", "v8/quit", "v8/version", "v8/gc" };
+  const int kExtensionCount = 1;
+  const char* extension_list[kExtensionCount] = { "v8/gc" };
    v8::ExtensionConfiguration extensions(kExtensionCount, extension_list);
    v8::Persistent<v8::Context> env = v8::Context::New(&extensions);
    env->Enter();
@@ -259,7 +258,7 @@
    v8::HandleScope scope;

    Deserialize();
-  const char* c_source = "print(\"abcd\");";
+  const char* c_source = "gc();";
    v8::Local<v8::String> source = v8::String::New(c_source);
    v8::Local<v8::Script> script = v8::Script::Compile(source);
    v8::Local<v8::Value> value = script->Run();

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

Reply via email to