| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include <wchar.h> | 29 #include <wchar.h> |
| 30 | 30 |
| 31 #include "v8.h" | 31 #include "v8.h" |
| 32 | 32 |
| 33 #include "compiler.h" | 33 #include "compiler.h" |
| 34 #include "disasm.h" | 34 #include "disasm.h" |
| 35 #include "disassembler.h" | |
| 36 #include "execution.h" | |
| 37 #include "factory.h" | |
| 38 #include "platform.h" | |
| 39 #include "cctest.h" | 35 #include "cctest.h" |
| 40 | 36 |
| 41 using namespace v8::internal; | 37 using namespace v8::internal; |
| 42 | 38 |
| 43 // --- P r i n t E x t e n s i o n --- | |
| 44 | |
| 45 class PrintExtension : public v8::Extension { | |
| 46 public: | |
| 47 PrintExtension() : v8::Extension("v8/print", kSource) { } | |
| 48 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | |
| 49 v8::Isolate* isolate, | |
| 50 v8::Handle<v8::String> name); | |
| 51 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 52 private: | |
| 53 static const char* kSource; | |
| 54 }; | |
| 55 | |
| 56 | |
| 57 const char* PrintExtension::kSource = "native function print();"; | |
| 58 | |
| 59 | |
| 60 v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunctionTemplate( | |
| 61 v8::Isolate* isolate, | |
| 62 v8::Handle<v8::String> str) { | |
| 63 return v8::FunctionTemplate::New(isolate, PrintExtension::Print); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 void PrintExtension::Print(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 68 for (int i = 0; i < args.Length(); i++) { | |
| 69 if (i != 0) printf(" "); | |
| 70 v8::HandleScope scope(args.GetIsolate()); | |
| 71 v8::String::Utf8Value str(args[i]); | |
| 72 if (*str == NULL) return; | |
| 73 printf("%s", *str); | |
| 74 } | |
| 75 printf("\n"); | |
| 76 } | |
| 77 | |
| 78 | |
| 79 static PrintExtension kPrintExtension; | |
| 80 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); | |
| 81 | |
| 82 | |
| 83 static MaybeObject* GetGlobalProperty(const char* name) { | 39 static MaybeObject* GetGlobalProperty(const char* name) { |
| 84 Isolate* isolate = CcTest::i_isolate(); | 40 Isolate* isolate = CcTest::i_isolate(); |
| 85 Handle<String> internalized_name = | 41 Handle<String> internalized_name = |
| 86 isolate->factory()->InternalizeUtf8String(name); | 42 isolate->factory()->InternalizeUtf8String(name); |
| 87 return isolate->context()->global_object()->GetProperty(*internalized_name); | 43 return isolate->context()->global_object()->GetProperty(*internalized_name); |
| 88 } | 44 } |
| 89 | 45 |
| 90 | 46 |
| 91 static void SetGlobalProperty(const char* name, Object* value) { | 47 static void SetGlobalProperty(const char* name, Object* value) { |
| 92 Isolate* isolate = CcTest::i_isolate(); | 48 Isolate* isolate = CcTest::i_isolate(); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 CompileRun("function f() { a = 12345678 }; f();"); | 393 CompileRun("function f() { a = 12345678 }; f();"); |
| 438 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 394 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 439 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 395 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 440 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 396 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 441 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 397 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 442 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 398 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 443 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 399 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 444 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 400 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 445 } | 401 } |
| 446 #endif | 402 #endif |
| OLD | NEW |