| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "gin/arguments.h" | 6 #include "gin/arguments.h" |
| 7 #include "gin/handle.h" | 7 #include "gin/handle.h" |
| 8 #include "gin/interceptor.h" | 8 #include "gin/interceptor.h" |
| 9 #include "gin/object_template_builder.h" | 9 #include "gin/object_template_builder.h" |
| 10 #include "gin/per_isolate_data.h" | 10 #include "gin/per_isolate_data.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 public: | 129 public: |
| 130 void RunInterceptorTest(const std::string& script_source) { | 130 void RunInterceptorTest(const std::string& script_source) { |
| 131 v8::Isolate* isolate = instance_->isolate(); | 131 v8::Isolate* isolate = instance_->isolate(); |
| 132 v8::HandleScope handle_scope(isolate); | 132 v8::HandleScope handle_scope(isolate); |
| 133 | 133 |
| 134 gin::Handle<MyInterceptor> obj = MyInterceptor::Create(isolate); | 134 gin::Handle<MyInterceptor> obj = MyInterceptor::Create(isolate); |
| 135 | 135 |
| 136 obj->set_value(42); | 136 obj->set_value(42); |
| 137 EXPECT_EQ(42, obj->value()); | 137 EXPECT_EQ(42, obj->value()); |
| 138 | 138 |
| 139 v8::Handle<v8::String> source = StringToV8(isolate, script_source); | 139 v8::Local<v8::String> source = StringToV8(isolate, script_source); |
| 140 EXPECT_FALSE(source.IsEmpty()); | 140 EXPECT_FALSE(source.IsEmpty()); |
| 141 | 141 |
| 142 gin::TryCatch try_catch; | 142 gin::TryCatch try_catch; |
| 143 v8::Handle<v8::Script> script = v8::Script::Compile(source); | 143 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 144 EXPECT_FALSE(script.IsEmpty()); | 144 EXPECT_FALSE(script.IsEmpty()); |
| 145 v8::Handle<v8::Value> val = script->Run(); | 145 v8::Local<v8::Value> val = script->Run(); |
| 146 EXPECT_FALSE(val.IsEmpty()); | 146 EXPECT_FALSE(val.IsEmpty()); |
| 147 v8::Handle<v8::Function> func; | 147 v8::Local<v8::Function> func; |
| 148 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); | 148 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); |
| 149 v8::Handle<v8::Value> argv[] = {ConvertToV8(isolate, obj.get()), }; | 149 v8::Local<v8::Value> argv[] = {ConvertToV8(isolate, obj.get()), }; |
| 150 func->Call(v8::Undefined(isolate), 1, argv); | 150 func->Call(v8::Undefined(isolate), 1, argv); |
| 151 EXPECT_FALSE(try_catch.HasCaught()); | 151 EXPECT_FALSE(try_catch.HasCaught()); |
| 152 EXPECT_EQ("", try_catch.GetStackTrace()); | 152 EXPECT_EQ("", try_catch.GetStackTrace()); |
| 153 | 153 |
| 154 EXPECT_EQ(191, obj->value()); | 154 EXPECT_EQ(191, obj->value()); |
| 155 } | 155 } |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 TEST_F(InterceptorTest, NamedInterceptor) { | 158 TEST_F(InterceptorTest, NamedInterceptor) { |
| 159 RunInterceptorTest( | 159 RunInterceptorTest( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 186 | 186 |
| 187 TEST_F(InterceptorTest, BypassInterceptorForbidden) { | 187 TEST_F(InterceptorTest, BypassInterceptorForbidden) { |
| 188 RunInterceptorTest( | 188 RunInterceptorTest( |
| 189 "(function (obj) {" | 189 "(function (obj) {" |
| 190 " obj.value = 191 /* make test happy */;" | 190 " obj.value = 191 /* make test happy */;" |
| 191 " obj[1] = 23;" | 191 " obj[1] = 23;" |
| 192 " if (obj[1] === 23) throw 'FAIL'; })"); | 192 " if (obj[1] === 23) throw 'FAIL'; })"); |
| 193 } | 193 } |
| 194 | 194 |
| 195 } // namespace gin | 195 } // namespace gin |
| OLD | NEW |