2012-04-13 09:38:00 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2009-11-04 09:19:30 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2009-11-04 09:19:30 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/api.h"
|
|
|
|
#include "src/frames-inl.h"
|
|
|
|
#include "src/string-stream.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
2009-11-04 09:19:30 +00:00
|
|
|
|
|
|
|
using ::v8::ObjectTemplate;
|
|
|
|
using ::v8::Value;
|
|
|
|
using ::v8::Context;
|
|
|
|
using ::v8::Local;
|
2014-11-27 10:21:32 +00:00
|
|
|
using ::v8::Name;
|
2009-11-04 09:19:30 +00:00
|
|
|
using ::v8::String;
|
|
|
|
using ::v8::Script;
|
|
|
|
using ::v8::Function;
|
|
|
|
using ::v8::Extension;
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void handle_property(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8_num(900));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
static void handle_property_2(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
info.GetReturnValue().Set(v8_num(902));
|
|
|
|
}
|
|
|
|
|
2009-11-04 09:19:30 +00:00
|
|
|
|
2013-08-26 11:59:14 +00:00
|
|
|
static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
CHECK_EQ(0, info.Length());
|
|
|
|
info.GetReturnValue().Set(v8_num(907));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 09:19:30 +00:00
|
|
|
THREADED_TEST(PropertyHandler) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property);
|
2013-08-26 11:59:14 +00:00
|
|
|
Local<v8::FunctionTemplate> getter_templ =
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::FunctionTemplate::New(isolate, handle_property);
|
2013-08-26 11:59:14 +00:00
|
|
|
getter_templ->SetLength(0);
|
|
|
|
fun_templ->
|
|
|
|
InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ);
|
2013-09-04 07:45:36 +00:00
|
|
|
fun_templ->InstanceTemplate()->
|
|
|
|
SetNativeDataProperty(v8_str("instance_foo"), handle_property);
|
|
|
|
fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2);
|
2015-10-28 12:31:41 +00:00
|
|
|
Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
|
|
|
|
CHECK(env->Global()->Set(env.local(), v8_str("Fun"), fun).FromJust());
|
2013-09-04 07:45:36 +00:00
|
|
|
Local<Script> getter;
|
|
|
|
Local<Script> setter;
|
|
|
|
// check function instance accessors
|
|
|
|
getter = v8_compile("var obj = new Fun(); obj.instance_foo;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(900, getter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2013-09-04 07:45:36 +00:00
|
|
|
setter = v8_compile("obj.instance_foo = 901;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(901, setter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2013-08-26 11:59:14 +00:00
|
|
|
getter = v8_compile("obj.bar;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(907, getter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2013-08-26 11:59:14 +00:00
|
|
|
setter = v8_compile("obj.bar = 908;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(908, setter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2013-09-04 07:45:36 +00:00
|
|
|
// check function static accessors
|
|
|
|
getter = v8_compile("Fun.object_foo;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(902, getter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2013-09-04 07:45:36 +00:00
|
|
|
setter = v8_compile("Fun.object_foo = 903;");
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(903, setter->Run(env.local())
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(env.local())
|
|
|
|
.FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void GetIntValue(Local<String> property,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
int* value =
|
2015-10-28 12:31:41 +00:00
|
|
|
static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8_num(*value));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SetIntValue(Local<String> property,
|
|
|
|
Local<Value> value,
|
2013-06-20 08:12:59 +00:00
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
int* field =
|
2015-10-28 12:31:41 +00:00
|
|
|
static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
|
|
|
|
*field = value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust();
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int foo, bar, baz;
|
|
|
|
|
|
|
|
THREADED_TEST(GlobalVariableAccess) {
|
|
|
|
foo = 0;
|
|
|
|
bar = -4;
|
|
|
|
baz = 10;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
|
2013-11-12 11:44:58 +00:00
|
|
|
templ->InstanceTemplate()->SetAccessor(
|
|
|
|
v8_str("foo"), GetIntValue, SetIntValue,
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &foo));
|
2013-11-12 11:44:58 +00:00
|
|
|
templ->InstanceTemplate()->SetAccessor(
|
|
|
|
v8_str("bar"), GetIntValue, SetIntValue,
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &bar));
|
2013-11-12 11:44:58 +00:00
|
|
|
templ->InstanceTemplate()->SetAccessor(
|
|
|
|
v8_str("baz"), GetIntValue, SetIntValue,
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::External::New(isolate, &baz));
|
2009-11-04 09:19:30 +00:00
|
|
|
LocalContext env(0, templ->InstanceTemplate());
|
2015-10-28 12:31:41 +00:00
|
|
|
v8_compile("foo = (++bar) + baz")->Run(env.local()).ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK_EQ(bar, -3);
|
|
|
|
CHECK_EQ(foo, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 11:59:14 +00:00
|
|
|
static int x_register[2] = {0, 0};
|
2015-10-28 12:31:41 +00:00
|
|
|
static v8::Local<v8::Object> x_receiver;
|
|
|
|
static v8::Local<v8::Object> x_holder;
|
2009-11-04 09:19:30 +00:00
|
|
|
|
2013-08-26 11:59:14 +00:00
|
|
|
template<class Info>
|
|
|
|
static void XGetter(const Info& info, int offset) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2012-04-13 09:38:00 +00:00
|
|
|
CHECK_EQ(isolate, info.GetIsolate());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(
|
|
|
|
x_receiver->Equals(isolate->GetCurrentContext(), info.This()).FromJust());
|
2013-08-26 11:59:14 +00:00
|
|
|
info.GetReturnValue().Set(v8_num(x_register[offset]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void XGetter(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
|
|
|
|
.FromJust());
|
2013-08-26 11:59:14 +00:00
|
|
|
XGetter(info, 0);
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 11:59:14 +00:00
|
|
|
static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(
|
|
|
|
x_receiver->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
|
|
|
|
.FromJust());
|
2013-08-26 11:59:14 +00:00
|
|
|
XGetter(info, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Info>
|
|
|
|
static void XSetter(Local<Value> value, const Info& info, int offset) {
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2012-04-13 09:38:00 +00:00
|
|
|
CHECK_EQ(isolate, info.GetIsolate());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.This())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
|
|
|
|
.FromJust());
|
|
|
|
x_register[offset] =
|
|
|
|
value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust();
|
2014-02-14 14:13:06 +00:00
|
|
|
info.GetReturnValue().Set(v8_num(-1));
|
2013-08-26 11:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void XSetter(Local<String> name,
|
|
|
|
Local<Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
XSetter(value, info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
CHECK_EQ(1, info.Length());
|
|
|
|
XSetter(info[0], info, 1);
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(AccessorIC) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2013-08-26 11:59:14 +00:00
|
|
|
obj->SetAccessor(v8_str("x0"), XGetter, XSetter);
|
|
|
|
obj->SetAccessorProperty(v8_str("x1"),
|
2013-12-18 10:31:42 +00:00
|
|
|
v8::FunctionTemplate::New(isolate, XGetter),
|
|
|
|
v8::FunctionTemplate::New(isolate, XSetter));
|
2015-10-28 12:31:41 +00:00
|
|
|
x_holder = obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context.local(), v8_str("holder"), x_holder)
|
|
|
|
.FromJust());
|
2014-01-03 14:31:17 +00:00
|
|
|
x_receiver = v8::Object::New(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context.local(), v8_str("obj"), x_receiver)
|
|
|
|
.FromJust());
|
|
|
|
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(
|
|
|
|
CompileRun("obj.__proto__ = holder;"
|
|
|
|
"var result = [];"
|
|
|
|
"var key_0 = 'x0';"
|
|
|
|
"var key_1 = 'x1';"
|
|
|
|
"for (var j = 0; j < 10; j++) {"
|
|
|
|
" var i = 4*j;"
|
|
|
|
" result.push(holder.x0 = i);"
|
|
|
|
" result.push(obj.x0);"
|
|
|
|
" result.push(holder.x1 = i + 1);"
|
|
|
|
" result.push(obj.x1);"
|
|
|
|
" result.push(holder[key_0] = i + 2);"
|
|
|
|
" result.push(obj[key_0]);"
|
|
|
|
" result.push(holder[key_1] = i + 3);"
|
|
|
|
" result.push(obj[key_1]);"
|
|
|
|
"}"
|
|
|
|
"result"));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(80u, array->Length());
|
2014-02-14 14:13:06 +00:00
|
|
|
for (int i = 0; i < 80; i++) {
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<Value> entry =
|
|
|
|
array->Get(context.local(), v8::Integer::New(isolate, i))
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK(v8::Integer::New(isolate, i / 2)
|
|
|
|
->Equals(context.local(), entry)
|
|
|
|
.FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <int C>
|
2013-06-20 08:12:59 +00:00
|
|
|
static void HandleAllocatingGetter(
|
|
|
|
Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2015-10-28 12:31:41 +00:00
|
|
|
for (int i = 0; i < C; i++) {
|
|
|
|
v8::String::NewFromUtf8(info.GetIsolate(), "foo",
|
|
|
|
v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked();
|
|
|
|
}
|
|
|
|
info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo",
|
|
|
|
v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(HandleScopePop) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>);
|
|
|
|
obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::Object> inst =
|
|
|
|
obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(
|
|
|
|
context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
|
2014-01-08 06:53:31 +00:00
|
|
|
int count_before =
|
|
|
|
i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate));
|
2009-11-04 09:19:30 +00:00
|
|
|
{
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 1000; i++) {"
|
|
|
|
" obj.one;"
|
|
|
|
" obj.many;"
|
|
|
|
"}");
|
|
|
|
}
|
2014-01-08 06:53:31 +00:00
|
|
|
int count_after =
|
|
|
|
i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate));
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK_EQ(count_before, count_after);
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void CheckAccessorArgsCorrect(
|
|
|
|
Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2013-09-19 08:54:58 +00:00
|
|
|
CHECK(info.GetIsolate() == CcTest::isolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(info.Data()
|
|
|
|
->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
|
|
|
|
.FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2013-09-19 08:54:58 +00:00
|
|
|
CHECK(info.GetIsolate() == CcTest::isolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(info.Data()
|
|
|
|
->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
|
|
|
|
.FromJust());
|
2015-04-23 08:37:24 +00:00
|
|
|
CcTest::heap()->CollectAllGarbage();
|
2013-09-19 08:54:58 +00:00
|
|
|
CHECK(info.GetIsolate() == CcTest::isolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(info.Data()
|
|
|
|
->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
|
|
|
|
.FromJust());
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(17);
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-11-04 09:19:30 +00:00
|
|
|
THREADED_TEST(DirectCall) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
|
|
|
obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL,
|
|
|
|
v8_str("data"));
|
|
|
|
v8::Local<v8::Object> inst =
|
|
|
|
obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(
|
|
|
|
context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
|
|
|
|
Local<Script> scr =
|
|
|
|
v8::Script::Compile(context.local(), v8_str("obj.xxx")).ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2015-10-28 12:31:41 +00:00
|
|
|
Local<Value> result = scr->Run(context.local()).ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(!result.IsEmpty());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(17, result->Int32Value(context.local()).FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void EmptyGetter(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
CheckAccessorArgsCorrect(name, info);
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
CheckAccessorArgsCorrect(name, info);
|
2015-10-28 12:31:41 +00:00
|
|
|
info.GetReturnValue().Set(v8::Local<v8::Value>());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2009-11-04 09:19:30 +00:00
|
|
|
THREADED_TEST(EmptyResult) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
2013-09-26 08:21:48 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
|
|
|
obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data"));
|
|
|
|
v8::Local<v8::Object> inst =
|
|
|
|
obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(
|
|
|
|
context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
|
2013-11-22 12:43:17 +00:00
|
|
|
Local<Script> scr =
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Script::Compile(context.local(), v8_str("obj.xxx")).ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2015-10-28 12:31:41 +00:00
|
|
|
Local<Value> result = scr->Run(context.local()).ToLocalChecked();
|
2013-09-26 08:21:48 +00:00
|
|
|
CHECK(result == v8::Undefined(isolate));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(NoReuseRegress) {
|
|
|
|
// Check that the IC generated for the one test doesn't get reused
|
|
|
|
// for the other.
|
2013-09-26 08:21:48 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
{
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
|
|
|
obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data"));
|
2009-11-04 09:19:30 +00:00
|
|
|
LocalContext context;
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::Object> inst =
|
|
|
|
obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context.local(), v8_str("obj"), inst)
|
|
|
|
.FromJust());
|
|
|
|
Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx"))
|
|
|
|
.ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2015-10-28 12:31:41 +00:00
|
|
|
Local<Value> result = scr->Run(context.local()).ToLocalChecked();
|
2013-09-26 08:21:48 +00:00
|
|
|
CHECK(result == v8::Undefined(isolate));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
|
|
|
obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL,
|
|
|
|
v8_str("data"));
|
2009-11-04 09:19:30 +00:00
|
|
|
LocalContext context;
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::Object> inst =
|
|
|
|
obj->NewInstance(context.local()).ToLocalChecked();
|
|
|
|
CHECK(context->Global()
|
|
|
|
->Set(context.local(), v8_str("obj"), inst)
|
|
|
|
.FromJust());
|
|
|
|
Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx"))
|
|
|
|
.ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
2015-10-28 12:31:41 +00:00
|
|
|
Local<Value> result = scr->Run(context.local()).ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(!result.IsEmpty());
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK_EQ(17, result->Int32Value(context.local()).FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void ThrowingGetAccessor(
|
|
|
|
Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2013-09-26 07:37:59 +00:00
|
|
|
info.GetIsolate()->ThrowException(v8_str("g"));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ThrowingSetAccessor(Local<String> name,
|
|
|
|
Local<Value> value,
|
2013-06-20 08:12:59 +00:00
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
2013-09-26 07:37:59 +00:00
|
|
|
info.GetIsolate()->ThrowException(value);
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(Regress1054726) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
obj->SetAccessor(v8_str("x"),
|
|
|
|
ThrowingGetAccessor,
|
|
|
|
ThrowingSetAccessor,
|
|
|
|
Local<Value>());
|
|
|
|
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
|
|
|
|
// Use the throwing property setter/getter in a loop to force
|
|
|
|
// the accessor ICs to be initialized.
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<Value> result;
|
|
|
|
result = Script::Compile(env.local(),
|
|
|
|
v8_str("var result = '';"
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" try { obj.x; } catch (e) { result += e; }"
|
|
|
|
"}; result"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK(v8_str("ggggg")->Equals(env.local(), result).FromJust());
|
|
|
|
|
|
|
|
result =
|
|
|
|
Script::Compile(env.local(),
|
|
|
|
v8_str("var result = '';"
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" try { obj.x = i; } catch (e) { result += e; }"
|
|
|
|
"}; result"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK(v8_str("01234")->Equals(env.local(), result).FromJust());
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void AllocGetter(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2013-11-28 08:21:26 +00:00
|
|
|
info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(Gc) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
obj->SetAccessor(v8_str("xxx"), AllocGetter);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
Script::Compile(env.local(), v8_str("var last = [];"
|
|
|
|
"for (var i = 0; i < 2048; i++) {"
|
|
|
|
" var result = obj.xxx;"
|
|
|
|
" result[0] = last;"
|
|
|
|
" last = result;"
|
|
|
|
"}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void StackCheck(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2013-02-15 09:27:10 +00:00
|
|
|
i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate()));
|
2009-11-04 09:19:30 +00:00
|
|
|
for (int i = 0; !iter.done(); i++) {
|
|
|
|
i::StackFrame* frame = iter.frame();
|
|
|
|
CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT));
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
i::Code* code = frame->LookupCode();
|
2011-03-18 20:35:07 +00:00
|
|
|
CHECK(code->IsCode());
|
2009-11-04 09:19:30 +00:00
|
|
|
i::Address pc = frame->pc();
|
|
|
|
CHECK(code->contains(pc));
|
|
|
|
iter.Advance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(StackIteration) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2014-01-08 06:53:31 +00:00
|
|
|
i::StringStream::ClearMentionedObjectCache(
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate));
|
2009-11-04 09:19:30 +00:00
|
|
|
obj->SetAccessor(v8_str("xxx"), StackCheck);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
Script::Compile(env.local(), v8_str("function foo() {"
|
|
|
|
" return obj.xxx;"
|
|
|
|
"}"
|
|
|
|
"for (var i = 0; i < 100; i++) {"
|
|
|
|
" foo();"
|
|
|
|
"}"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
2009-11-06 11:35:47 +00:00
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void AllocateHandles(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-06 11:35:47 +00:00
|
|
|
for (int i = 0; i < i::kHandleBlockSize + 1; i++) {
|
2013-09-27 07:04:02 +00:00
|
|
|
v8::Local<v8::Value>::New(info.GetIsolate(), name);
|
2009-11-06 11:35:47 +00:00
|
|
|
}
|
2014-01-03 14:31:17 +00:00
|
|
|
info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100));
|
2009-11-06 11:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(HandleScopeSegment) {
|
|
|
|
// Check that we can return values past popping of handle scope
|
|
|
|
// segments.
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2009-11-06 11:35:47 +00:00
|
|
|
obj->SetAccessor(v8_str("xxx"), AllocateHandles);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
v8::Local<v8::Value> result =
|
|
|
|
Script::Compile(env.local(), v8_str("var result;"
|
|
|
|
"for (var i = 0; i < 4; i++)"
|
|
|
|
" result = obj.xxx;"
|
|
|
|
"result;"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
|
|
|
CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
|
2009-11-06 11:35:47 +00:00
|
|
|
}
|
2012-11-23 12:32:24 +00:00
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), 1);
|
|
|
|
CHECK(array->Set(info.GetIsolate()->GetCurrentContext(), 0, v8_str("regress"))
|
|
|
|
.FromJust());
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(array);
|
2012-11-23 12:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-27 10:21:32 +00:00
|
|
|
void JSONStringifyGetter(Local<Name> name,
|
2013-06-20 08:12:59 +00:00
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
info.GetReturnValue().Set(v8_str("crbug-161028"));
|
2012-11-23 12:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(JSONStringifyNamedInterceptorObject) {
|
|
|
|
LocalContext env;
|
2014-01-08 06:53:31 +00:00
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2012-11-23 12:32:24 +00:00
|
|
|
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2014-11-27 10:21:32 +00:00
|
|
|
obj->SetHandler(v8::NamedPropertyHandlerConfiguration(
|
|
|
|
JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator));
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
v8::Local<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
|
|
|
|
CHECK(CompileRun("JSON.stringify(obj)")
|
|
|
|
->Equals(env.local(), expected)
|
|
|
|
.FromJust());
|
2012-11-23 12:32:24 +00:00
|
|
|
}
|
2013-09-09 15:03:03 +00:00
|
|
|
|
|
|
|
|
2014-01-27 08:12:59 +00:00
|
|
|
static v8::Local<v8::Context> expected_current_context;
|
|
|
|
|
|
|
|
|
|
|
|
static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-17 12:23:12 +00:00
|
|
|
THREADED_TEST(AccessorPropertyCrossContext) {
|
2013-09-09 15:03:03 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::Function> fun =
|
|
|
|
v8::Function::New(env.local(), check_contexts).ToLocalChecked();
|
2013-09-09 15:03:03 +00:00
|
|
|
LocalContext switch_context;
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(switch_context->Global()
|
|
|
|
->Set(switch_context.local(), v8_str("fun"), fun)
|
|
|
|
.FromJust());
|
2015-05-28 12:49:31 +00:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2014-01-27 08:12:59 +00:00
|
|
|
expected_current_context = env.local();
|
2013-09-09 15:03:03 +00:00
|
|
|
CompileRun(
|
|
|
|
"var o = Object.create(null, { n: { get:fun } });"
|
|
|
|
"for (var i = 0; i < 10; i++) o.n;");
|
|
|
|
CHECK(!try_catch.HasCaught());
|
|
|
|
}
|
2014-02-06 10:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(GlobalObjectAccessor) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
CompileRun(
|
|
|
|
"var set_value = 1;"
|
|
|
|
"Object.defineProperty(this.__proto__, 'x', {"
|
|
|
|
" get : function() { return this; },"
|
|
|
|
" set : function() { set_value = this; }"
|
|
|
|
"});"
|
|
|
|
"function getter() { return x; }"
|
|
|
|
"function setter() { x = 1; }"
|
|
|
|
"for (var i = 0; i < 4; i++) { getter(); setter(); }");
|
|
|
|
CHECK(v8::Utils::OpenHandle(*CompileRun("getter()"))->IsJSGlobalProxy());
|
|
|
|
CHECK(v8::Utils::OpenHandle(*CompileRun("set_value"))->IsJSGlobalProxy());
|
|
|
|
}
|
2014-12-10 10:18:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void EmptyGetter(Local<Name> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void OneProperty(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
ApiTestFuzzer::Fuzz();
|
|
|
|
info.GetReturnValue().Set(v8_num(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(Regress433458) {
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-10-28 12:31:41 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
|
2014-12-10 10:18:00 +00:00
|
|
|
obj->SetHandler(v8::NamedPropertyHandlerConfiguration(EmptyGetter));
|
|
|
|
obj->SetNativeDataProperty(v8_str("prop"), OneProperty);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
2014-12-10 10:18:00 +00:00
|
|
|
CompileRun(
|
|
|
|
"Object.defineProperty(obj, 'prop', { writable: false });"
|
|
|
|
"Object.defineProperty(obj, 'prop', { writable: true });");
|
|
|
|
}
|
2015-03-26 15:21:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
static bool security_check_value = false;
|
|
|
|
|
|
|
|
|
2015-10-23 08:13:24 +00:00
|
|
|
static bool SecurityTestCallback(Local<v8::Context> accessing_context,
|
|
|
|
Local<v8::Object> accessed_object) {
|
2015-03-26 15:21:54 +00:00
|
|
|
return security_check_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(PrototypeGetterAccessCheck) {
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
LocalContext env;
|
|
|
|
v8::Isolate* isolate = env->GetIsolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
auto fun_templ = v8::FunctionTemplate::New(isolate);
|
|
|
|
auto getter_templ = v8::FunctionTemplate::New(isolate, handle_property);
|
|
|
|
getter_templ->SetAcceptAnyReceiver(false);
|
|
|
|
fun_templ->InstanceTemplate()->SetAccessorProperty(v8_str("foo"),
|
|
|
|
getter_templ);
|
|
|
|
auto obj_templ = v8::ObjectTemplate::New(isolate);
|
2015-10-23 08:13:24 +00:00
|
|
|
obj_templ->SetAccessCheckCallback(SecurityTestCallback);
|
2015-10-28 12:31:41 +00:00
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("Fun"),
|
|
|
|
fun_templ->GetFunction(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj"),
|
|
|
|
obj_templ->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
|
|
|
CHECK(env->Global()
|
|
|
|
->Set(env.local(), v8_str("obj2"),
|
|
|
|
obj_templ->NewInstance(env.local()).ToLocalChecked())
|
|
|
|
.FromJust());
|
2015-03-26 15:21:54 +00:00
|
|
|
|
|
|
|
security_check_value = true;
|
|
|
|
CompileRun("var proto = new Fun();");
|
|
|
|
CompileRun("obj.__proto__ = proto;");
|
|
|
|
ExpectInt32("proto.foo", 907);
|
|
|
|
|
|
|
|
// Test direct.
|
|
|
|
security_check_value = true;
|
|
|
|
ExpectInt32("obj.foo", 907);
|
|
|
|
security_check_value = false;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
CompileRun("obj.foo");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test through call.
|
|
|
|
security_check_value = true;
|
|
|
|
ExpectInt32("proto.__lookupGetter__('foo').call(obj)", 907);
|
|
|
|
security_check_value = false;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
CompileRun("proto.__lookupGetter__('foo').call(obj)");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test ics.
|
|
|
|
CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var x;"
|
|
|
|
" for (var i = 0; i < 4; i++) {"
|
|
|
|
" x = obj.foo;"
|
|
|
|
" }"
|
|
|
|
" return x;"
|
|
|
|
"}");
|
|
|
|
|
|
|
|
security_check_value = true;
|
|
|
|
ExpectInt32("f()", 907);
|
|
|
|
security_check_value = false;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
CompileRun("f();");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test crankshaft.
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(f);");
|
|
|
|
|
|
|
|
security_check_value = true;
|
|
|
|
ExpectInt32("f()", 907);
|
|
|
|
security_check_value = false;
|
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
CompileRun("f();");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
}
|
|
|
|
}
|