| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 using namespace v8::internal; | 41 using namespace v8::internal; |
| 42 | 42 |
| 43 // --- P r i n t E x t e n s i o n --- | 43 // --- P r i n t E x t e n s i o n --- |
| 44 | 44 |
| 45 class PrintExtension : public v8::Extension { | 45 class PrintExtension : public v8::Extension { |
| 46 public: | 46 public: |
| 47 PrintExtension() : v8::Extension("v8/print", kSource) { } | 47 PrintExtension() : v8::Extension("v8/print", kSource) { } |
| 48 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 48 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| 49 v8::Handle<v8::String> name); | 49 v8::Handle<v8::String> name); |
| 50 static v8::Handle<v8::Value> Print(const v8::Arguments& args); | 50 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 51 private: | 51 private: |
| 52 static const char* kSource; | 52 static const char* kSource; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 | 55 |
| 56 const char* PrintExtension::kSource = "native function print();"; | 56 const char* PrintExtension::kSource = "native function print();"; |
| 57 | 57 |
| 58 | 58 |
| 59 v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction( | 59 v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction( |
| 60 v8::Handle<v8::String> str) { | 60 v8::Handle<v8::String> str) { |
| 61 return v8::FunctionTemplate::New(PrintExtension::Print); | 61 return v8::FunctionTemplate::New(PrintExtension::Print); |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 v8::Handle<v8::Value> PrintExtension::Print(const v8::Arguments& args) { | 65 void PrintExtension::Print(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 66 for (int i = 0; i < args.Length(); i++) { | 66 for (int i = 0; i < args.Length(); i++) { |
| 67 if (i != 0) printf(" "); | 67 if (i != 0) printf(" "); |
| 68 v8::HandleScope scope(args.GetIsolate()); | 68 v8::HandleScope scope(args.GetIsolate()); |
| 69 v8::String::Utf8Value str(args[i]); | 69 v8::String::Utf8Value str(args[i]); |
| 70 if (*str == NULL) return v8::Undefined(); | 70 if (*str == NULL) return; |
| 71 printf("%s", *str); | 71 printf("%s", *str); |
| 72 } | 72 } |
| 73 printf("\n"); | 73 printf("\n"); |
| 74 return v8::Undefined(); | |
| 75 } | 74 } |
| 76 | 75 |
| 77 | 76 |
| 78 static PrintExtension kPrintExtension; | 77 static PrintExtension kPrintExtension; |
| 79 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); | 78 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); |
| 80 | 79 |
| 81 | 80 |
| 82 static MaybeObject* GetGlobalProperty(const char* name) { | 81 static MaybeObject* GetGlobalProperty(const char* name) { |
| 83 Isolate* isolate = Isolate::Current(); | 82 Isolate* isolate = Isolate::Current(); |
| 84 Handle<String> internalized_name = | 83 Handle<String> internalized_name = |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 CompileRun("function f() { a = 12345678 }; f();"); | 420 CompileRun("function f() { a = 12345678 }; f();"); |
| 422 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 421 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); |
| 423 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 422 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 424 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 423 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); |
| 425 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 424 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 426 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 425 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); |
| 427 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 426 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 428 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); | 427 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); |
| 429 } | 428 } |
| 430 #endif | 429 #endif |
| OLD | NEW |