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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction( | 61 v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunction( |
62 v8::Handle<v8::String> str) { | 62 v8::Handle<v8::String> str) { |
63 return v8::FunctionTemplate::New(PrintExtension::Print); | 63 return v8::FunctionTemplate::New(PrintExtension::Print); |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 v8::Handle<v8::Value> PrintExtension::Print(const v8::Arguments& args) { | 67 v8::Handle<v8::Value> PrintExtension::Print(const v8::Arguments& args) { |
68 for (int i = 0; i < args.Length(); i++) { | 68 for (int i = 0; i < args.Length(); i++) { |
69 if (i != 0) printf(" "); | 69 if (i != 0) printf(" "); |
70 v8::HandleScope scope; | 70 v8::HandleScope scope; |
71 v8::String::Utf8Value str(args[i]); | 71 v8::Handle<v8::Value> arg = args[i]; |
72 if (*str == NULL) return v8::Undefined(); | 72 v8::Handle<v8::String> string_obj = arg->ToString(); |
73 printf("%s", *str); | 73 if (string_obj.IsEmpty()) return string_obj; |
| 74 int length = string_obj->Length(); |
| 75 uint16_t* string = NewArray<uint16_t>(length + 1); |
| 76 string_obj->Write(string); |
| 77 for (int j = 0; j < length; j++) |
| 78 printf("%lc", static_cast<wchar_t>(string[j])); |
| 79 DeleteArray(string); |
74 } | 80 } |
75 printf("\n"); | 81 printf("\n"); |
76 return v8::Undefined(); | 82 return v8::Undefined(); |
77 } | 83 } |
78 | 84 |
79 | 85 |
80 static PrintExtension kPrintExtension; | 86 static PrintExtension kPrintExtension; |
81 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); | 87 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); |
82 | 88 |
83 | 89 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 CompileRun("function f() { a = 12345678 }; f();"); | 430 CompileRun("function f() { a = 12345678 }; f();"); |
425 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 431 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
426 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 432 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
427 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 433 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
428 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 434 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
429 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 435 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
430 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 436 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
431 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); | 437 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); |
432 } | 438 } |
433 #endif | 439 #endif |
OLD | NEW |