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>
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "api.h"
|
|
|
|
#include "cctest.h"
|
|
|
|
#include "frames-inl.h"
|
|
|
|
#include "string-stream.h"
|
|
|
|
|
|
|
|
using ::v8::ObjectTemplate;
|
|
|
|
using ::v8::Value;
|
|
|
|
using ::v8::Context;
|
|
|
|
using ::v8::Local;
|
|
|
|
using ::v8::String;
|
|
|
|
using ::v8::Script;
|
|
|
|
using ::v8::Function;
|
|
|
|
using ::v8::AccessorInfo;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(PropertyHandler) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
|
|
|
|
fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property);
|
|
|
|
Local<Function> fun = fun_templ->GetFunction();
|
|
|
|
env->Global()->Set(v8_str("Fun"), fun);
|
|
|
|
Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;");
|
|
|
|
CHECK_EQ(900, getter->Run()->Int32Value());
|
|
|
|
Local<Script> setter = v8_compile("obj.foo = 901;");
|
|
|
|
CHECK_EQ(901, setter->Run()->Int32Value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 =
|
|
|
|
static_cast<int*>(v8::Handle<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 =
|
|
|
|
static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
|
|
|
|
*field = value->Int32Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
int foo, bar, baz;
|
|
|
|
|
|
|
|
THREADED_TEST(GlobalVariableAccess) {
|
|
|
|
foo = 0;
|
|
|
|
bar = -4;
|
|
|
|
baz = 10;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
|
|
|
|
templ->InstanceTemplate()->SetAccessor(v8_str("foo"),
|
|
|
|
GetIntValue,
|
|
|
|
SetIntValue,
|
|
|
|
v8::External::New(&foo));
|
|
|
|
templ->InstanceTemplate()->SetAccessor(v8_str("bar"),
|
|
|
|
GetIntValue,
|
|
|
|
SetIntValue,
|
|
|
|
v8::External::New(&bar));
|
|
|
|
templ->InstanceTemplate()->SetAccessor(v8_str("baz"),
|
|
|
|
GetIntValue,
|
|
|
|
SetIntValue,
|
|
|
|
v8::External::New(&baz));
|
|
|
|
LocalContext env(0, templ->InstanceTemplate());
|
|
|
|
v8_compile("foo = (++bar) + baz")->Run();
|
|
|
|
CHECK_EQ(bar, -3);
|
|
|
|
CHECK_EQ(foo, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int x_register = 0;
|
|
|
|
static v8::Handle<v8::Object> x_receiver;
|
|
|
|
static v8::Handle<v8::Object> x_holder;
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void XGetter(Local<String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2009-11-04 09:19:30 +00:00
|
|
|
ApiTestFuzzer::Fuzz();
|
2012-04-13 09:38:00 +00:00
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
CHECK_EQ(isolate, info.GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK_EQ(x_receiver, info.This());
|
|
|
|
CHECK_EQ(x_holder, info.Holder());
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8_num(x_register));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void XSetter(Local<String> name,
|
|
|
|
Local<Value> value,
|
2013-06-20 08:12:59 +00:00
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
2012-04-13 09:38:00 +00:00
|
|
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
|
|
CHECK_EQ(isolate, info.GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK_EQ(x_holder, info.This());
|
|
|
|
CHECK_EQ(x_holder, info.Holder());
|
|
|
|
x_register = value->Int32Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(AccessorIC) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("x"), XGetter, XSetter);
|
|
|
|
x_holder = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8_str("holder"), x_holder);
|
|
|
|
x_receiver = v8::Object::New();
|
|
|
|
context->Global()->Set(v8_str("obj"), x_receiver);
|
|
|
|
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun(
|
|
|
|
"obj.__proto__ = holder;"
|
|
|
|
"var result = [];"
|
|
|
|
"for (var i = 0; i < 10; i++) {"
|
|
|
|
" holder.x = i;"
|
|
|
|
" result.push(obj.x);"
|
|
|
|
"}"
|
|
|
|
"result"));
|
|
|
|
CHECK_EQ(10, array->Length());
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
v8::Handle<Value> entry = array->Get(v8::Integer::New(i));
|
|
|
|
CHECK_EQ(v8::Integer::New(i), entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
static void AccessorProhibitsOverwritingGetter(
|
2009-11-04 09:19:30 +00:00
|
|
|
Local<String> name,
|
2013-06-20 08:12:59 +00:00
|
|
|
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(true);
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(AccessorProhibitsOverwriting) {
|
|
|
|
LocalContext context;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
Local<ObjectTemplate> templ = ObjectTemplate::New();
|
|
|
|
templ->SetAccessor(v8_str("x"),
|
|
|
|
AccessorProhibitsOverwritingGetter,
|
|
|
|
0,
|
|
|
|
v8::Handle<Value>(),
|
|
|
|
v8::PROHIBITS_OVERWRITING,
|
|
|
|
v8::ReadOnly);
|
|
|
|
Local<v8::Object> instance = templ->NewInstance();
|
|
|
|
context->Global()->Set(v8_str("obj"), instance);
|
|
|
|
Local<Value> value = CompileRun(
|
|
|
|
"obj.__defineGetter__('x', function() { return false; });"
|
|
|
|
"obj.x");
|
|
|
|
CHECK(value->BooleanValue());
|
|
|
|
value = CompileRun(
|
|
|
|
"var setter_called = false;"
|
|
|
|
"obj.__defineSetter__('x', function() { setter_called = true; });"
|
|
|
|
"obj.x = 42;"
|
|
|
|
"setter_called");
|
|
|
|
CHECK(!value->BooleanValue());
|
|
|
|
value = CompileRun(
|
|
|
|
"obj2 = {};"
|
|
|
|
"obj2.__proto__ = obj;"
|
|
|
|
"obj2.__defineGetter__('x', function() { return false; });"
|
|
|
|
"obj2.x");
|
|
|
|
CHECK(value->BooleanValue());
|
|
|
|
value = CompileRun(
|
|
|
|
"var setter_called = false;"
|
|
|
|
"obj2 = {};"
|
|
|
|
"obj2.__proto__ = obj;"
|
|
|
|
"obj2.__defineSetter__('x', function() { setter_called = true; });"
|
|
|
|
"obj2.x = 42;"
|
|
|
|
"setter_called");
|
|
|
|
CHECK(!value->BooleanValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
for (int i = 0; i < C; i++)
|
|
|
|
v8::String::New("foo");
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8::String::New("foo"));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(HandleScopePop) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>);
|
|
|
|
obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>);
|
|
|
|
v8::Handle<v8::Object> inst = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8::String::New("obj"), inst);
|
2013-02-25 14:46:09 +00:00
|
|
|
i::Isolate* isolate = i::Isolate::Current();
|
|
|
|
int count_before = i::HandleScope::NumberOfHandles(isolate);
|
2009-11-04 09:19:30 +00:00
|
|
|
{
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 1000; i++) {"
|
|
|
|
" obj.one;"
|
|
|
|
" obj.many;"
|
|
|
|
"}");
|
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
int count_after = i::HandleScope::NumberOfHandles(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) {
|
2012-04-13 09:38:00 +00:00
|
|
|
CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
|
|
|
CHECK(info.Data()->Equals(v8::String::New("data")));
|
|
|
|
ApiTestFuzzer::Fuzz();
|
2012-04-13 09:38:00 +00:00
|
|
|
CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
|
|
|
CHECK(info.Data()->Equals(v8::String::New("data")));
|
2011-09-19 18:36:47 +00:00
|
|
|
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
|
2012-04-13 09:38:00 +00:00
|
|
|
CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
|
2009-11-04 09:19:30 +00:00
|
|
|
CHECK(info.This() == info.Holder());
|
|
|
|
CHECK(info.Data()->Equals(v8::String::New("data")));
|
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;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"),
|
|
|
|
CheckAccessorArgsCorrect,
|
|
|
|
NULL,
|
|
|
|
v8::String::New("data"));
|
|
|
|
v8::Handle<v8::Object> inst = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8::String::New("obj"), inst);
|
|
|
|
Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
Local<Value> result = scr->Run();
|
|
|
|
CHECK(!result.IsEmpty());
|
|
|
|
CHECK_EQ(17, result->Int32Value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8::Handle<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;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data"));
|
|
|
|
v8::Handle<v8::Object> inst = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8::String::New("obj"), inst);
|
|
|
|
Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
Local<Value> result = scr->Run();
|
|
|
|
CHECK(result == v8::Undefined());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(NoReuseRegress) {
|
|
|
|
// Check that the IC generated for the one test doesn't get reused
|
|
|
|
// for the other.
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
2009-11-04 09:19:30 +00:00
|
|
|
{
|
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data"));
|
|
|
|
LocalContext context;
|
|
|
|
v8::Handle<v8::Object> inst = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8::String::New("obj"), inst);
|
|
|
|
Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
Local<Value> result = scr->Run();
|
|
|
|
CHECK(result == v8::Undefined());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"),
|
|
|
|
CheckAccessorArgsCorrect,
|
|
|
|
NULL,
|
|
|
|
v8::String::New("data"));
|
|
|
|
LocalContext context;
|
|
|
|
v8::Handle<v8::Object> inst = obj->NewInstance();
|
|
|
|
context->Global()->Set(v8::String::New("obj"), inst);
|
|
|
|
Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
Local<Value> result = scr->Run();
|
|
|
|
CHECK(!result.IsEmpty());
|
|
|
|
CHECK_EQ(17, result->Int32Value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-06-20 08:12:59 +00:00
|
|
|
v8::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) {
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::ThrowException(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(Regress1054726) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("x"),
|
|
|
|
ThrowingGetAccessor,
|
|
|
|
ThrowingSetAccessor,
|
|
|
|
Local<Value>());
|
|
|
|
|
|
|
|
env->Global()->Set(v8_str("obj"), obj->NewInstance());
|
|
|
|
|
|
|
|
// Use the throwing property setter/getter in a loop to force
|
|
|
|
// the accessor ICs to be initialized.
|
|
|
|
v8::Handle<Value> result;
|
|
|
|
result = Script::Compile(v8_str(
|
|
|
|
"var result = '';"
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" try { obj.x; } catch (e) { result += e; }"
|
|
|
|
"}; result"))->Run();
|
|
|
|
CHECK_EQ(v8_str("ggggg"), result);
|
|
|
|
|
|
|
|
result = Script::Compile(String::New(
|
|
|
|
"var result = '';"
|
|
|
|
"for (var i = 0; i < 5; i++) {"
|
|
|
|
" try { obj.x = i; } catch (e) { result += e; }"
|
|
|
|
"}; result"))->Run();
|
|
|
|
CHECK_EQ(v8_str("01234"), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8::Array::New(1000));
|
2009-11-04 09:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THREADED_TEST(Gc) {
|
2013-03-15 12:06:53 +00:00
|
|
|
LocalContext env;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"), AllocGetter);
|
|
|
|
env->Global()->Set(v8_str("obj"), obj->NewInstance());
|
|
|
|
Script::Compile(String::New(
|
|
|
|
"var last = [];"
|
|
|
|
"for (var i = 0; i < 2048; i++) {"
|
|
|
|
" var result = obj.xxx;"
|
|
|
|
" result[0] = last;"
|
|
|
|
" last = result;"
|
|
|
|
"}"))->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-11-04 09:19:30 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
i::StringStream::ClearMentionedObjectCache();
|
|
|
|
obj->SetAccessor(v8_str("xxx"), StackCheck);
|
|
|
|
env->Global()->Set(v8_str("obj"), obj->NewInstance());
|
|
|
|
Script::Compile(String::New(
|
|
|
|
"function foo() {"
|
|
|
|
" return obj.xxx;"
|
|
|
|
"}"
|
|
|
|
"for (var i = 0; i < 100; i++) {"
|
|
|
|
" foo();"
|
|
|
|
"}"))->Run();
|
|
|
|
}
|
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++) {
|
|
|
|
v8::Local<v8::Value>::New(name);
|
|
|
|
}
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(v8::Integer::New(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;
|
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2009-11-06 11:35:47 +00:00
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetAccessor(v8_str("xxx"), AllocateHandles);
|
|
|
|
env->Global()->Set(v8_str("obj"), obj->NewInstance());
|
|
|
|
v8::Handle<v8::Value> result = Script::Compile(String::New(
|
|
|
|
"var result;"
|
|
|
|
"for (var i = 0; i < 4; i++)"
|
|
|
|
" result = obj.xxx;"
|
|
|
|
"result;"))->Run();
|
|
|
|
CHECK_EQ(100, result->Int32Value());
|
|
|
|
}
|
2012-11-23 12:32:24 +00:00
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
|
2012-11-23 12:32:24 +00:00
|
|
|
v8::Handle<v8::Array> array = v8::Array::New(1);
|
|
|
|
array->Set(0, v8_str("regress"));
|
2013-06-20 08:12:59 +00:00
|
|
|
info.GetReturnValue().Set(array);
|
2012-11-23 12:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 08:12:59 +00:00
|
|
|
void JSONStringifyGetter(Local<String> name,
|
|
|
|
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;
|
2013-03-15 12:06:53 +00:00
|
|
|
v8::HandleScope scope(env->GetIsolate());
|
2012-11-23 12:32:24 +00:00
|
|
|
|
|
|
|
v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
|
|
|
|
obj->SetNamedPropertyHandler(
|
|
|
|
JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
|
|
|
|
env->Global()->Set(v8_str("obj"), obj->NewInstance());
|
|
|
|
v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
|
|
|
|
CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
|
|
|
|
}
|