v8/test/cctest/test-usecounters.cc
Adam Klein 6e39c9e1a7 Remove always-on flag --harmony-strict-legacy-accessor-builtins
It was shipped in Chrome 62.

Bug: v8:5070
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I77119540411d1fe15691d40012cb96f4e2e45048
Reviewed-on: https://chromium-review.googlesource.com/776154
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49434}
2017-11-17 04:06:30 +00:00

91 lines
3.8 KiB
C++

// Copyright 2016 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.
#include "src/v8.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
namespace test_usecounters {
int* global_use_counts = nullptr;
void MockUseCounterCallback(v8::Isolate* isolate,
v8::Isolate::UseCounterFeature feature) {
++global_use_counts[feature];
}
TEST(AssigmentExpressionLHSIsCall) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
global_use_counts = use_counts;
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
// AssignmentExpressions whose LHS is not a call do not increment counters
CompileRun("function f(){ a = 0; a()[b] = 0; }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
CompileRun("function f(){ ++a; ++a()[b]; }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
CompileRun("function f(){ 'use strict'; a = 0; a()[b] = 0; }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
CompileRun("function f(){ 'use strict'; ++a; ++a()[b]; }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
// AssignmentExpressions whose LHS is a call increment appropriate counters
CompileRun("function f(){ a() = 0; }");
CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy] = 0;
CompileRun("function f(){ 'use strict'; a() = 0; }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict] = 0;
// UpdateExpressions whose LHS is a call increment appropriate counters
CompileRun("function f(){ ++a(); }");
CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy] = 0;
CompileRun("function f(){ 'use strict'; ++a(); }");
CHECK_EQ(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInSloppy]);
CHECK_NE(0, use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict]);
use_counts[v8::Isolate::kAssigmentExpressionLHSIsCallInStrict] = 0;
}
TEST(LabeledExpressionStatement) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
global_use_counts = use_counts;
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
CompileRun("typeof a");
CHECK_EQ(0, use_counts[v8::Isolate::kLabeledExpressionStatement]);
CompileRun("foo: null");
CHECK_EQ(1, use_counts[v8::Isolate::kLabeledExpressionStatement]);
CompileRun("foo: bar: baz: undefined");
CHECK_EQ(2, use_counts[v8::Isolate::kLabeledExpressionStatement]);
CompileRun(
"foo: if (false);"
"bar: { }"
"baz: switch (false) { }"
"bat: do { } while (false);");
CHECK_EQ(2, use_counts[v8::Isolate::kLabeledExpressionStatement]);
}
} // namespace test_usecounters
} // namespace internal
} // namespace v8