OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "include/v8.h" | 7 #include "include/v8.h" |
8 #include "include/v8-experimental.h" | 8 #include "include/v8-experimental.h" |
9 | 9 |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 val.intval = 0; | 280 val.intval = 0; |
281 ExpectInt32("nonzero()", 0); | 281 ExpectInt32("nonzero()", 0); |
282 val.intval = 27; | 282 val.intval = 27; |
283 ExpectInt32("nonzero()", 1); | 283 ExpectInt32("nonzero()", 1); |
284 | 284 |
285 // Access val.v8val: | 285 // Access val.v8val: |
286 CompileRun(FN_WARMUP("loadval", "return obj.loadval")); | 286 CompileRun(FN_WARMUP("loadval", "return obj.loadval")); |
287 ExpectString("loadval()", "Hello"); | 287 ExpectString("loadval()", "Hello"); |
288 } | 288 } |
289 | 289 |
290 | |
291 void ApiCallbackInt(const v8::FunctionCallbackInfo<v8::Value>& info) { | 290 void ApiCallbackInt(const v8::FunctionCallbackInfo<v8::Value>& info) { |
292 info.GetReturnValue().Set(12345); | 291 info.GetReturnValue().Set(12345); |
293 } | 292 } |
294 | 293 |
295 const char* kApiCallbackStringValue = | 294 const char* kApiCallbackStringValue = |
296 "Hello World! Bizarro C++ world, actually."; | 295 "Hello World! Bizarro C++ world, actually."; |
297 void ApiCallbackString(const v8::FunctionCallbackInfo<v8::Value>& info) { | 296 void ApiCallbackString(const v8::FunctionCallbackInfo<v8::Value>& info) { |
298 info.GetReturnValue().Set(v8_str(kApiCallbackStringValue)); | 297 info.GetReturnValue().Set(v8_str(kApiCallbackStringValue)); |
299 } | 298 } |
300 | 299 |
301 | |
302 void ApiCallbackParam(const v8::FunctionCallbackInfo<v8::Value>& info) { | 300 void ApiCallbackParam(const v8::FunctionCallbackInfo<v8::Value>& info) { |
303 CHECK_EQ(1, info.Length()); | 301 CHECK_EQ(1, info.Length()); |
304 CHECK(info[0]->IsNumber()); | 302 CHECK(info[0]->IsNumber()); |
305 info.GetReturnValue().Set(info[0]); | 303 info.GetReturnValue().Set(info[0]); |
306 } | 304 } |
307 | 305 |
308 | |
309 // "Fast" accessor, callback to embedder | 306 // "Fast" accessor, callback to embedder |
310 TEST(FastAccessorCallback) { | 307 TEST(FastAccessorCallback) { |
311 LocalContext env; | 308 LocalContext env; |
312 v8::Isolate* isolate = env->GetIsolate(); | 309 v8::Isolate* isolate = env->GetIsolate(); |
313 v8::HandleScope scope(isolate); | 310 v8::HandleScope scope(isolate); |
314 | 311 |
315 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); | 312 v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate); |
316 { | 313 { |
317 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); | 314 auto builder = v8::experimental::FastAccessorBuilder::New(isolate); |
318 builder->ReturnValue( | 315 builder->ReturnValue( |
(...skipping 24 matching lines...) Expand all Loading... |
343 // Callbacks: | 340 // Callbacks: |
344 CompileRun(FN_WARMUP("callbackint", "return obj.int")); | 341 CompileRun(FN_WARMUP("callbackint", "return obj.int")); |
345 ExpectInt32("callbackint()", 12345); | 342 ExpectInt32("callbackint()", 12345); |
346 | 343 |
347 CompileRun(FN_WARMUP("callbackstr", "return obj.str")); | 344 CompileRun(FN_WARMUP("callbackstr", "return obj.str")); |
348 ExpectString("callbackstr()", kApiCallbackStringValue); | 345 ExpectString("callbackstr()", kApiCallbackStringValue); |
349 | 346 |
350 CompileRun(FN_WARMUP("callbackparam", "return obj.param")); | 347 CompileRun(FN_WARMUP("callbackparam", "return obj.param")); |
351 ExpectInt32("callbackparam()", 1000); | 348 ExpectInt32("callbackparam()", 1000); |
352 } | 349 } |
OLD | NEW |