Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: test/cctest/test-api.cc

Issue 861053003: add some tests for HandleApiCall builtin (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23418 matching lines...) Expand 10 before | Expand all | Expand 10 after
23429 int ApiCallOptimizationChecker::count = 0; 23429 int ApiCallOptimizationChecker::count = 0;
23430 23430
23431 23431
23432 TEST(FunctionCallOptimization) { 23432 TEST(FunctionCallOptimization) {
23433 i::FLAG_allow_natives_syntax = true; 23433 i::FLAG_allow_natives_syntax = true;
23434 ApiCallOptimizationChecker checker; 23434 ApiCallOptimizationChecker checker;
23435 checker.RunAll(); 23435 checker.RunAll();
23436 } 23436 }
23437 23437
23438 23438
23439 static void EmptyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {} 23439 static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) {
23440 info.GetReturnValue().Set(42);
23441 }
23440 23442
23441 23443
23442 TEST(FunctionCallOptimizationMultipleArgs) { 23444 TEST(FunctionCallOptimizationMultipleArgs) {
23443 i::FLAG_allow_natives_syntax = true; 23445 i::FLAG_allow_natives_syntax = true;
23444 LocalContext context; 23446 LocalContext context;
23445 v8::Isolate* isolate = context->GetIsolate(); 23447 v8::Isolate* isolate = context->GetIsolate();
23446 v8::HandleScope scope(isolate); 23448 v8::HandleScope scope(isolate);
23447 Handle<Object> global = context->Global(); 23449 Handle<Object> global = context->Global();
23448 Local<v8::Function> function = Function::New(isolate, EmptyCallback); 23450 Local<v8::Function> function = Function::New(isolate, Returns42);
23449 global->Set(v8_str("x"), function); 23451 global->Set(v8_str("x"), function);
23450 CompileRun( 23452 CompileRun(
23451 "function x_wrap() {\n" 23453 "function x_wrap() {\n"
23452 " for (var i = 0; i < 5; i++) {\n" 23454 " for (var i = 0; i < 5; i++) {\n"
23453 " x(1,2,3);\n" 23455 " x(1,2,3);\n"
23454 " }\n" 23456 " }\n"
23455 "}\n" 23457 "}\n"
23456 "x_wrap();\n" 23458 "x_wrap();\n"
23457 "%OptimizeFunctionOnNextCall(x_wrap);" 23459 "%OptimizeFunctionOnNextCall(x_wrap);"
23458 "x_wrap();\n"); 23460 "x_wrap();\n");
(...skipping 19 matching lines...) Expand all
23478 " for (var i = 0; i < 5; i++) {\n" 23480 " for (var i = 0; i < 5; i++) {\n"
23479 " x();\n" 23481 " x();\n"
23480 " }\n" 23482 " }\n"
23481 "}\n" 23483 "}\n"
23482 "x_wrap();\n" 23484 "x_wrap();\n"
23483 "%OptimizeFunctionOnNextCall(x_wrap);" 23485 "%OptimizeFunctionOnNextCall(x_wrap);"
23484 "x_wrap();\n"); 23486 "x_wrap();\n");
23485 } 23487 }
23486 23488
23487 23489
23490 TEST(EmptyApiCallback) {
23491 LocalContext context;
23492 auto isolate = context->GetIsolate();
23493 v8::HandleScope scope(isolate);
23494 auto global = context->Global();
23495 auto function = FunctionTemplate::New(isolate)->GetFunction();
23496 global->Set(v8_str("x"), function);
23497
23498 auto result = CompileRun("x()");
23499 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy());
23500
23501 result = CompileRun("x(1,2,3)");
23502 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy());
23503
23504 result = CompileRun("7 + x.call(3) + 11");
23505 CHECK(result->IsInt32());
23506 CHECK_EQ(21, result->Int32Value());
23507
23508 result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11");
23509 CHECK(result->IsInt32());
23510 CHECK_EQ(21, result->Int32Value());
23511
23512 result = CompileRun("var y = []; x.call(y)");
23513 CHECK(result->IsArray());
23514
23515 result = CompileRun("x.call(y, 1, 2, 3, 4)");
23516 CHECK(result->IsArray());
23517 }
23518
23519
23520 TEST(SimpleSignatureCheck) {
23521 LocalContext context;
23522 auto isolate = context->GetIsolate();
23523 v8::HandleScope scope(isolate);
23524 auto global = context->Global();
23525 auto sig_obj = FunctionTemplate::New(isolate);
23526 auto sig = v8::Signature::New(isolate, sig_obj);
23527 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig);
23528 global->Set(v8_str("sig_obj"), sig_obj->GetFunction());
23529 global->Set(v8_str("x"), x->GetFunction());
23530 CompileRun("var s = new sig_obj();");
23531 {
23532 TryCatch try_catch(isolate);
23533 CompileRun("x()");
23534 CHECK(try_catch.HasCaught());
23535 }
23536 {
23537 TryCatch try_catch(isolate);
23538 CompileRun("x.call(1)");
23539 CHECK(try_catch.HasCaught());
23540 }
23541 {
23542 TryCatch try_catch(isolate);
23543 auto result = CompileRun("s.x = x; s.x()");
23544 CHECK(!try_catch.HasCaught());
23545 CHECK_EQ(42, result->Int32Value());
23546 }
23547 {
23548 TryCatch try_catch(isolate);
23549 auto result = CompileRun("x.call(s)");
23550 CHECK(!try_catch.HasCaught());
23551 CHECK_EQ(42, result->Int32Value());
23552 }
23553 }
23554
23555
23556 TEST(ChainSignatureCheck) {
23557 LocalContext context;
23558 auto isolate = context->GetIsolate();
23559 v8::HandleScope scope(isolate);
23560 auto global = context->Global();
23561 auto sig_obj = FunctionTemplate::New(isolate);
23562 auto sig = v8::Signature::New(isolate, sig_obj);
23563 for (int i = 0; i < 4; ++i) {
23564 auto temp = FunctionTemplate::New(isolate);
23565 temp->Inherit(sig_obj);
23566 sig_obj = temp;
23567 }
23568 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig);
23569 global->Set(v8_str("sig_obj"), sig_obj->GetFunction());
23570 global->Set(v8_str("x"), x->GetFunction());
23571 CompileRun("var s = new sig_obj();");
23572 {
23573 TryCatch try_catch(isolate);
23574 CompileRun("x()");
23575 CHECK(try_catch.HasCaught());
23576 }
23577 {
23578 TryCatch try_catch(isolate);
23579 CompileRun("x.call(1)");
23580 CHECK(try_catch.HasCaught());
23581 }
23582 {
23583 TryCatch try_catch(isolate);
23584 auto result = CompileRun("s.x = x; s.x()");
23585 CHECK(!try_catch.HasCaught());
23586 CHECK_EQ(42, result->Int32Value());
23587 }
23588 {
23589 TryCatch try_catch(isolate);
23590 auto result = CompileRun("x.call(s)");
23591 CHECK(!try_catch.HasCaught());
23592 CHECK_EQ(42, result->Int32Value());
23593 }
23594 }
23595
23596
23597 TEST(PrototypeSignatureCheck) {
23598 LocalContext context;
23599 auto isolate = context->GetIsolate();
23600 v8::HandleScope scope(isolate);
23601 auto global = context->Global();
23602 auto sig_obj = FunctionTemplate::New(isolate);
23603 sig_obj->SetHiddenPrototype(true);
23604 auto sig = v8::Signature::New(isolate, sig_obj);
23605 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig);
23606 global->Set(v8_str("sig_obj"), sig_obj->GetFunction());
23607 global->Set(v8_str("x"), x->GetFunction());
23608 CompileRun("s = {}; s.__proto__ = new sig_obj();");
23609 {
23610 TryCatch try_catch(isolate);
23611 CompileRun("x()");
23612 CHECK(try_catch.HasCaught());
23613 }
23614 {
23615 TryCatch try_catch(isolate);
23616 CompileRun("x.call(1)");
23617 CHECK(try_catch.HasCaught());
23618 }
23619 {
23620 TryCatch try_catch(isolate);
23621 auto result = CompileRun("s.x = x; s.x()");
23622 CHECK(!try_catch.HasCaught());
23623 CHECK_EQ(42, result->Int32Value());
23624 }
23625 {
23626 TryCatch try_catch(isolate);
23627 auto result = CompileRun("x.call(s)");
23628 CHECK(!try_catch.HasCaught());
23629 CHECK_EQ(42, result->Int32Value());
23630 }
23631 }
23632
23633
23488 static const char* last_event_message; 23634 static const char* last_event_message;
23489 static int last_event_status; 23635 static int last_event_status;
23490 void StoringEventLoggerCallback(const char* message, int status) { 23636 void StoringEventLoggerCallback(const char* message, int status) {
23491 last_event_message = message; 23637 last_event_message = message;
23492 last_event_status = status; 23638 last_event_status = status;
23493 } 23639 }
23494 23640
23495 23641
23496 TEST(EventLogging) { 23642 TEST(EventLogging) {
23497 v8::Isolate* isolate = CcTest::isolate(); 23643 v8::Isolate* isolate = CcTest::isolate();
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
24573 "bar2.js"); 24719 "bar2.js");
24574 } 24720 }
24575 24721
24576 24722
24577 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { 24723 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
24578 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", 24724 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
24579 " sourceMappingURL=bar2.js\n", "foo();", NULL}; 24725 " sourceMappingURL=bar2.js\n", "foo();", NULL};
24580 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, 24726 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
24581 "bar2.js"); 24727 "bar2.js");
24582 } 24728 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698