| Index: src/execution.cc
|
| ===================================================================
|
| --- src/execution.cc (revision 404)
|
| +++ src/execution.cc (working copy)
|
| @@ -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();";
|
|
|