2015-02-27 06:56:44 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-03-18 11:42:36 +00:00
|
|
|
#include "src/bootstrapper.h"
|
2015-02-27 06:56:44 +00:00
|
|
|
#include "src/code-stubs.h"
|
2015-03-18 11:42:36 +00:00
|
|
|
#include "src/compiler/common-operator.h"
|
2015-02-27 06:56:44 +00:00
|
|
|
#include "src/compiler/graph.h"
|
2015-05-11 11:45:02 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
|
|
|
#include "src/compiler/js-operator.h"
|
2015-02-27 06:56:44 +00:00
|
|
|
#include "src/compiler/linkage.h"
|
2015-05-11 11:45:02 +00:00
|
|
|
#include "src/compiler/machine-operator.h"
|
2015-02-27 06:56:44 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/parsing/parser.h"
|
2015-02-27 06:56:44 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2015-02-27 06:56:44 +00:00
|
|
|
|
|
|
|
|
2015-12-02 12:35:12 +00:00
|
|
|
TEST(RunStringLengthStub) {
|
2015-02-27 06:56:44 +00:00
|
|
|
HandleAndZoneScope scope;
|
|
|
|
Isolate* isolate = scope.main_isolate();
|
|
|
|
Zone* zone = scope.main_zone();
|
|
|
|
|
|
|
|
// Create code and an accompanying descriptor.
|
2015-12-02 12:35:12 +00:00
|
|
|
StringLengthStub stub(isolate);
|
2015-02-27 06:56:44 +00:00
|
|
|
Handle<Code> code = stub.GenerateCode();
|
2016-04-26 14:36:35 +00:00
|
|
|
CompilationInfo info(ArrayVector("test"), isolate, zone,
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::ComputeFlags(Code::HANDLER));
|
|
|
|
CallInterfaceDescriptor interface_descriptor =
|
|
|
|
stub.GetCallInterfaceDescriptor();
|
|
|
|
CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
|
|
|
|
isolate, zone, interface_descriptor, stub.GetStackParameterCount(),
|
|
|
|
CallDescriptor::kNoFlags, Operator::kNoProperties);
|
2015-02-27 06:56:44 +00:00
|
|
|
|
|
|
|
// Create a function to call the code using the descriptor.
|
|
|
|
Graph graph(zone);
|
|
|
|
CommonOperatorBuilder common(zone);
|
2015-05-20 13:19:11 +00:00
|
|
|
// FunctionTester (ab)uses a 4-argument function
|
2015-07-06 12:11:50 +00:00
|
|
|
Node* start = graph.NewNode(common.Start(6));
|
2015-02-27 06:56:44 +00:00
|
|
|
// Parameter 0 is the receiver
|
|
|
|
Node* receiverParam = graph.NewNode(common.Parameter(1), start);
|
|
|
|
Node* nameParam = graph.NewNode(common.Parameter(2), start);
|
2015-05-20 13:19:11 +00:00
|
|
|
Node* slotParam = graph.NewNode(common.Parameter(3), start);
|
|
|
|
Node* vectorParam = graph.NewNode(common.Parameter(4), start);
|
2015-08-31 08:24:52 +00:00
|
|
|
Node* theCode = graph.NewNode(common.HeapConstant(code));
|
2015-02-27 06:56:44 +00:00
|
|
|
Node* dummyContext = graph.NewNode(common.NumberConstant(0.0));
|
2015-05-20 13:19:11 +00:00
|
|
|
Node* call =
|
|
|
|
graph.NewNode(common.Call(descriptor), theCode, receiverParam, nameParam,
|
|
|
|
slotParam, vectorParam, dummyContext, start, start);
|
2015-02-27 06:56:44 +00:00
|
|
|
Node* ret = graph.NewNode(common.Return(), call, call, start);
|
2015-05-26 10:31:55 +00:00
|
|
|
Node* end = graph.NewNode(common.End(1), ret);
|
2015-02-27 06:56:44 +00:00
|
|
|
graph.SetStart(start);
|
|
|
|
graph.SetEnd(end);
|
2015-12-02 12:35:12 +00:00
|
|
|
FunctionTester ft(&graph, 4);
|
2015-02-27 06:56:44 +00:00
|
|
|
|
|
|
|
// Actuall call through to the stub, verifying its result.
|
|
|
|
const char* testString = "Und das Lamm schrie HURZ!";
|
|
|
|
Handle<JSReceiver> receiverArg =
|
|
|
|
Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked();
|
|
|
|
Handle<String> nameArg = ft.Val("length");
|
2015-05-20 13:19:11 +00:00
|
|
|
Handle<Object> slot = ft.Val(0.0);
|
|
|
|
Handle<Object> vector = ft.Val(0.0);
|
|
|
|
Handle<Object> result =
|
|
|
|
ft.Call(receiverArg, nameArg, slot, vector).ToHandleChecked();
|
2015-02-27 06:56:44 +00:00
|
|
|
CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value());
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:31:41 +00:00
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|