OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iostream> | 5 #include <iostream> |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/test/v8_unit_test.h" | 8 #include "chrome/test/v8_unit_test.h" |
9 | 9 |
10 void V8UnitTest::SetUp() { | 10 void V8UnitTest::SetUp() { |
11 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 11 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
12 global->Set(v8::String::New("log"), | 12 global->Set(v8::String::New("log"), |
13 v8::FunctionTemplate::New(&V8UnitTest::Log)); | 13 v8::FunctionTemplate::New(&V8UnitTest::Log)); |
14 context_ = v8::Context::New(NULL, global); | 14 context_ = v8::Context::New(NULL, global); |
15 } | 15 } |
16 | 16 |
17 void V8UnitTest::ExecuteScriptInContext(const StringPiece& script_source, | 17 void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source, |
18 const StringPiece& script_name) { | 18 const base::StringPiece& script_name) { |
19 v8::Context::Scope context_scope(context_); | 19 v8::Context::Scope context_scope(context_); |
20 v8::HandleScope handle_scope; | 20 v8::HandleScope handle_scope; |
21 v8::Handle<v8::String> source = v8::String::New(script_source.data(), | 21 v8::Handle<v8::String> source = v8::String::New(script_source.data(), |
22 script_source.size()); | 22 script_source.size()); |
23 v8::Handle<v8::String> name = v8::String::New(script_name.data(), | 23 v8::Handle<v8::String> name = v8::String::New(script_name.data(), |
24 script_source.size()); | 24 script_source.size()); |
25 | 25 |
26 v8::TryCatch try_catch; | 26 v8::TryCatch try_catch; |
27 v8::Handle<v8::Script> script = v8::Script::Compile(source, name); | 27 v8::Handle<v8::Script> script = v8::Script::Compile(source, name); |
28 // Ensure the script compiled without errors. | 28 // Ensure the script compiled without errors. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 first = false; | 84 first = false; |
85 } else { | 85 } else { |
86 message += " "; | 86 message += " "; |
87 } | 87 } |
88 v8::String::Utf8Value str(args[i]); | 88 v8::String::Utf8Value str(args[i]); |
89 message += *str; | 89 message += *str; |
90 } | 90 } |
91 std::cout << message << "\n"; | 91 std::cout << message << "\n"; |
92 return v8::Undefined(); | 92 return v8::Undefined(); |
93 } | 93 } |
OLD | NEW |