summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-api-interceptors.cc
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-05-02 10:50:00 +0200
committerMichaël Zasso <targos@protonmail.com>2017-05-06 20:02:35 +0200
commit60d1aac8d225e844e68ae48e8f3d58802e635fbe (patch)
tree922f347dd054db18d88666fad7181e5a777f4022 /deps/v8/test/cctest/test-api-interceptors.cc
parent73d9c0f903ae371cd5011af64c3a6f69a1bda978 (diff)
downloadandroid-node-v8-60d1aac8d225e844e68ae48e8f3d58802e635fbe.tar.gz
android-node-v8-60d1aac8d225e844e68ae48e8f3d58802e635fbe.tar.bz2
android-node-v8-60d1aac8d225e844e68ae48e8f3d58802e635fbe.zip
deps: update V8 to 5.8.283.38
PR-URL: https://github.com/nodejs/node/pull/12784 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest/test-api-interceptors.cc')
-rw-r--r--deps/v8/test/cctest/test-api-interceptors.cc239
1 files changed, 149 insertions, 90 deletions
diff --git a/deps/v8/test/cctest/test-api-interceptors.cc b/deps/v8/test/cctest/test-api-interceptors.cc
index 66f0a0b0eb..955b8f4df5 100644
--- a/deps/v8/test/cctest/test-api-interceptors.cc
+++ b/deps/v8/test/cctest/test-api-interceptors.cc
@@ -12,7 +12,9 @@
#include "src/base/platform/platform.h"
#include "src/compilation-cache.h"
#include "src/execution.h"
+#include "src/objects-inl.h"
#include "src/objects.h"
+#include "src/runtime/runtime.h"
#include "src/unicode-inl.h"
#include "src/utils.h"
@@ -403,12 +405,12 @@ THREADED_TEST(QueryInterceptor) {
->NewInstance(env.local())
.ToLocalChecked())
.FromJust();
- CHECK_EQ(query_counter_int, 0);
+ CHECK_EQ(0, query_counter_int);
v8::Local<Value> result =
v8_compile("Object.getOwnPropertyDescriptor(obj, 'x');")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(query_counter_int, 1);
+ CHECK_EQ(1, query_counter_int);
CHECK_EQ(v8::PropertyAttribute::None,
static_cast<v8::PropertyAttribute>(
result->Int32Value(env.local()).FromJust()));
@@ -416,64 +418,64 @@ THREADED_TEST(QueryInterceptor) {
v8_compile("Object.defineProperty(obj, 'not_enum', {value: 17});")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(query_counter_int, 2);
+ CHECK_EQ(2, query_counter_int);
v8_compile(
"Object.defineProperty(obj, 'enum', {value: 17, enumerable: true, "
"writable: true});")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(query_counter_int, 3);
+ CHECK_EQ(3, query_counter_int);
CHECK(v8_compile("obj.propertyIsEnumerable('enum');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 4);
+ CHECK_EQ(4, query_counter_int);
CHECK(!v8_compile("obj.propertyIsEnumerable('not_enum');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 5);
+ CHECK_EQ(5, query_counter_int);
CHECK(v8_compile("obj.hasOwnProperty('enum');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 5);
+ CHECK_EQ(5, query_counter_int);
CHECK(v8_compile("obj.hasOwnProperty('not_enum');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 5);
+ CHECK_EQ(5, query_counter_int);
CHECK(!v8_compile("obj.hasOwnProperty('x');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 6);
+ CHECK_EQ(6, query_counter_int);
CHECK(!v8_compile("obj.propertyIsEnumerable('undef');")
->Run(env.local())
.ToLocalChecked()
->BooleanValue(env.local())
.FromJust());
- CHECK_EQ(query_counter_int, 7);
+ CHECK_EQ(7, query_counter_int);
v8_compile("Object.defineProperty(obj, 'enum', {value: 42});")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(query_counter_int, 8);
+ CHECK_EQ(8, query_counter_int);
v8_compile("Object.isFrozen('obj.x');")->Run(env.local()).ToLocalChecked();
- CHECK_EQ(query_counter_int, 8);
+ CHECK_EQ(8, query_counter_int);
}
namespace {
@@ -494,6 +496,12 @@ void SetterCallback(Local<Name> property, Local<Value> value,
set_was_called_counter++;
}
+void InterceptingSetterCallback(
+ Local<Name> property, Local<Value> value,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ info.GetReturnValue().Set(value);
+}
+
} // namespace
// Check that get callback is called in defineProperty with accessor descriptor.
@@ -517,8 +525,8 @@ THREADED_TEST(DefinerCallbackAccessorInterceptor) {
v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(get_was_called, true);
- CHECK_EQ(set_was_called, false);
+ CHECK(get_was_called);
+ CHECK(!set_was_called);
}
// Check that set callback is called for function declarations.
@@ -544,7 +552,7 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) {
.ToLocalChecked()
->Int32Value(ctx)
.FromJust());
- CHECK_EQ(set_was_called_counter, 1);
+ CHECK_EQ(1, set_was_called_counter);
// Redeclare function.
code = v8_str("function x() {return 43;}; x();");
@@ -554,7 +562,7 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) {
.ToLocalChecked()
->Int32Value(ctx)
.FromJust());
- CHECK_EQ(set_was_called_counter, 2);
+ CHECK_EQ(2, set_was_called_counter);
// Redefine function.
code = v8_str("x = function() {return 44;}; x();");
@@ -564,7 +572,99 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptor) {
.ToLocalChecked()
->Int32Value(ctx)
.FromJust());
- CHECK_EQ(set_was_called_counter, 3);
+ CHECK_EQ(3, set_was_called_counter);
+}
+
+namespace {
+int descriptor_was_called;
+
+void PropertyDescriptorCallback(
+ Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
+ // Intercept the callback by setting a different descriptor.
+ descriptor_was_called++;
+ const char* code =
+ "var desc = {value: 5};"
+ "desc;";
+ Local<Value> descriptor = v8_compile(code)
+ ->Run(info.GetIsolate()->GetCurrentContext())
+ .ToLocalChecked();
+ info.GetReturnValue().Set(descriptor);
+}
+} // namespace
+
+// Check that the descriptor callback is called on the global object.
+THREADED_TEST(DescriptorCallbackOnGlobalObject) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+
+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
+ object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr));
+ v8::Local<v8::Context> ctx =
+ v8::Context::New(CcTest::isolate(), nullptr, object_template);
+
+ descriptor_was_called = 0;
+
+ // Declare function.
+ v8::Local<v8::String> code = v8_str(
+ "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); "
+ "desc.value;");
+ CHECK_EQ(5, v8::Script::Compile(ctx, code)
+ .ToLocalChecked()
+ ->Run(ctx)
+ .ToLocalChecked()
+ ->Int32Value(ctx)
+ .FromJust());
+ CHECK_EQ(1, descriptor_was_called);
+}
+
+namespace {
+void QueryCallbackSetDontDelete(
+ Local<Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) {
+ info.GetReturnValue().Set(v8::PropertyAttribute::DontDelete);
+}
+
+} // namespace
+
+// Regression for a Node.js test that fails in debug mode.
+THREADED_TEST(InterceptorFunctionRedeclareWithQueryCallback) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+
+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
+ object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, nullptr, QueryCallbackSetDontDelete));
+ v8::Local<v8::Context> ctx =
+ v8::Context::New(CcTest::isolate(), nullptr, object_template);
+
+ // Declare and redeclare function.
+ v8::Local<v8::String> code = v8_str(
+ "function x() {return 42;};"
+ "function x() {return 43;};");
+ v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).ToLocalChecked();
+}
+
+// Regression test for chromium bug 656648.
+// Do not crash on non-masking, intercepting setter callbacks.
+THREADED_TEST(NonMaskingInterceptor) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::Local<v8::FunctionTemplate> templ =
+ v8::FunctionTemplate::New(CcTest::isolate());
+
+ v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
+ object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
+ nullptr, InterceptingSetterCallback, nullptr, nullptr, nullptr,
+ Local<Value>(), v8::PropertyHandlerFlags::kNonMasking));
+ v8::Local<v8::Context> ctx =
+ v8::Context::New(CcTest::isolate(), nullptr, object_template);
+
+ v8::Local<v8::String> code = v8_str("function x() {return 43;};");
+ v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).ToLocalChecked();
}
// Check that function re-declarations throw if they are read-only.
@@ -595,7 +695,7 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {
->Int32Value(ctx)
.FromJust());
- CHECK_EQ(set_was_called, true);
+ CHECK(set_was_called);
v8::TryCatch try_catch(CcTest::isolate());
set_was_called = false;
@@ -605,51 +705,7 @@ THREADED_TEST(SetterCallbackFunctionDeclarationInterceptorThrow) {
CHECK(v8::Script::Compile(ctx, code).ToLocalChecked()->Run(ctx).IsEmpty());
CHECK(try_catch.HasCaught());
- CHECK_EQ(set_was_called, false);
-}
-namespace {
-int descriptor_was_called;
-
-void PropertyDescriptorCallback(
- Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
- // Intercept the callback by setting a different descriptor.
- descriptor_was_called++;
- const char* code =
- "var desc = {value: 5};"
- "desc;";
- Local<Value> descriptor = v8_compile(code)
- ->Run(info.GetIsolate()->GetCurrentContext())
- .ToLocalChecked();
- info.GetReturnValue().Set(descriptor);
-}
-} // namespace
-
-// Check that the descriptor callback is called on the global object.
-THREADED_TEST(DescriptorCallbackOnGlobalObject) {
- v8::HandleScope scope(CcTest::isolate());
- LocalContext env;
- v8::Local<v8::FunctionTemplate> templ =
- v8::FunctionTemplate::New(CcTest::isolate());
-
- v8::Local<ObjectTemplate> object_template = templ->InstanceTemplate();
- object_template->SetHandler(v8::NamedPropertyHandlerConfiguration(
- nullptr, nullptr, PropertyDescriptorCallback, nullptr, nullptr, nullptr));
- v8::Local<v8::Context> ctx =
- v8::Context::New(CcTest::isolate(), nullptr, object_template);
-
- descriptor_was_called = 0;
-
- // Declare function.
- v8::Local<v8::String> code = v8_str(
- "var x = 42; var desc = Object.getOwnPropertyDescriptor(this, 'x'); "
- "desc.value;");
- CHECK_EQ(5, v8::Script::Compile(ctx, code)
- .ToLocalChecked()
- ->Run(ctx)
- .ToLocalChecked()
- ->Int32Value(ctx)
- .FromJust());
- CHECK_EQ(1, descriptor_was_called);
+ CHECK(!set_was_called);
}
@@ -661,14 +717,14 @@ bool define_was_called_in_order = false;
void GetterCallbackOrder(Local<Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
get_was_called_in_order = true;
- CHECK_EQ(define_was_called_in_order, true);
+ CHECK(define_was_called_in_order);
info.GetReturnValue().Set(property);
}
void DefinerCallbackOrder(Local<Name> property,
const v8::PropertyDescriptor& desc,
const v8::PropertyCallbackInfo<v8::Value>& info) {
- CHECK_EQ(get_was_called_in_order, false); // Define called before get.
+ CHECK(!get_was_called_in_order); // Define called before get.
define_was_called_in_order = true;
}
@@ -689,14 +745,14 @@ THREADED_TEST(DefinerCallbackGetAndDefine) {
.ToLocalChecked())
.FromJust();
- CHECK_EQ(get_was_called_in_order, false);
- CHECK_EQ(define_was_called_in_order, false);
+ CHECK(!get_was_called_in_order);
+ CHECK(!define_was_called_in_order);
v8_compile("Object.defineProperty(obj, 'x', {set: function() {return 17;}});")
->Run(env.local())
.ToLocalChecked();
- CHECK_EQ(get_was_called_in_order, true);
- CHECK_EQ(define_was_called_in_order, true);
+ CHECK(get_was_called_in_order);
+ CHECK(define_was_called_in_order);
}
namespace { // namespace for InObjectLiteralDefinitionWithInterceptor
@@ -777,15 +833,15 @@ THREADED_TEST(InterceptorHasOwnProperty) {
v8::Local<Value> value = CompileRun(
"var o = new constructor();"
"o.hasOwnProperty('ostehaps');");
- CHECK_EQ(false, value->BooleanValue(context.local()).FromJust());
+ CHECK(!value->BooleanValue(context.local()).FromJust());
value = CompileRun(
"o.ostehaps = 42;"
"o.hasOwnProperty('ostehaps');");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
value = CompileRun(
"var p = new constructor();"
"p.hasOwnProperty('ostehaps');");
- CHECK_EQ(false, value->BooleanValue(context.local()).FromJust());
+ CHECK(!value->BooleanValue(context.local()).FromJust());
}
@@ -819,7 +875,7 @@ THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
"var o = new constructor();"
"o.__proto__ = new String(x);"
"o.hasOwnProperty('ostehaps');");
- CHECK_EQ(false, value->BooleanValue(context.local()).FromJust());
+ CHECK(!value->BooleanValue(context.local()).FromJust());
}
@@ -1295,7 +1351,7 @@ THREADED_TEST(InterceptorLoadGlobalICGlobalWithInterceptor) {
" f();"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
value = CompileRun(
"var f = function() { "
@@ -1310,7 +1366,7 @@ THREADED_TEST(InterceptorLoadGlobalICGlobalWithInterceptor) {
" f();"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
value = CompileRun(
"var f = function() { "
@@ -1325,7 +1381,7 @@ THREADED_TEST(InterceptorLoadGlobalICGlobalWithInterceptor) {
" f();"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
}
static void InterceptorLoadICGetter0(
@@ -1492,9 +1548,9 @@ THREADED_TEST(NamedPropertyHandlerGetter) {
->NewInstance(env.local())
.ToLocalChecked())
.FromJust();
- CHECK_EQ(echo_named_call_count, 0);
+ CHECK_EQ(0, echo_named_call_count);
v8_compile("obj.x")->Run(env.local()).ToLocalChecked();
- CHECK_EQ(echo_named_call_count, 1);
+ CHECK_EQ(1, echo_named_call_count);
const char* code = "var str = 'oddle'; obj[str] + obj.poddle;";
v8::Local<Value> str = CompileRun(code);
String::Utf8Value value(str);
@@ -2044,11 +2100,10 @@ THREADED_TEST(IndexedPropertyHandlerGetter) {
.ToLocalChecked())
.FromJust();
Local<Script> script = v8_compile("obj[900]");
- CHECK_EQ(script->Run(env.local())
- .ToLocalChecked()
- ->Int32Value(env.local())
- .FromJust(),
- 900);
+ CHECK_EQ(900, script->Run(env.local())
+ .ToLocalChecked()
+ ->Int32Value(env.local())
+ .FromJust());
}
@@ -2674,7 +2729,7 @@ THREADED_TEST(NamedInterceptorMapTransitionRead) {
CompileRun("var o = new F(); o.x = 23;");
// Create an instance of F and invoke the getter. The result should be 23.
Local<Value> result = CompileRun("o = new F(); o.x");
- CHECK_EQ(result->Int32Value(context.local()).FromJust(), 23);
+ CHECK_EQ(23, result->Int32Value(context.local()).FromJust());
}
@@ -3978,7 +4033,7 @@ THREADED_TEST(InterceptorICReferenceErrors) {
" return false;"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
interceptor_call_count = 0;
value = CompileRun(
"function g() {"
@@ -3988,7 +4043,7 @@ THREADED_TEST(InterceptorICReferenceErrors) {
" return false;"
"};"
"g();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
}
@@ -4034,7 +4089,7 @@ THREADED_TEST(InterceptorICGetterExceptions) {
" return false;"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
interceptor_ic_exception_get_count = 0;
value = CompileRun(
"function f() {"
@@ -4044,7 +4099,7 @@ THREADED_TEST(InterceptorICGetterExceptions) {
" return false;"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
}
@@ -4078,7 +4133,7 @@ THREADED_TEST(InterceptorICSetterExceptions) {
" return false;"
"};"
"f();");
- CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
+ CHECK(value->BooleanValue(context.local()).FromJust());
}
@@ -4137,6 +4192,7 @@ THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
THREADED_TEST(Regress256330) {
+ if (!i::FLAG_crankshaft) return;
i::FLAG_allow_natives_syntax = true;
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
@@ -4152,7 +4208,10 @@ THREADED_TEST(Regress256330) {
"f(o); f(o); f(o);"
"%OptimizeFunctionOnNextCall(f);"
"f(o);");
- ExpectBoolean("%GetOptimizationStatus(f) != 2", true);
+ int status = v8_run_int32value(v8_compile("%GetOptimizationStatus(f)"));
+ int mask = static_cast<int>(i::OptimizationStatus::kIsFunction) |
+ static_cast<int>(i::OptimizationStatus::kOptimized);
+ CHECK_EQ(mask, status & mask);
}