43 static const bool kLogThreading =
false;
45 static bool IsNaN(
double x) {
53 using ::v8::AccessorInfo;
54 using ::v8::Arguments;
56 using ::v8::Extension;
58 using ::v8::FunctionTemplate;
60 using ::v8::HandleScope;
65 using ::v8::ObjectTemplate;
66 using ::v8::Persistent;
68 using ::v8::StackTrace;
76 static void ExpectString(
const char* code,
const char* expected) {
77 Local<Value> result = CompileRun(code);
78 CHECK(result->IsString());
79 String::AsciiValue ascii(result);
83 static void ExpectInt32(
const char* code,
int expected) {
84 Local<Value> result = CompileRun(code);
85 CHECK(result->IsInt32());
86 CHECK_EQ(expected, result->Int32Value());
89 static void ExpectBoolean(
const char* code,
bool expected) {
90 Local<Value> result = CompileRun(code);
91 CHECK(result->IsBoolean());
92 CHECK_EQ(expected, result->BooleanValue());
96 static void ExpectTrue(
const char* code) {
97 ExpectBoolean(code,
true);
101 static void ExpectFalse(
const char* code) {
102 ExpectBoolean(code,
false);
106 static void ExpectObject(
const char* code, Local<Value> expected) {
107 Local<Value> result = CompileRun(code);
108 CHECK(result->Equals(expected));
112 static void ExpectUndefined(
const char* code) {
113 Local<Value> result = CompileRun(code);
114 CHECK(result->IsUndefined());
118 static int signature_callback_count;
122 signature_callback_count++;
124 for (
int i = 0; i < args.
Length(); i++)
133 for (
int i = 0; i < args.
Length(); i++) {
142 Local<Context> local_env;
145 local_env = env.
local();
149 CHECK(!local_env.IsEmpty());
156 const char* c_source =
"1 + 2 + 3";
157 Local<String> source = String::New(c_source);
158 Local<Script> script = Script::Compile(source);
159 CHECK_EQ(6, script->Run()->Int32Value());
176 signature_callback_count = 0;
180 CHECK_EQ(1, signature_callback_count);
185 "var o = new SubFun();"
187 CHECK_EQ(2, signature_callback_count);
192 "o.m = Fun.prototype.m;"
194 CHECK_EQ(2, signature_callback_count);
201 "var o = new UnrelFun();"
202 "o.m = Fun.prototype.m;"
204 CHECK_EQ(2, signature_callback_count);
225 CHECK(value2->IsTrue());
228 CHECK(value3->IsTrue());
231 cons1->SetClassName(v8_str(
"Cons1"));
243 env->
Global()->Set(v8_str(
"Cons1"), cons1->GetFunction());
248 "Fun2(new Cons1(), new Cons2(), new Cons3()) =="
249 "'[object Cons1],[object Cons2],[object Cons3]'");
253 "Fun2(new Cons1(), new Cons2(), 5) == '[object Cons1],[object Cons2],'");
254 CHECK(value5->IsTrue());
257 "Fun2(new Cons3(), new Cons2(), new Cons1()) == ',[object Cons2],'");
258 CHECK(value6->IsTrue());
261 "Fun2(new Cons1(), new Cons2(), new Cons3(), 'd') == "
262 "'[object Cons1],[object Cons2],[object Cons3],d';");
263 CHECK(value7->IsTrue());
266 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'");
267 CHECK(value8->IsTrue());
275 Local<String> undef_str = undef->
ToString();
276 char* value = i::NewArray<char>(undef_str->Length() + 1);
277 undef_str->WriteAscii(value);
278 CHECK_EQ(0, strcmp(value,
"undefined"));
287 Local<Value> foo_before = obj->Get(v8_str(
"foo"));
288 CHECK(foo_before->IsUndefined());
289 Local<String> bar_str = v8_str(
"bar");
290 obj->Set(v8_str(
"foo"), bar_str);
291 Local<Value> foo_after = obj->Get(v8_str(
"foo"));
292 CHECK(!foo_after->IsUndefined());
293 CHECK(foo_after->IsString());
302 Local<Value> before = obj->Get(1);
303 CHECK(before->IsUndefined());
304 Local<String> bar_str = v8_str(
"bar");
305 obj->Set(1, bar_str);
306 Local<Value> after = obj->Get(1);
307 CHECK(!after->IsUndefined());
308 CHECK(after->IsString());
311 Local<v8::Array> value = CompileRun(
"[\"a\", \"b\"]").As<
v8::Array>();
312 CHECK_EQ(v8_str(
"a"), value->Get(0));
313 CHECK_EQ(v8_str(
"b"), value->Get(1));
320 const char* c_source =
"1 + 2 + 3";
321 Local<String> source = String::New(c_source);
322 Local<Script> script = Script::Compile(source);
323 CHECK_EQ(6, script->Run()->Int32Value());
327 static uint16_t* AsciiToTwoByteString(
const char* source) {
329 uint16_t* converted = i::NewArray<uint16_t>(array_length);
330 for (
int i = 0; i < array_length; i++) converted[i] = source[i];
338 : data_(data), length_(0), counter_(counter) {
339 while (data[length_]) ++length_;
344 if (counter_ !=
NULL) ++*counter_;
364 : data_(data), length_(strlen(data)), counter_(counter) { }
368 if (counter_ !=
NULL) ++*counter_;
386 int dispose_count = 0;
387 const char* c_source =
"1 + 2 * 3";
388 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
393 Local<String> source = String::NewExternal(resource);
394 Local<Script> script = Script::Compile(source);
395 Local<Value> value = script->Run();
396 CHECK(value->IsNumber());
398 CHECK(source->IsExternal());
400 static_cast<TestResource*>(source->GetExternalStringResource()));
404 v8::internal::Isolate::Current()->compilation_cache()->Clear();
405 HEAP->CollectAllAvailableGarbage();
411 int dispose_count = 0;
412 const char* c_source =
"1 + 2 * 3";
416 Local<String> source =
419 Local<Script> script = Script::Compile(source);
420 Local<Value> value = script->Run();
421 CHECK(value->IsNumber());
426 i::Isolate::Current()->compilation_cache()->Clear();
427 HEAP->CollectAllAvailableGarbage();
433 int dispose_count = 0;
434 uint16_t* two_byte_source = AsciiToTwoByteString(
"1 + 2 * 3");
438 Local<String> source = String::New(two_byte_source);
442 bool success = source->MakeExternal(
new TestResource(two_byte_source,
445 Local<Script> script = Script::Compile(source);
446 Local<Value> value = script->Run();
447 CHECK(value->IsNumber());
452 i::Isolate::Current()->compilation_cache()->Clear();
459 int dispose_count = 0;
460 const char* c_source =
"1 + 2 * 3";
464 Local<String> source = v8_str(c_source);
468 bool success = source->MakeExternal(
471 Local<Script> script = Script::Compile(source);
472 Local<Value> value = script->Run();
473 CHECK(value->IsNumber());
478 i::Isolate::Current()->compilation_cache()->Clear();
484 TEST(MakingExternalStringConditions) {
492 uint16_t* two_byte_string = AsciiToTwoByteString(
"s1");
493 Local<String> small_string = String::New(two_byte_string);
497 CHECK(!small_string->CanMakeExternal());
502 CHECK(small_string->CanMakeExternal());
504 two_byte_string = AsciiToTwoByteString(
"small string 2");
505 small_string = String::New(two_byte_string);
509 CHECK(!small_string->CanMakeExternal());
510 for (
int i = 0; i < 100; i++) {
511 String::Value value(small_string);
514 CHECK(small_string->CanMakeExternal());
516 const int buf_size = 10 * 1024;
517 char* buf = i::NewArray<char>(buf_size);
518 memset(buf,
'a', buf_size);
519 buf[buf_size - 1] =
'\0';
521 two_byte_string = AsciiToTwoByteString(buf);
522 Local<String> large_string = String::New(two_byte_string);
526 CHECK(large_string->CanMakeExternal());
530 TEST(MakingExternalAsciiStringConditions) {
538 Local<String> small_string = String::New(
"s1");
540 CHECK(!small_string->CanMakeExternal());
545 CHECK(small_string->CanMakeExternal());
547 small_string = String::New(
"small string 2");
549 CHECK(!small_string->CanMakeExternal());
550 for (
int i = 0; i < 100; i++) {
551 String::Value value(small_string);
554 CHECK(small_string->CanMakeExternal());
556 const int buf_size = 10 * 1024;
557 char* buf = i::NewArray<char>(buf_size);
558 memset(buf,
'a', buf_size);
559 buf[buf_size - 1] =
'\0';
560 Local<String> large_string = String::New(buf);
563 CHECK(large_string->CanMakeExternal());
570 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
571 Local<String>
string =
578 CHECK(isymbol->IsSymbol());
588 const char* one_byte_string =
"test string";
589 Local<String>
string = String::NewExternal(
596 CHECK(isymbol->IsSymbol());
604 int dispose_count = 0;
605 bool in_new_space =
false;
608 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
609 Local<String>
string =
614 in_new_space =
HEAP->InNewSpace(*istring);
615 CHECK(in_new_space ||
HEAP->old_data_space()->Contains(*istring));
624 int dispose_count = 0;
625 bool in_new_space =
false;
628 const char* one_byte_string =
"test string";
629 Local<String>
string = String::NewExternal(
633 in_new_space =
HEAP->InNewSpace(*istring);
634 CHECK(in_new_space ||
HEAP->old_data_space()->Contains(*istring));
650 dispose_(dispose) { }
654 if (dispose_)
delete this;
665 TEST(ExternalStringWithDisposeHandling) {
666 const char* c_source =
"1 + 2 * 3";
669 TestAsciiResourceWithDisposeControl::dispose_count = 0;
670 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
675 Local<String> source = String::NewExternal(&res_stack);
676 Local<Script> script = Script::Compile(source);
677 Local<Value> value = script->Run();
678 CHECK(value->IsNumber());
680 HEAP->CollectAllAvailableGarbage();
681 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
683 i::Isolate::Current()->compilation_cache()->Clear();
684 HEAP->CollectAllAvailableGarbage();
685 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
686 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
689 TestAsciiResourceWithDisposeControl::dispose_count = 0;
690 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
696 Local<String> source = String::NewExternal(res_heap);
697 Local<Script> script = Script::Compile(source);
698 Local<Value> value = script->Run();
699 CHECK(value->IsNumber());
701 HEAP->CollectAllAvailableGarbage();
702 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
704 i::Isolate::Current()->compilation_cache()->Clear();
705 HEAP->CollectAllAvailableGarbage();
706 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
707 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
715 const char* one_byte_string_1 =
"function a_times_t";
716 const char* two_byte_string_1 =
"wo_plus_b(a, b) {return ";
717 const char* one_byte_extern_1 =
"a * 2 + b;} a_times_two_plus_b(4, 8) + ";
718 const char* two_byte_extern_1 =
"a_times_two_plus_b(4, 8) + ";
719 const char* one_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
720 const char* two_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
721 const char* two_byte_extern_2 =
"a_times_two_plus_b(1, 2);";
722 Local<String> left = v8_str(one_byte_string_1);
724 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
725 Local<String> right = String::New(two_byte_source);
728 Local<String> source = String::Concat(left, right);
729 right = String::NewExternal(
731 source = String::Concat(source, right);
732 right = String::NewExternal(
733 new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
734 source = String::Concat(source, right);
735 right = v8_str(one_byte_string_2);
736 source = String::Concat(source, right);
738 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
739 right = String::New(two_byte_source);
742 source = String::Concat(source, right);
743 right = String::NewExternal(
744 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
745 source = String::Concat(source, right);
746 Local<Script> script = Script::Compile(source);
747 Local<Value> value = script->Run();
748 CHECK(value->IsNumber());
751 i::Isolate::Current()->compilation_cache()->Clear();
761 global->
Set(v8_str(
"pi"), v8_num(3.1415926));
762 Local<Value> pi = global->
Get(v8_str(
"pi"));
763 CHECK_EQ(3.1415926, pi->NumberValue());
775 args.
This()->Set(v8_str(
"x"), v8_num(1));
776 args.
This()->Set(v8_str(
"y"), v8_num(2));
790 Local<v8::FunctionTemplate> fun_templ =
792 Local<Function> fun = fun_templ->GetFunction();
793 env->
Global()->Set(v8_str(
"obj"), fun);
794 Local<Script> script = v8_compile(
"obj()");
795 CHECK_EQ(102, script->Run()->Int32Value());
801 fun_templ->SetCallHandler(handle_call);
802 Local<Function> fun = fun_templ->GetFunction();
803 env->
Global()->Set(v8_str(
"obj"), fun);
804 Local<Script> script = v8_compile(
"obj()");
805 CHECK_EQ(102, script->Run()->Int32Value());
809 Local<v8::FunctionTemplate> fun_templ =
811 fun_templ->SetClassName(v8_str(
"funky"));
812 fun_templ->InstanceTemplate()->SetAccessor(v8_str(
"m"), Return239);
813 Local<Function> fun = fun_templ->GetFunction();
814 env->
Global()->Set(v8_str(
"obj"), fun);
815 Local<Script> script = v8_compile(
"var s = new obj(); s.x");
816 CHECK_EQ(1, script->Run()->Int32Value());
818 Local<Value> result = v8_compile(
"(new obj()).toString()")->Run();
819 CHECK_EQ(v8_str(
"[object funky]"), result);
821 result = v8_compile(
"(new obj()).m")->Run();
822 CHECK_EQ(239, result->Int32Value());
827 static void* expected_ptr;
835 static void TestExternalPointerWrapping() {
842 obj->
Set(v8_str(
"func"),
844 env->
Global()->Set(v8_str(
"obj"), obj);
848 " for (var i = 0; i < 13; i++) obj.func();\n"
850 "foo(), true")->BooleanValue());
858 TestExternalPointerWrapping();
864 TestExternalPointerWrapping();
868 char* s =
new char[n];
869 for (
int i = 0; i < n; i++) {
870 expected_ptr = s + i;
871 TestExternalPointerWrapping();
877 expected_ptr =
reinterpret_cast<void*
>(1);
878 TestExternalPointerWrapping();
880 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef);
881 TestExternalPointerWrapping();
883 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef + 1);
884 TestExternalPointerWrapping();
886 #if defined(V8_HOST_ARCH_X64)
888 expected_ptr =
reinterpret_cast<void*
>(0x400000000);
889 TestExternalPointerWrapping();
891 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef);
892 TestExternalPointerWrapping();
894 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef + 1);
895 TestExternalPointerWrapping();
907 derived->Inherit(base);
909 Local<v8::Function> base_function = base->GetFunction();
910 Local<v8::Function> derived_function = derived->GetFunction();
911 Local<v8::Function> other_function = other->GetFunction();
913 Local<v8::Object> base_instance = base_function->NewInstance();
914 Local<v8::Object> derived_instance = derived_function->NewInstance();
915 Local<v8::Object> derived_instance2 = derived_function->NewInstance();
916 Local<v8::Object> other_instance = other_function->NewInstance();
917 derived_instance2->Set(v8_str(
"__proto__"), derived_instance);
918 other_instance->Set(v8_str(
"__proto__"), derived_instance2);
922 base_instance->FindInstanceInPrototypeChain(base));
923 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty());
924 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty());
928 derived_instance->FindInstanceInPrototypeChain(base));
930 derived_instance->FindInstanceInPrototypeChain(derived));
931 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty());
939 other_instance->FindInstanceInPrototypeChain(base));
941 other_instance->FindInstanceInPrototypeChain(derived));
943 other_instance->FindInstanceInPrototypeChain(other));
952 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
965 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
982 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
990 uint32_t value = 239;
992 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1003 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1014 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1021 uint32_t INT32_MAX_AS_UINT = (1
U << 31) - 1;
1022 uint32_t value = INT32_MAX_AS_UINT + 1;
1023 CHECK(value > INT32_MAX_AS_UINT);
1025 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1033 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1036 CHECK(!not_error->IsNativeError());
1038 CHECK(!not_object->IsNativeError());
1048 CHECK(!unboxed_string->IsStringObject());
1050 CHECK(!boxed_not_string->IsStringObject());
1052 CHECK(!not_object->IsStringObject());
1054 CHECK(!as_boxed.IsEmpty());
1055 Local<v8::String> the_string = as_boxed->StringValue();
1056 CHECK(!the_string.IsEmpty());
1057 ExpectObject(
"\"test\"", the_string);
1062 CHECK(!the_string.IsEmpty());
1063 ExpectObject(
"\"test\"", the_string);
1073 CHECK(!unboxed_number->IsNumberObject());
1075 CHECK(!boxed_not_number->IsNumberObject());
1077 CHECK(!as_boxed.IsEmpty());
1078 double the_number = as_boxed->NumberValue();
1094 CHECK(!unboxed_boolean->IsBooleanObject());
1096 CHECK(!boxed_not_boolean->IsBooleanObject());
1099 CHECK(!as_boxed.IsEmpty());
1100 bool the_boolean = as_boxed->BooleanValue();
1107 CHECK_EQ(
true, as_boxed->BooleanValue());
1109 CHECK_EQ(
false, as_boxed->BooleanValue());
1116 double PI = 3.1415926;
1118 CHECK_EQ(PI, pi_obj->NumberValue());
1125 Local<String> str = v8_str(
"3.1415926");
1126 CHECK_EQ(3.1415926, str->NumberValue());
1137 double PI = 3.1415926;
1139 CHECK_EQ(3.0, date->NumberValue());
1153 CHECK(!u->BooleanValue());
1155 CHECK(!n->BooleanValue());
1157 CHECK(!str1->BooleanValue());
1159 CHECK(str2->BooleanValue());
1164 CHECK(!v8_compile(
"NaN")->Run()->BooleanValue());
1170 return v8_num(13.4);
1187 templ->
Set(
"x", v8_num(200));
1193 CHECK_EQ(200, v8_compile(
"x")->Run()->Int32Value());
1194 CHECK_EQ(876, v8_compile(
"m")->Run()->Int32Value());
1200 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1201 templ1->Set(
"x", v8_num(10));
1202 templ1->Set(
"y", v8_num(13));
1204 Local<v8::Object> instance1 = templ1->NewInstance();
1205 env->
Global()->Set(v8_str(
"p"), instance1);
1206 CHECK(v8_compile(
"(p.x == 10)")->Run()->BooleanValue());
1207 CHECK(v8_compile(
"(p.y == 13)")->Run()->BooleanValue());
1209 fun->PrototypeTemplate()->Set(
"nirk", v8_num(123));
1210 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
1211 templ2->Set(
"a", v8_num(12));
1212 templ2->Set(
"b", templ1);
1213 Local<v8::Object> instance2 = templ2->NewInstance();
1214 env->
Global()->Set(v8_str(
"q"), instance2);
1215 CHECK(v8_compile(
"(q.nirk == 123)")->Run()->BooleanValue());
1216 CHECK(v8_compile(
"(q.a == 12)")->Run()->BooleanValue());
1217 CHECK(v8_compile(
"(q.b.x == 10)")->Run()->BooleanValue());
1218 CHECK(v8_compile(
"(q.b.y == 13)")->Run()->BooleanValue());
1224 return v8_num(17.2);
1228 static v8::Handle<Value> GetKnurd(Local<String> property,
const AccessorInfo&) {
1230 return v8_num(15.2);
1258 CHECK(CompileRun(
"base1.prototype.__proto__ == s.prototype")->BooleanValue());
1259 CHECK(CompileRun(
"base2.prototype.__proto__ == s.prototype")->BooleanValue());
1261 CHECK(v8_compile(
"s.prototype.PI == 3.14")->Run()->BooleanValue());
1264 CHECK(CompileRun(
"s.knurd == undefined")->BooleanValue());
1265 CHECK(CompileRun(
"s.prototype.knurd == undefined")->BooleanValue());
1266 CHECK(CompileRun(
"base1.prototype.knurd == undefined")->BooleanValue());
1268 env->
Global()->Set(v8_str(
"obj"),
1270 CHECK_EQ(17.2, v8_compile(
"obj.flabby()")->Run()->NumberValue());
1271 CHECK(v8_compile(
"'flabby' in obj")->Run()->BooleanValue());
1272 CHECK_EQ(15.2, v8_compile(
"obj.knurd")->Run()->NumberValue());
1273 CHECK(v8_compile(
"'knurd' in obj")->Run()->BooleanValue());
1274 CHECK_EQ(20.1, v8_compile(
"obj.v1")->Run()->NumberValue());
1276 env->
Global()->Set(v8_str(
"obj2"),
1278 CHECK_EQ(17.2, v8_compile(
"obj2.flabby()")->Run()->NumberValue());
1279 CHECK(v8_compile(
"'flabby' in obj2")->Run()->BooleanValue());
1280 CHECK_EQ(15.2, v8_compile(
"obj2.knurd")->Run()->NumberValue());
1281 CHECK(v8_compile(
"'knurd' in obj2")->Run()->BooleanValue());
1282 CHECK_EQ(10.1, v8_compile(
"obj2.v2")->Run()->NumberValue());
1285 CHECK(v8_compile(
"obj.v2")->Run()->IsUndefined());
1286 CHECK(v8_compile(
"obj2.v1")->Run()->IsUndefined());
1294 const AccessorInfo& info) {
1296 CHECK_EQ(v8_str(
"data"), info.Data());
1297 echo_named_call_count++;
1304 const AccessorInfo& info) {
1305 Handle<Object>
self = info.This();
1306 return self->Get(String::Concat(v8_str(
"accessor_"), name));
1310 const AccessorInfo& info) {
1311 Handle<Object>
self = info.This();
1312 self->Set(String::Concat(v8_str(
"accessor_"), name), value);
1316 const AccessorInfo& info) {
1317 return Handle<Value>();
1322 const AccessorInfo& info) {
1323 return Handle<Value>();
1327 const AccessorInfo& info) {
1329 String::AsciiValue ascii(name);
1330 char* name_str = *ascii;
1331 char prefix[] =
"interceptor_";
1333 for (i = 0; name_str[i] && prefix[i]; ++i) {
1334 if (name_str[i] != prefix[i])
return Handle<Value>();
1336 Handle<Object>
self = info.This();
1337 return self->GetHiddenValue(v8_str(name_str + i));
1342 const AccessorInfo& info) {
1344 if (value->IsInt32() && value->Int32Value() < 10000) {
1345 Handle<Object>
self = info.This();
1346 self->SetHiddenValue(name, value);
1349 return Handle<Value>();
1353 Handle<String>
name,
1356 templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
1362 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1367 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1368 Handle<FunctionTemplate> child = FunctionTemplate::New();
1369 child->Inherit(parent);
1374 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1375 CompileRun(
"var child = new Child;"
1377 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
1378 ExpectInt32(
"child.age", 10);
1379 ExpectInt32(
"child.accessor_age", 10);
1384 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1385 Handle<FunctionTemplate> child = FunctionTemplate::New();
1386 child->Inherit(parent);
1389 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1390 CompileRun(
"var child = new Child;"
1391 "var parent = child.__proto__;"
1392 "Object.defineProperty(parent, 'age', "
1393 " {get: function(){ return this.accessor_age; }, "
1394 " set: function(v){ this.accessor_age = v; }, "
1395 " enumerable: true, configurable: true});"
1397 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
1398 ExpectInt32(
"child.age", 10);
1399 ExpectInt32(
"child.accessor_age", 10);
1404 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1405 Handle<FunctionTemplate> child = FunctionTemplate::New();
1406 child->Inherit(parent);
1409 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1410 CompileRun(
"var child = new Child;"
1411 "var parent = child.__proto__;"
1412 "parent.name = 'Alice';");
1413 ExpectBoolean(
"child.hasOwnProperty('name')",
false);
1414 ExpectString(
"child.name",
"Alice");
1415 CompileRun(
"child.name = 'Bob';");
1416 ExpectString(
"child.name",
"Bob");
1417 ExpectBoolean(
"child.hasOwnProperty('name')",
true);
1418 ExpectString(
"parent.name",
"Alice");
1423 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1428 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1429 CompileRun(
"var obj = new Obj;"
1430 "function setAge(i){ obj.age = i; };"
1431 "for(var i = 0; i <= 10000; i++) setAge(i);");
1433 ExpectInt32(
"obj.interceptor_age", 9999);
1435 ExpectInt32(
"obj.accessor_age", 10000);
1440 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1445 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1446 CompileRun(
"var obj = new Obj;"
1447 "function setAge(i){ obj.age = i; };"
1448 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1450 ExpectInt32(
"obj.accessor_age", 10000);
1452 ExpectInt32(
"obj.interceptor_age", 9999);
1457 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1458 Handle<FunctionTemplate> child = FunctionTemplate::New();
1459 child->Inherit(parent);
1464 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1465 CompileRun(
"var child = new Child;"
1466 "function setAge(i){ child.age = i; };"
1467 "for(var i = 0; i <= 10000; i++) setAge(i);");
1469 ExpectInt32(
"child.interceptor_age", 9999);
1471 ExpectInt32(
"child.accessor_age", 10000);
1476 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1477 Handle<FunctionTemplate> child = FunctionTemplate::New();
1478 child->Inherit(parent);
1483 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1484 CompileRun(
"var child = new Child;"
1485 "function setAge(i){ child.age = i; };"
1486 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1488 ExpectInt32(
"child.accessor_age", 10000);
1490 ExpectInt32(
"child.interceptor_age", 9999);
1495 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1498 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1499 CompileRun(
"var obj = new Obj;"
1500 "function setter(i) { this.accessor_age = i; };"
1501 "function getter() { return this.accessor_age; };"
1502 "function setAge(i) { obj.age = i; };"
1503 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1504 "for(var i = 0; i <= 10000; i++) setAge(i);");
1506 ExpectInt32(
"obj.interceptor_age", 9999);
1508 ExpectInt32(
"obj.accessor_age", 10000);
1512 ExpectInt32(
"obj.age", 10000);
1513 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
1514 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
1519 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1522 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1523 CompileRun(
"var obj = new Obj;"
1524 "function setter(i) { this.accessor_age = i; };"
1525 "function getter() { return this.accessor_age; };"
1526 "function setAge(i) { obj.age = i; };"
1527 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1528 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1530 ExpectInt32(
"obj.accessor_age", 10000);
1532 ExpectInt32(
"obj.interceptor_age", 9999);
1536 ExpectInt32(
"obj.age", 10000);
1537 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
1538 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
1543 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1544 Handle<FunctionTemplate> child = FunctionTemplate::New();
1545 child->Inherit(parent);
1548 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1549 CompileRun(
"var child = new Child;"
1550 "function setAge(i){ child.age = i; };"
1551 "for(var i = 0; i <= 10000; i++) setAge(i);");
1553 ExpectInt32(
"child.interceptor_age", 9999);
1555 ExpectInt32(
"child.age", 10000);
1560 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1561 Handle<FunctionTemplate> child = FunctionTemplate::New();
1562 child->Inherit(parent);
1565 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1566 CompileRun(
"var child = new Child;"
1567 "function setAge(i){ child.age = i; };"
1568 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1570 ExpectInt32(
"child.age", 10000);
1572 ExpectInt32(
"child.interceptor_age", 9999);
1576 echo_named_call_count = 0;
1583 env->
Global()->Set(v8_str(
"obj"),
1585 CHECK_EQ(echo_named_call_count, 0);
1586 v8_compile(
"obj.x")->Run();
1587 CHECK_EQ(echo_named_call_count, 1);
1588 const char* code =
"var str = 'oddle'; obj[str] + obj.poddle;";
1590 String::AsciiValue value(str);
1593 CHECK_EQ(v8_compile(
"obj.flob = 10;")->Run()->Int32Value(), 10);
1594 CHECK(v8_compile(
"'myProperty' in obj")->Run()->BooleanValue());
1595 CHECK(v8_compile(
"delete obj.myProperty")->Run()->BooleanValue());
1603 const AccessorInfo& info) {
1605 CHECK_EQ(v8_num(637), info.Data());
1606 echo_indexed_call_count++;
1607 return v8_num(index);
1618 env->
Global()->Set(v8_str(
"obj"),
1620 Local<Script> script = v8_compile(
"obj[900]");
1621 CHECK_EQ(script->Run()->Int32Value(), 900);
1629 const AccessorInfo& info) {
1631 CHECK(info.This()->Equals(bottom));
1637 const AccessorInfo& info) {
1639 CHECK(info.This()->Equals(bottom));
1646 const AccessorInfo& info) {
1648 CHECK(info.This()->Equals(bottom));
1655 const AccessorInfo& info) {
1657 CHECK(info.This()->Equals(bottom));
1663 const AccessorInfo& info) {
1665 CHECK(info.This()->Equals(bottom));
1671 const AccessorInfo& info) {
1673 CHECK(info.This()->Equals(bottom));
1680 const AccessorInfo& info) {
1682 CHECK(info.This()->Equals(bottom));
1688 Local<String> property,
1689 const AccessorInfo& info) {
1691 CHECK(info.This()->Equals(bottom));
1697 const AccessorInfo& info) {
1699 CHECK(info.This()->Equals(bottom));
1705 const AccessorInfo& info) {
1707 CHECK(info.This()->Equals(bottom));
1719 CheckThisIndexedPropertyHandler,
1726 CheckThisNamedPropertyHandler,
1733 Local<v8::Object> top = templ->
GetFunction()->NewInstance();
1734 Local<v8::Object> middle = templ->
GetFunction()->NewInstance();
1736 bottom->
Set(v8_str(
"__proto__"), middle);
1737 middle->Set(v8_str(
"__proto__"), top);
1738 env->
Global()->Set(v8_str(
"obj"), bottom);
1741 Script::Compile(v8_str(
"obj[0]"))->Run();
1742 Script::Compile(v8_str(
"obj.x"))->Run();
1745 Script::Compile(v8_str(
"obj[1] = 42"))->Run();
1746 Script::Compile(v8_str(
"obj.y = 42"))->Run();
1749 Script::Compile(v8_str(
"0 in obj"))->Run();
1750 Script::Compile(v8_str(
"'x' in obj"))->Run();
1753 Script::Compile(v8_str(
"delete obj[0]"))->Run();
1754 Script::Compile(v8_str(
"delete obj.x"))->Run();
1757 Script::Compile(v8_str(
"for (var p in obj) ;"))->Run();
1762 const AccessorInfo& info) {
1764 if (v8_str(
"pre")->Equals(key)) {
1765 return v8_str(
"PrePropertyHandler: pre");
1772 const AccessorInfo&) {
1773 if (v8_str(
"pre")->Equals(key)) {
1786 PrePropertyHandlerQuery);
1788 Script::Compile(v8_str(
1789 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run();
1791 CHECK_EQ(v8_str(
"PrePropertyHandler: pre"), result_pre);
1793 CHECK_EQ(v8_str(
"Object: on"), result_on);
1803 "this.propertyIsEnumerable(undefined)"))->Run();
1809 static const int kTargetRecursionDepth = 200;
1814 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
1817 return call_recursively_script->
Run();
1824 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
1825 if (depth == kTargetRecursionDepth) {
1826 printf(
"[depth = %d]\n", depth);
1831 args.
This()->Get(v8_str(
"callFunctionRecursively"));
1832 return function.
As<Function>()->Call(args.
This(), 0,
NULL);
1839 global->
Set(v8_str(
"callScriptRecursively"),
1841 global->
Set(v8_str(
"callFunctionRecursively"),
1846 call_recursively_script = v8_compile(
"callScriptRecursively()");
1847 call_recursively_script->
Run();
1851 Script::Compile(v8_str(
"callFunctionRecursively()"))->Run();
1856 ThrowingPropertyHandlerGet(Local<String> key,
const AccessorInfo&) {
1864 const AccessorInfo&) {
1874 ThrowingPropertyHandlerSet);
1878 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
1881 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
1889 Foo->PrototypeTemplate()->Set(v8_str(
"plak"), v8_num(321));
1891 env->
Global()->Set(v8_str(
"Foo"), Foo->GetFunction());
1892 Local<Script> script = Script::Compile(v8_str(
"Foo.prototype.plak"));
1893 CHECK_EQ(script->Run()->Int32Value(), 321);
1902 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1903 instance_templ->SetInternalFieldCount(1);
1904 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1905 CHECK_EQ(1, obj->InternalFieldCount());
1906 CHECK(obj->GetInternalField(0)->IsUndefined());
1907 obj->SetInternalField(0, v8_num(17));
1908 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
1915 global_template->SetInternalFieldCount(1);
1931 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1932 instance_templ->SetInternalFieldCount(1);
1933 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1934 CHECK_EQ(1, obj->InternalFieldCount());
1935 CHECK(obj->GetPointerFromInternalField(0) ==
NULL);
1937 char* data =
new char[100];
1939 void* aligned = data;
1940 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(aligned) & 0x1));
1941 void* unaligned = data + 1;
1942 CHECK_EQ(1, static_cast<int>(reinterpret_cast<uintptr_t>(unaligned) & 0x1));
1945 obj->SetPointerInInternalField(0, aligned);
1947 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0));
1950 obj->SetPointerInInternalField(0, unaligned);
1952 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0));
1963 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1964 instance_templ->SetInternalFieldCount(1);
1965 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1966 CHECK_EQ(1, obj->InternalFieldCount());
1967 CHECK(obj->GetPointerFromInternalField(0) ==
NULL);
1969 char* data =
new char[100];
1971 void* aligned = data;
1972 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(aligned) & 0x1));
1973 void* unaligned = data + 1;
1974 CHECK_EQ(1, static_cast<int>(reinterpret_cast<uintptr_t>(unaligned) & 0x1));
1976 obj->SetPointerInInternalField(0, aligned);
1980 obj->SetPointerInInternalField(0, unaligned);
1986 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0));
1990 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0));
2004 int hash = obj->GetIdentityHash();
2005 int hash1 = obj->GetIdentityHash();
2018 int hash4 = obj->GetIdentityHash();
2024 CompileRun(
"Object.prototype['v8::IdentityHash'] = 42;\n");
2027 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2031 "function cnst() { return 42; };\n"
2032 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2035 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2064 CHECK(obj->
Get(empty)->IsUndefined());
2076 CHECK_EQ(2008, obj->
Get(prop_name)->Int32Value());
2099 "set_called = false;"
2100 "Object.defineProperty("
2101 " Object.prototype,"
2103 " {get: function() { return 45; },"
2104 " set: function() { set_called = true; }})");
2111 ExpectFalse(
"set_called");
2116 static bool interceptor_for_hidden_properties_called;
2118 Local<String> name,
const AccessorInfo& info) {
2119 interceptor_for_hidden_properties_called =
true;
2128 interceptor_for_hidden_properties_called =
false;
2134 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
2135 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
2136 Local<v8::Function>
function = fun_templ->GetFunction();
2137 Local<v8::Object> obj =
function->NewInstance();
2139 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
2140 CHECK(!interceptor_for_hidden_properties_called);
2149 env->
Global()->Set(v8_str(
"ext"), ext);
2150 Local<Value> reext_obj = Script::Compile(v8_str(
"this.ext"))->Run();
2152 int* ptr =
static_cast<int*
>(reext->
Value());
2180 Local<String> str = v8_str(
"str");
2196 int number_of_weak_calls_;
2200 static void WeakPointerCallback(Persistent<Value> handle,
void*
id) {
2212 Persistent<Object> g1s1;
2213 Persistent<Object> g1s2;
2214 Persistent<Object> g1c1;
2215 Persistent<Object> g2s1;
2216 Persistent<Object> g2s2;
2217 Persistent<Object> g2c1;
2223 g1s1 = Persistent<Object>::New(Object::New());
2224 g1s2 = Persistent<Object>::New(Object::New());
2225 g1c1 = Persistent<Object>::New(Object::New());
2226 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2227 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2228 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2230 g2s1 = Persistent<Object>::New(Object::New());
2231 g2s2 = Persistent<Object>::New(Object::New());
2232 g2c1 = Persistent<Object>::New(Object::New());
2233 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2234 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2235 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2238 Persistent<Object> root = Persistent<Object>::New(g1s1);
2241 CHECK(g1s2->Set(0, g2s2));
2242 CHECK(g2s1->Set(0, g1s1));
2245 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2246 Persistent<Value> g1_children[] = { g1c1 };
2247 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2248 Persistent<Value> g2_children[] = { g2c1 };
2249 V8::AddObjectGroup(g1_objects, 2);
2250 V8::AddImplicitReferences(g1s1, g1_children, 1);
2251 V8::AddObjectGroup(g2_objects, 2);
2252 V8::AddImplicitReferences(g2s2, g2_children, 1);
2261 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2269 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2270 Persistent<Value> g1_children[] = { g1c1 };
2271 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2272 Persistent<Value> g2_children[] = { g2c1 };
2273 V8::AddObjectGroup(g1_objects, 2);
2274 V8::AddImplicitReferences(g1s1, g1_children, 1);
2275 V8::AddObjectGroup(g2_objects, 2);
2276 V8::AddImplicitReferences(g2s2, g2_children, 1);
2285 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2286 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2299 Persistent<Object> g1s1;
2300 Persistent<Object> g1s2;
2301 Persistent<Object> g2s1;
2302 Persistent<Object> g2s2;
2303 Persistent<Object> g3s1;
2304 Persistent<Object> g3s2;
2308 g1s1 = Persistent<Object>::New(Object::New());
2309 g1s2 = Persistent<Object>::New(Object::New());
2310 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2311 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2313 g2s1 = Persistent<Object>::New(Object::New());
2314 g2s2 = Persistent<Object>::New(Object::New());
2315 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2316 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2318 g3s1 = Persistent<Object>::New(Object::New());
2319 g3s2 = Persistent<Object>::New(Object::New());
2320 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2321 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2324 Persistent<Object> root = Persistent<Object>::New(g1s1);
2330 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2331 Persistent<Value> g1_children[] = { g2s1 };
2332 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2333 Persistent<Value> g2_children[] = { g3s1 };
2334 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2335 Persistent<Value> g3_children[] = { g1s1 };
2336 V8::AddObjectGroup(g1_objects, 2);
2337 V8::AddImplicitReferences(g1s1, g1_children, 1);
2338 V8::AddObjectGroup(g2_objects, 2);
2339 V8::AddImplicitReferences(g2s1, g2_children, 1);
2340 V8::AddObjectGroup(g3_objects, 2);
2341 V8::AddImplicitReferences(g3s1, g3_children, 1);
2350 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2354 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2355 Persistent<Value> g1_children[] = { g2s1 };
2356 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2357 Persistent<Value> g2_children[] = { g3s1 };
2358 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2359 Persistent<Value> g3_children[] = { g1s1 };
2360 V8::AddObjectGroup(g1_objects, 2);
2361 V8::AddImplicitReferences(g1s1, g1_children, 1);
2362 V8::AddObjectGroup(g2_objects, 2);
2363 V8::AddImplicitReferences(g2s1, g2_children, 1);
2364 V8::AddObjectGroup(g3_objects, 2);
2365 V8::AddImplicitReferences(g3s1, g3_children, 1);
2378 Local<Script> script = Script::Compile(v8_str(
"throw 'panama!';"));
2380 Local<Value> result = script->Run();
2381 CHECK(result.IsEmpty());
2383 String::AsciiValue exception_value(try_catch.
Exception());
2384 CHECK_EQ(*exception_value,
"panama!");
2396 message_received =
true;
2401 message_received =
false;
2403 CHECK(!message_received);
2410 script->
SetData(v8_str(
"7.56"));
2412 CHECK(message_received);
2421 context->
Global()->Set(v8_str(
"foo"), v8_num(14));
2422 context->
Global()->Set(v8_str(
"12"), v8_num(92));
2424 context->
Global()->Set(v8_num(13), v8_num(56));
2425 Local<Value>
foo = Script::Compile(v8_str(
"this.foo"))->Run();
2427 Local<Value> twelve = Script::Compile(v8_str(
"this[12]"))->Run();
2428 CHECK_EQ(92, twelve->Int32Value());
2429 Local<Value> sixteen = Script::Compile(v8_str(
"this[16]"))->Run();
2430 CHECK_EQ(32, sixteen->Int32Value());
2431 Local<Value> thirteen = Script::Compile(v8_str(
"this[13]"))->Run();
2432 CHECK_EQ(56, thirteen->Int32Value());
2434 CHECK_EQ(92, context->
Global()->Get(v8_str(
"12"))->Int32Value());
2437 CHECK_EQ(32, context->
Global()->Get(v8_str(
"16"))->Int32Value());
2440 CHECK_EQ(56, context->
Global()->Get(v8_str(
"13"))->Int32Value());
2449 Local<String> prop = v8_str(
"none");
2450 context->
Global()->Set(prop, v8_num(7));
2453 prop = v8_str(
"read_only");
2457 Script::Compile(v8_str(
"read_only = 9"))->Run();
2459 context->
Global()->Set(prop, v8_num(10));
2462 prop = v8_str(
"dont_delete");
2465 Script::Compile(v8_str(
"delete dont_delete"))->Run();
2469 prop = v8_str(
"dont_enum");
2473 prop = v8_str(
"absent");
2475 Local<Value> fake_prop = v8_num(1);
2479 Local<Value> exception =
2480 CompileRun(
"({ toString: function() { throw 'exception';} })");
2482 CHECK(try_catch.HasCaught());
2483 String::AsciiValue exception_value(try_catch.Exception());
2484 CHECK_EQ(
"exception", *exception_value);
2494 CHECK(array->Get(0)->IsUndefined());
2495 CHECK(!array->Has(0));
2496 CHECK(array->Get(100)->IsUndefined());
2497 CHECK(!array->Has(100));
2498 array->Set(2, v8_num(7));
2500 CHECK(!array->Has(0));
2501 CHECK(!array->Has(1));
2502 CHECK(array->Has(2));
2503 CHECK_EQ(7, array->Get(2)->Int32Value());
2504 Local<Value> obj = Script::Compile(v8_str(
"[1, 2, 3]"))->Run();
2505 Local<v8::Array> arr = obj.As<
v8::Array>();
2507 CHECK_EQ(1, arr->Get(0)->Int32Value());
2508 CHECK_EQ(2, arr->Get(1)->Int32Value());
2509 CHECK_EQ(3, arr->Get(2)->Int32Value());
2521 for (
int i = 0; i < args.
Length(); i++)
2522 result->Set(i, args[i]);
2523 return scope.
Close(result);
2529 Local<ObjectTemplate> global = ObjectTemplate::New();
2533 const char* fun =
"f()";
2534 Local<v8::Array> a0 = CompileRun(fun).As<
v8::Array>();
2537 const char* fun2 =
"f(11)";
2538 Local<v8::Array> a1 = CompileRun(fun2).As<
v8::Array>();
2540 CHECK_EQ(11, a1->Get(0)->Int32Value());
2542 const char* fun3 =
"f(12, 13)";
2543 Local<v8::Array> a2 = CompileRun(fun3).As<
v8::Array>();
2545 CHECK_EQ(12, a2->Get(0)->Int32Value());
2546 CHECK_EQ(13, a2->Get(1)->Int32Value());
2548 const char* fun4 =
"f(14, 15, 16)";
2549 Local<v8::Array> a3 = CompileRun(fun4).As<
v8::Array>();
2551 CHECK_EQ(14, a3->Get(0)->Int32Value());
2552 CHECK_EQ(15, a3->Get(1)->Int32Value());
2553 CHECK_EQ(16, a3->Get(2)->Int32Value());
2555 const char* fun5 =
"f(17, 18, 19, 20)";
2556 Local<v8::Array> a4 = CompileRun(fun5).As<
v8::Array>();
2558 CHECK_EQ(17, a4->Get(0)->Int32Value());
2559 CHECK_EQ(18, a4->Get(1)->Int32Value());
2560 CHECK_EQ(19, a4->Get(2)->Int32Value());
2561 CHECK_EQ(20, a4->Get(3)->Int32Value());
2571 " for (var i = 0; i < arguments.length; i++) {"
2572 " result.push(arguments[i]);"
2576 Local<Function> Foo =
2577 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
2580 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
2584 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
2590 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2));
2598 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3));
2608 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
2617 static const char* js_code_causing_out_of_memory =
2618 "var a = new Array(); while(true) a.push(a);";
2627 static const int K = 1024;
2637 Local<Script> script =
2638 Script::Compile(String::New(js_code_causing_out_of_memory));
2639 Local<Value> result = script->Run();
2642 CHECK(result.IsEmpty());
2652 Local<Script> script =
2653 Script::Compile(String::New(js_code_causing_out_of_memory));
2654 Local<Value> result = script->Run();
2657 CHECK(result.IsEmpty());
2668 static const int K = 1024;
2675 Local<ObjectTemplate> templ = ObjectTemplate::New();
2676 templ->Set(v8_str(
"ProvokeOutOfMemory"),
2680 Local<Value> result = CompileRun(
2681 "var thrown = false;"
2683 " ProvokeOutOfMemory();"
2688 CHECK(result.IsEmpty());
2697 static const int K = 1024;
2710 Local<Value> result = CompileRun(
2711 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
2712 "for (var i = 0; i < 22; i++) { str = str + str; }");
2715 CHECK(result.IsEmpty());
2726 " for (var i = 0; i < arguments.length; i++) {"
2727 " result.push(arguments[i]);"
2731 Local<Function> Foo =
2732 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
2735 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0));
2739 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1));
2745 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2));
2753 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3));
2763 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4));
2774 String::AsciiValue str_value(try_catch->
Exception());
2784 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
2785 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
2786 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
2787 CHECK_EQ(0, obj->ToInt32()->Value());
2788 CHECK(0u == obj->ToUint32()->Value());
2790 CompileRun(
"var obj = -1234567890123;");
2791 obj = env->
Global()->Get(v8_str(
"obj"));
2792 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
2793 CHECK_EQ(-1912276171, obj->ToInt32()->Value());
2794 CHECK(2382691125u == obj->ToUint32()->Value());
2796 CompileRun(
"var obj = 42;");
2797 obj = env->
Global()->Get(v8_str(
"obj"));
2798 CHECK_EQ(42.0, obj->ToNumber()->Value());
2799 CHECK_EQ(42, obj->ToInt32()->Value());
2800 CHECK(42u == obj->ToUint32()->Value());
2802 CompileRun(
"var obj = -37;");
2803 obj = env->
Global()->Get(v8_str(
"obj"));
2804 CHECK_EQ(-37.0, obj->ToNumber()->Value());
2805 CHECK_EQ(-37, obj->ToInt32()->Value());
2806 CHECK(4294967259u == obj->ToUint32()->Value());
2808 CompileRun(
"var obj = 0x81234567;");
2809 obj = env->
Global()->Get(v8_str(
"obj"));
2810 CHECK_EQ(2166572391.0, obj->ToNumber()->Value());
2811 CHECK_EQ(-2128394905, obj->ToInt32()->Value());
2812 CHECK(2166572391u == obj->ToUint32()->Value());
2814 CompileRun(
"var obj = 42.3;");
2815 obj = env->
Global()->Get(v8_str(
"obj"));
2816 CHECK_EQ(42.3, obj->ToNumber()->Value());
2817 CHECK_EQ(42, obj->ToInt32()->Value());
2818 CHECK(42u == obj->ToUint32()->Value());
2820 CompileRun(
"var obj = -5726623061.75;");
2821 obj = env->
Global()->Get(v8_str(
"obj"));
2822 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
2823 CHECK_EQ(-1431655765, obj->ToInt32()->Value());
2824 CHECK(2863311531u == obj->ToUint32()->Value());
2832 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
2833 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
2834 CHECK(!obj->IsInt32());
2835 CHECK(!obj->IsUint32());
2837 CompileRun(
"var obj = -1234567890123;");
2838 obj = env->
Global()->Get(v8_str(
"obj"));
2839 CHECK(!obj->IsInt32());
2840 CHECK(!obj->IsUint32());
2842 CompileRun(
"var obj = 42;");
2843 obj = env->
Global()->Get(v8_str(
"obj"));
2844 CHECK(obj->IsInt32());
2845 CHECK(obj->IsUint32());
2847 CompileRun(
"var obj = -37;");
2848 obj = env->
Global()->Get(v8_str(
"obj"));
2849 CHECK(obj->IsInt32());
2850 CHECK(!obj->IsUint32());
2852 CompileRun(
"var obj = 0x81234567;");
2853 obj = env->
Global()->Get(v8_str(
"obj"));
2854 CHECK(!obj->IsInt32());
2855 CHECK(obj->IsUint32());
2857 CompileRun(
"var obj = 42.3;");
2858 obj = env->
Global()->Get(v8_str(
"obj"));
2859 CHECK(!obj->IsInt32());
2860 CHECK(!obj->IsUint32());
2862 CompileRun(
"var obj = -5726623061.75;");
2863 obj = env->
Global()->Get(v8_str(
"obj"));
2864 CHECK(!obj->IsInt32());
2865 CHECK(!obj->IsUint32());
2867 CompileRun(
"var obj = 0.0;");
2868 obj = env->
Global()->Get(v8_str(
"obj"));
2869 CHECK(obj->IsInt32());
2870 CHECK(obj->IsUint32());
2872 CompileRun(
"var obj = -0.0;");
2873 obj = env->
Global()->Get(v8_str(
"obj"));
2874 CHECK(!obj->IsInt32());
2875 CHECK(!obj->IsUint32());
2883 "function TestClass() { };"
2884 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
2885 "var obj = new TestClass();");
2886 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
2890 Local<Value> to_string_result = obj->ToString();
2891 CHECK(to_string_result.IsEmpty());
2892 CheckUncle(&try_catch);
2894 Local<Value> to_number_result = obj->ToNumber();
2895 CHECK(to_number_result.IsEmpty());
2896 CheckUncle(&try_catch);
2898 Local<Value> to_integer_result = obj->ToInteger();
2899 CHECK(to_integer_result.IsEmpty());
2900 CheckUncle(&try_catch);
2902 Local<Value> to_uint32_result = obj->ToUint32();
2903 CHECK(to_uint32_result.IsEmpty());
2904 CheckUncle(&try_catch);
2906 Local<Value> to_int32_result = obj->ToInt32();
2907 CHECK(to_int32_result.IsEmpty());
2908 CheckUncle(&try_catch);
2910 Local<Value> to_object_result =
v8::Undefined()->ToObject();
2911 CHECK(to_object_result.IsEmpty());
2915 int32_t int32_value = obj->Int32Value();
2917 CheckUncle(&try_catch);
2919 uint32_t uint32_value = obj->Uint32Value();
2921 CheckUncle(&try_catch);
2923 double number_value = obj->NumberValue();
2925 CheckUncle(&try_catch);
2927 int64_t integer_value = obj->IntegerValue();
2928 CHECK_EQ(0.0, static_cast<double>(integer_value));
2929 CheckUncle(&try_catch);
2951 Local<ObjectTemplate> templ = ObjectTemplate::New();
2952 templ->Set(v8_str(
"ThrowFromC"),
2956 "var thrown = false;"
2962 Local<Value> thrown = context->
Global()->Get(v8_str(
"thrown"));
2963 CHECK(thrown->BooleanValue());
2969 Local<ObjectTemplate> templ = ObjectTemplate::New();
2970 templ->Set(v8_str(
"ThrowFromC"),
2974 CompileRun(
"ThrowFromC();");
2988 Local<ObjectTemplate> templ = ObjectTemplate::New();
2989 templ->Set(v8_str(
"CCatcher"),
2992 Local<Value> result = CompileRun(
"try {"
2994 " CCatcher('throw 7;');"
2999 CHECK(result->IsTrue());
3003 static void check_reference_error_message(
3006 const char* reference_error =
"Uncaught ReferenceError: asdf is not defined";
3007 CHECK(message->
Get()->Equals(v8_str(reference_error)));
3021 TEST(APIThrowMessageOverwrittenToString) {
3024 Local<ObjectTemplate> templ = ObjectTemplate::New();
3027 CompileRun(
"asdf;");
3028 CompileRun(
"var limit = {};"
3029 "limit.valueOf = fail;"
3030 "Error.stackTraceLimit = limit;");
3032 CompileRun(
"Array.prototype.pop = fail;");
3033 CompileRun(
"Object.prototype.hasOwnProperty = fail;");
3034 CompileRun(
"Object.prototype.toString = function f() { return 'Yikes'; }");
3035 CompileRun(
"Number.prototype.toString = function f() { return 'Yikes'; }");
3036 CompileRun(
"String.prototype.toString = function f() { return 'Yikes'; }");
3037 CompileRun(
"ReferenceError.prototype.toString ="
3038 " function() { return 'Whoops' }");
3039 CompileRun(
"asdf;");
3040 CompileRun(
"ReferenceError.prototype.constructor.name = void 0;");
3041 CompileRun(
"asdf;");
3042 CompileRun(
"ReferenceError.prototype.constructor = void 0;");
3043 CompileRun(
"asdf;");
3044 CompileRun(
"ReferenceError.prototype.__proto__ = new Object();");
3045 CompileRun(
"asdf;");
3046 CompileRun(
"ReferenceError.prototype = new Object();");
3047 CompileRun(
"asdf;");
3050 CompileRun(
"ReferenceError.prototype.constructor = new Object();"
3051 "ReferenceError.prototype.constructor.name = 1;"
3052 "Number.prototype.toString = function() { return 'Whoops'; };"
3053 "ReferenceError.prototype.toString = Object.prototype.toString;");
3054 CompileRun(
"asdf;");
3062 message_received =
true;
3067 message_received =
false;
3070 Local<ObjectTemplate> templ = ObjectTemplate::New();
3071 templ->Set(v8_str(
"ThrowFromC"),
3074 CompileRun(
"ThrowFromC();");
3075 CHECK(message_received);
3080 TEST(APIThrowMessageAndVerboseTryCatch) {
3081 message_received =
false;
3084 Local<ObjectTemplate> templ = ObjectTemplate::New();
3085 templ->Set(v8_str(
"ThrowFromC"),
3090 Local<Value> result = CompileRun(
"ThrowFromC();");
3092 CHECK(result.IsEmpty());
3093 CHECK(message_received);
3098 TEST(APIStackOverflowAndVerboseTryCatch) {
3099 message_received =
false;
3105 Local<Value> result = CompileRun(
"function foo() { foo(); } foo();");
3107 CHECK(result.IsEmpty());
3108 CHECK(message_received);
3115 Local<ObjectTemplate> templ = ObjectTemplate::New();
3116 templ->Set(v8_str(
"ThrowFromC"),
3121 Local<Script> script
3122 = Script::Compile(v8_str(
"ThrowFromC(); throw 'panama';"));
3123 Local<Value> result = script->Run();
3124 CHECK(result.IsEmpty());
3126 String::AsciiValue exception_value(try_catch.
Exception());
3127 CHECK_EQ(
"konto", *exception_value);
3135 int count = args[0]->Int32Value();
3136 int cInterval = args[2]->Int32Value();
3140 Local<v8::Object> global = Context::GetCurrent()->Global();
3141 Local<Value> fun = global->Get(v8_str(
"JSThrowCountDown"));
3146 if (count % cInterval == 0) {
3148 Local<Value> result = fun.
As<Function>()->Call(global, 4, argv);
3149 int expected = args[3]->Int32Value();
3152 CHECK(result.IsEmpty());
3153 CHECK(!i::Isolate::Current()->has_scheduled_exception());
3159 return fun.As<Function>()->Call(global, 4, argv);
3168 bool equality = args[0]->BooleanValue();
3169 int count = args[1]->Int32Value();
3170 int expected = args[2]->Int32Value();
3184 CompileRun(
"(function() {"
3186 " eval('asldkf (*&^&*^');"
3217 Local<ObjectTemplate> templ = ObjectTemplate::New();
3219 templ->Set(v8_str(
"CThrowCountDown"),
3223 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
3224 " if (count == 0) throw 'FromJS';"
3225 " if (count % jsInterval == 0) {"
3227 " var value = CThrowCountDown(count - 1,"
3231 " check(false, count, expected);"
3234 " check(true, count, expected);"
3237 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);"
3240 Local<Function> fun =
3241 Local<Function>::Cast(context->
Global()->Get(v8_str(
"JSThrowCountDown")));
3248 fun->Call(fun, argc, a0);
3252 fun->Call(fun, argc, a1);
3256 fun->Call(fun, argc, a2);
3260 fun->Call(fun, argc, a3);
3264 fun->Call(fun, argc, a4);
3268 fun->Call(fun, argc, a5);
3281 Local<ObjectTemplate> templ = ObjectTemplate::New();
3285 "function Run(obj) {"
3291 " return 'no exception';"
3293 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
3310 Script::Compile(v8_str(
"throw 10"))->Run();
3315 Script::Compile(v8_str(
"throw 0"))->Run();
3326 Script::Compile(v8_str(
"var o = {}; with (o) { throw 42; }"))->Run();
3336 CompileRun(
"function f(k) { try { this[k]; } finally { return 0; } };");
3337 CompileRun(
"f({toString: function() { throw 42; }});");
3352 v8_str(
"native_with_try_catch"),
3358 " throw new Error('a');\n"
3360 " native_with_try_catch();\n"
3370 CHECK(v8_str(
"a")->Equals(v8_str(
"a")));
3371 CHECK(!v8_str(
"a")->Equals(v8_str(
"b")));
3373 CHECK_EQ(v8_str(
"a"), v8_str(
"a"));
3374 CHECK_NE(v8_str(
"a"), v8_str(
"b"));
3380 CHECK(v8_str(
"a")->StrictEquals(v8_str(
"a")));
3381 CHECK(!v8_str(
"a")->StrictEquals(v8_str(
"b")));
3382 CHECK(!v8_str(
"5")->StrictEquals(v8_num(5)));
3383 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
3384 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
3385 CHECK(v8_num(0)->StrictEquals(v8_num(-0)));
3387 CHECK(!not_a_number->StrictEquals(not_a_number));
3393 CHECK(alias->StrictEquals(obj));
3401 Local<Script> script = Script::Compile(v8_str(
"x"));
3402 for (
int i = 0; i < 10; i++)
3408 const AccessorInfo& info) {
3410 CHECK_EQ(info.Data(), v8_str(
"donut"));
3418 Local<ObjectTemplate> templ = ObjectTemplate::New();
3419 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3421 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3422 Local<Script> script = Script::Compile(v8_str(
"obj.x"));
3423 for (
int i = 0; i < 10; i++) {
3424 Local<Value> result = script->Run();
3431 Local<ObjectTemplate> templ = ObjectTemplate::New();
3432 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3434 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3437 Local<Script> script_desc
3438 = Script::Compile(v8_str(
"var prop = Object.getOwnPropertyDescriptor( "
3440 "prop.configurable;"));
3441 Local<Value> result = script_desc->Run();
3442 CHECK_EQ(result->BooleanValue(),
true);
3445 Local<Script> script_define
3446 = Script::Compile(v8_str(
"var desc = { get: function(){return 42; },"
3447 " configurable: true };"
3448 "Object.defineProperty(obj, 'x', desc);"
3450 result = script_define->Run();
3454 result = script_desc->Run();
3455 CHECK_EQ(result->BooleanValue(),
true);
3459 = Script::Compile(v8_str(
"var desc = { get: function(){return 43; },"
3460 " configurable: false };"
3461 "Object.defineProperty(obj, 'x', desc);"
3463 result = script_define->Run();
3465 result = script_desc->Run();
3466 CHECK_EQ(result->BooleanValue(),
false);
3470 result = script_define->Run();
3471 CHECK(try_catch.HasCaught());
3472 String::AsciiValue exception_value(try_catch.Exception());
3473 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3478 Local<ObjectTemplate> templ = ObjectTemplate::New();
3479 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3481 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3483 Local<Script> script_desc = Script::Compile(v8_str(
"var prop ="
3484 "Object.getOwnPropertyDescriptor( "
3486 "prop.configurable;"));
3487 Local<Value> result = script_desc->Run();
3488 CHECK_EQ(result->BooleanValue(),
true);
3490 Local<Script> script_define =
3491 Script::Compile(v8_str(
"var desc = {get: function(){return 42; },"
3492 " configurable: true };"
3493 "Object.defineProperty(obj, 'x', desc);"
3495 result = script_define->Run();
3499 result = script_desc->Run();
3500 CHECK_EQ(result->BooleanValue(),
true);
3504 Script::Compile(v8_str(
"var desc = {get: function(){return 43; },"
3505 " configurable: false };"
3506 "Object.defineProperty(obj, 'x', desc);"
3508 result = script_define->Run();
3510 result = script_desc->Run();
3512 CHECK_EQ(result->BooleanValue(),
false);
3515 result = script_define->Run();
3516 CHECK(try_catch.HasCaught());
3517 String::AsciiValue exception_value(try_catch.Exception());
3518 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3530 Local<ObjectTemplate> templ = ObjectTemplate::New();
3533 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3534 CompileRun(
"var obj2 = {};");
3536 CHECK(CompileRun(
"obj1.x")->IsUndefined());
3537 CHECK(CompileRun(
"obj2.x")->IsUndefined());
3539 CHECK(GetGlobalProperty(&context,
"obj1")->
3542 ExpectString(
"obj1.x",
"x");
3543 CHECK(CompileRun(
"obj2.x")->IsUndefined());
3545 CHECK(GetGlobalProperty(&context,
"obj2")->
3548 ExpectString(
"obj1.x",
"x");
3549 ExpectString(
"obj2.x",
"x");
3551 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3552 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3554 CompileRun(
"Object.defineProperty(obj1, 'x',"
3555 "{ get: function() { return 'y'; }, configurable: true })");
3557 ExpectString(
"obj1.x",
"y");
3558 ExpectString(
"obj2.x",
"x");
3560 CompileRun(
"Object.defineProperty(obj2, 'x',"
3561 "{ get: function() { return 'y'; }, configurable: true })");
3563 ExpectString(
"obj1.x",
"y");
3564 ExpectString(
"obj2.x",
"y");
3566 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3567 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3569 CHECK(GetGlobalProperty(&context,
"obj1")->
3571 CHECK(GetGlobalProperty(&context,
"obj2")->
3574 ExpectString(
"obj1.x",
"x");
3575 ExpectString(
"obj2.x",
"x");
3577 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3578 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3581 CompileRun(
"Object.defineProperty(obj1, 'x',"
3582 "{ get: function() { return 'z'; }, configurable: false })");
3583 CompileRun(
"Object.defineProperty(obj2, 'x',"
3584 "{ get: function() { return 'z'; }, configurable: false })");
3586 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3587 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3589 ExpectString(
"obj1.x",
"z");
3590 ExpectString(
"obj2.x",
"z");
3592 CHECK(!GetGlobalProperty(&context,
"obj1")->
3594 CHECK(!GetGlobalProperty(&context,
"obj2")->
3597 ExpectString(
"obj1.x",
"z");
3598 ExpectString(
"obj2.x",
"z");
3604 Local<ObjectTemplate> templ = ObjectTemplate::New();
3607 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3608 CompileRun(
"var obj2 = {};");
3619 ExpectString(
"obj1.x",
"x");
3620 ExpectString(
"obj2.x",
"x");
3622 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3623 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3625 CHECK(!GetGlobalProperty(&context,
"obj1")->
3627 CHECK(!GetGlobalProperty(&context,
"obj2")->
3632 CompileRun(
"Object.defineProperty(obj1, 'x',"
3633 "{get: function() { return 'func'; }})");
3635 String::AsciiValue exception_value(try_catch.
Exception());
3636 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3640 CompileRun(
"Object.defineProperty(obj2, 'x',"
3641 "{get: function() { return 'func'; }})");
3643 String::AsciiValue exception_value(try_catch.
Exception());
3644 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3650 const AccessorInfo& info) {
3652 CHECK_EQ(info.Data(), v8_str(
"donut"));
3660 Local<ObjectTemplate> templ = ObjectTemplate::New();
3663 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3664 CompileRun(
"var obj2 = {};");
3675 ExpectString(
"obj1[239]",
"239");
3676 ExpectString(
"obj2[239]",
"239");
3677 ExpectString(
"obj1['239']",
"239");
3678 ExpectString(
"obj2['239']",
"239");
3685 static void SetXValue(Local<String> name,
3687 const AccessorInfo& info) {
3689 CHECK_EQ(info.Data(), v8_str(
"donut"));
3698 Local<ObjectTemplate> templ = ObjectTemplate::New();
3699 templ->SetAccessor(v8_str(
"x"), GetXValue, SetXValue, v8_str(
"donut"));
3701 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3702 Local<Script> script = Script::Compile(v8_str(
"obj.x = 4"));
3703 for (
int i = 0; i < 10; i++) {
3714 const AccessorInfo& info) {
3716 CHECK(info.Data()->IsUndefined());
3723 Local<ObjectTemplate> templ = ObjectTemplate::New();
3724 templ->SetNamedPropertyHandler(XPropertyGetter);
3726 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3727 Local<Script> script = Script::Compile(v8_str(
"obj.x"));
3728 for (
int i = 0; i < 10; i++) {
3729 Local<Value> result = script->Run();
3737 Local<ObjectTemplate> templ = ObjectTemplate::New();
3738 templ->SetNamedPropertyHandler(XPropertyGetter);
3741 context->
Global()->Set(v8_str(
"interceptor_obj"), templ->NewInstance());
3742 Local<Script> script = Script::Compile(v8_str(
"interceptor_obj.x"));
3743 for (
int i = 0; i < 10; i++) {
3744 Local<Value> result = script->Run();
3752 Local<Value> result =
3753 CompileRun(
"function get_x(o) { return o.x; };"
3754 "var obj = { x : 42, y : 0 };"
3756 "for (var i = 0; i < 10; i++) get_x(obj);"
3757 "interceptor_obj.x = 42;"
3758 "interceptor_obj.y = 10;"
3759 "delete interceptor_obj.y;"
3760 "get_x(interceptor_obj)");
3771 Local<ObjectTemplate> templ = ObjectTemplate::New();
3772 templ->SetNamedPropertyHandler(XPropertyGetter);
3775 context1->Global()->Set(v8_str(
"interceptor_obj"),
object);
3778 CompileRun(
"interceptor_obj.y = 0;"
3779 "delete interceptor_obj.y;");
3786 context2->
Global()->Set(v8_str(
"interceptor_obj"),
object);
3787 Local<Value> result =
3788 CompileRun(
"function get_x(o) { return o.x; }"
3789 "interceptor_obj.x = 42;"
3790 "for (var i=0; i != 10; i++) {"
3791 " get_x(interceptor_obj);"
3793 "get_x(interceptor_obj)");
3801 CompileRun(
"var obj = { x : 0 }; delete obj.x;");
3809 const AccessorInfo& info) {
3823 = function_template->InstanceTemplate();
3824 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
3826 context->
Global()->Set(v8_str(
"F"), function_template->GetFunction());
3828 CompileRun(
"var o = new F(); o.x = 23;");
3830 Local<Value> result = CompileRun(
"o = new F(); o.x");
3831 CHECK_EQ(result->Int32Value(), 23);
3836 const AccessorInfo& info) {
3847 const AccessorInfo& info) {
3858 Local<ObjectTemplate> templ = ObjectTemplate::New();
3859 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
3860 IndexedPropertySetter);
3862 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3863 Local<Script> getter_script = Script::Compile(v8_str(
3864 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"));
3865 Local<Script> setter_script = Script::Compile(v8_str(
3866 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
3869 Local<Script> interceptor_setter_script = Script::Compile(v8_str(
3870 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});"
3873 Local<Script> interceptor_getter_script = Script::Compile(v8_str(
3875 Local<Value> result = getter_script->Run();
3877 result = setter_script->Run();
3879 result = interceptor_setter_script->Run();
3881 result = interceptor_getter_script->Run();
3888 const AccessorInfo& info) {
3900 const AccessorInfo& info) {
3910 const AccessorInfo& info) {
3912 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
3913 "keys = new Array(); keys[125000] = 1;"
3914 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
3915 "keys.length = 25; keys;"));
3916 Local<Value> result = indexed_property_names_script->Run();
3925 Local<ObjectTemplate> templ = ObjectTemplate::New();
3926 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
3927 UnboxedDoubleIndexedPropertySetter,
3932 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3934 Local<Script> create_unboxed_double_script = Script::Compile(v8_str(
3935 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } "
3937 "for (x in obj) {key_count++;};"
3939 Local<Value> result = create_unboxed_double_script->Run();
3940 CHECK(result->ToObject()->HasRealIndexedProperty(2000));
3941 Local<Script> key_count_check = Script::Compile(v8_str(
3943 result = key_count_check->Run();
3949 const AccessorInfo& info) {
3951 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
3953 " return arguments;"
3955 "keys = f(0, 1, 2, 3);"
3957 Local<Value> result = indexed_property_names_script->Run();
3964 const AccessorInfo& info) {
3977 Local<ObjectTemplate> templ = ObjectTemplate::New();
3978 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
3984 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3985 Local<Script> create_args_script =
3986 Script::Compile(v8_str(
3987 "var key_count = 0;"
3988 "for (x in obj) {key_count++;} key_count;"));
3989 Local<Value> result = create_args_script->Run();
3996 const AccessorInfo& info) {
4003 Local<ObjectTemplate> templ = ObjectTemplate::New();
4004 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4007 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4010 const char* fast_case_code =
4011 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
4012 ExpectString(fast_case_code,
"0");
4015 const char* slow_case_code =
4016 "obj.x = 1; delete obj.x;"
4017 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
4018 ExpectString(slow_case_code,
"1");
4024 Local<ObjectTemplate> templ = ObjectTemplate::New();
4025 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4028 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4033 " for (var i = 0; i < 100; i++) {"
4035 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
4041 ExpectString(code,
"PASSED");
4047 Local<ObjectTemplate> templ = ObjectTemplate::New();
4048 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4051 Local<v8::Object> obj = templ->NewInstance();
4053 context->
Global()->Set(v8_str(
"obj"), obj);
4057 " for (var i = 0; i < 100; i++) {"
4059 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
4065 ExpectString(code,
"PASSED");
4070 i::FLAG_allow_natives_syntax =
true;
4072 Local<ObjectTemplate> templ = ObjectTemplate::New();
4073 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4076 Local<v8::Object> obj = templ->NewInstance();
4077 context->
Global()->Set(v8_str(
"obj"), obj);
4081 " for (var i = 0; i < 100; i++) {"
4082 " var expected = i;"
4084 " %EnableAccessChecks(obj);"
4085 " expected = undefined;"
4088 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4089 " if (i == 5) %DisableAccessChecks(obj);"
4095 ExpectString(code,
"PASSED");
4101 Local<ObjectTemplate> templ = ObjectTemplate::New();
4102 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4105 Local<v8::Object> obj = templ->NewInstance();
4106 context->
Global()->Set(v8_str(
"obj"), obj);
4110 " for (var i = 0; i < 100; i++) {"
4112 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4118 ExpectString(code,
"PASSED");
4124 Local<ObjectTemplate> templ = ObjectTemplate::New();
4125 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4128 Local<v8::Object> obj = templ->NewInstance();
4129 context->
Global()->Set(v8_str(
"obj"), obj);
4133 " for (var i = 0; i < 100; i++) {"
4134 " var expected = i;"
4138 " expected = undefined;"
4141 " /* probe minimal Smi number on 32-bit platforms */"
4142 " key = -(1 << 30);"
4143 " expected = undefined;"
4146 " /* probe minimal Smi number on 64-bit platforms */"
4148 " expected = undefined;"
4150 " var v = obj[key];"
4151 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4157 ExpectString(code,
"PASSED");
4163 Local<ObjectTemplate> templ = ObjectTemplate::New();
4164 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4167 Local<v8::Object> obj = templ->NewInstance();
4168 context->
Global()->Set(v8_str(
"obj"), obj);
4172 " for (var i = 0; i < 100; i++) {"
4173 " var expected = i;"
4177 " expected = undefined;"
4179 " var v = obj[key];"
4180 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4186 ExpectString(code,
"PASSED");
4192 Local<ObjectTemplate> templ = ObjectTemplate::New();
4193 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4196 Local<v8::Object> obj = templ->NewInstance();
4197 context->
Global()->Set(v8_str(
"obj"), obj);
4200 "var original = obj;"
4202 " for (var i = 0; i < 100; i++) {"
4203 " var expected = i;"
4205 " obj = {50: 'foobar'};"
4206 " expected = 'foobar';"
4209 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4210 " if (i == 50) obj = original;"
4216 ExpectString(code,
"PASSED");
4222 Local<ObjectTemplate> templ = ObjectTemplate::New();
4223 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4226 Local<v8::Object> obj = templ->NewInstance();
4227 context->
Global()->Set(v8_str(
"obj"), obj);
4230 "var original = obj;"
4232 " for (var i = 0; i < 100; i++) {"
4233 " var expected = i;"
4236 " expected = undefined;"
4239 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4240 " if (i == 5) obj = original;"
4246 ExpectString(code,
"PASSED");
4252 Local<ObjectTemplate> templ = ObjectTemplate::New();
4253 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4256 Local<v8::Object> obj = templ->NewInstance();
4257 context->
Global()->Set(v8_str(
"obj"), obj);
4260 "var o = {__proto__: obj};"
4262 " for (var i = 0; i < 100; i++) {"
4264 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4270 ExpectString(code,
"PASSED");
4279 Local<String> password = v8_str(
"Password");
4285 global0->
Set(v8_str(
"custom"), v8_num(1234));
4286 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
4290 context1->SetSecurityToken(password);
4292 global1->
Set(v8_str(
"custom"), v8_num(1234));
4294 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
4295 CHECK_EQ(1234, global1->
Get(v8_str(
"custom"))->Int32Value());
4299 context2->SetSecurityToken(password);
4302 CHECK_EQ(0, global1->
Get(v8_str(
"custom"))->Int32Value());
4303 CHECK_EQ(0, global2->
Get(v8_str(
"custom"))->Int32Value());
4322 proto0->
Set(v8_str(
"custom"), v8_num(1234));
4333 CHECK(!proto1->Has(v8_str(
"custom")));
4346 Local<String> source = v8_str(
"Object.prototype.obj = 1234;"
4347 "Array.prototype.arr = 4567;"
4351 Local<Script> script0 = Script::Compile(source);
4352 CHECK_EQ(8901.0, script0->Run()->NumberValue());
4355 Local<Script> script1 = Script::Compile(source);
4356 CHECK_EQ(8901.0, script1->Run()->NumberValue());
4364 Local<v8::FunctionTemplate> desc =
4366 desc->InstanceTemplate()->MarkAsUndetectable();
4368 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4369 env->
Global()->Set(v8_str(
"undetectable"), obj);
4371 ExpectString(
"undetectable.toString()",
"[object Object]");
4372 ExpectString(
"typeof undetectable",
"undefined");
4373 ExpectString(
"typeof(undetectable)",
"undefined");
4374 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
4375 ExpectBoolean(
"typeof undetectable == 'object'",
false);
4376 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
4377 ExpectBoolean(
"!undetectable",
true);
4379 ExpectObject(
"true&&undetectable", obj);
4380 ExpectBoolean(
"false&&undetectable",
false);
4381 ExpectBoolean(
"true||undetectable",
true);
4382 ExpectObject(
"false||undetectable", obj);
4384 ExpectObject(
"undetectable&&true", obj);
4385 ExpectObject(
"undetectable&&false", obj);
4386 ExpectBoolean(
"undetectable||true",
true);
4387 ExpectBoolean(
"undetectable||false",
false);
4389 ExpectBoolean(
"undetectable==null",
true);
4390 ExpectBoolean(
"null==undetectable",
true);
4391 ExpectBoolean(
"undetectable==undefined",
true);
4392 ExpectBoolean(
"undefined==undetectable",
true);
4393 ExpectBoolean(
"undetectable==undetectable",
true);
4396 ExpectBoolean(
"undetectable===null",
false);
4397 ExpectBoolean(
"null===undetectable",
false);
4398 ExpectBoolean(
"undetectable===undefined",
false);
4399 ExpectBoolean(
"undefined===undetectable",
false);
4400 ExpectBoolean(
"undetectable===undetectable",
true);
4408 Local<v8::FunctionTemplate> desc =
4410 desc->InstanceTemplate()->MarkAsUndetectable();
4412 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4413 env->
Global()->Set(v8_str(
"undetectable"), obj);
4415 ExpectBoolean(
"undefined == void 0",
true);
4416 ExpectBoolean(
"undetectable == void 0",
true);
4417 ExpectBoolean(
"null == void 0",
true);
4418 ExpectBoolean(
"undefined === void 0",
true);
4419 ExpectBoolean(
"undetectable === void 0",
false);
4420 ExpectBoolean(
"null === void 0",
false);
4422 ExpectBoolean(
"void 0 == undefined",
true);
4423 ExpectBoolean(
"void 0 == undetectable",
true);
4424 ExpectBoolean(
"void 0 == null",
true);
4425 ExpectBoolean(
"void 0 === undefined",
true);
4426 ExpectBoolean(
"void 0 === undetectable",
false);
4427 ExpectBoolean(
"void 0 === null",
false);
4429 ExpectString(
"(function() {"
4431 " return x === void 0;"
4433 " return e.toString();"
4436 "ReferenceError: x is not defined");
4437 ExpectString(
"(function() {"
4439 " return void 0 === x;"
4441 " return e.toString();"
4444 "ReferenceError: x is not defined");
4452 Local<v8::FunctionTemplate> desc =
4454 desc->InstanceTemplate()->MarkAsUndetectable();
4456 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4457 env->
Global()->Set(v8_str(
"undetectable"), obj);
4459 Local<String> source = v8_str(
"undetectable.x = 42;"
4462 Local<Script> script = Script::Compile(source);
4466 ExpectBoolean(
"Object.isExtensible(undetectable)",
true);
4468 source = v8_str(
"Object.preventExtensions(undetectable);");
4469 script = Script::Compile(source);
4471 ExpectBoolean(
"Object.isExtensible(undetectable)",
false);
4473 source = v8_str(
"undetectable.y = 2000;");
4474 script = Script::Compile(source);
4476 ExpectBoolean(
"undetectable.y == undefined",
true);
4485 Local<String> obj = String::NewUndetectable(
"foo");
4486 env->
Global()->Set(v8_str(
"undetectable"), obj);
4488 ExpectString(
"undetectable",
"foo");
4489 ExpectString(
"typeof undetectable",
"undefined");
4490 ExpectString(
"typeof(undetectable)",
"undefined");
4491 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
4492 ExpectBoolean(
"typeof undetectable == 'string'",
false);
4493 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
4494 ExpectBoolean(
"!undetectable",
true);
4496 ExpectObject(
"true&&undetectable", obj);
4497 ExpectBoolean(
"false&&undetectable",
false);
4498 ExpectBoolean(
"true||undetectable",
true);
4499 ExpectObject(
"false||undetectable", obj);
4501 ExpectObject(
"undetectable&&true", obj);
4502 ExpectObject(
"undetectable&&false", obj);
4503 ExpectBoolean(
"undetectable||true",
true);
4504 ExpectBoolean(
"undetectable||false",
false);
4506 ExpectBoolean(
"undetectable==null",
true);
4507 ExpectBoolean(
"null==undetectable",
true);
4508 ExpectBoolean(
"undetectable==undefined",
true);
4509 ExpectBoolean(
"undefined==undetectable",
true);
4510 ExpectBoolean(
"undetectable==undetectable",
true);
4513 ExpectBoolean(
"undetectable===null",
false);
4514 ExpectBoolean(
"null===undetectable",
false);
4515 ExpectBoolean(
"undetectable===undefined",
false);
4516 ExpectBoolean(
"undefined===undetectable",
false);
4517 ExpectBoolean(
"undetectable===undetectable",
true);
4522 i::FLAG_allow_natives_syntax =
true;
4526 Local<String> obj = String::NewUndetectable(
"foo");
4527 env->
Global()->Set(v8_str(
"undetectable"), obj);
4528 env->
Global()->Set(v8_str(
"detectable"), v8_str(
"bar"));
4531 "function testBranch() {"
4532 " if (!%_IsUndetectableObject(undetectable)) throw 1;"
4533 " if (%_IsUndetectableObject(detectable)) throw 2;"
4535 "function testBool() {"
4536 " var b1 = !%_IsUndetectableObject(undetectable);"
4537 " var b2 = %_IsUndetectableObject(detectable);"
4542 "%OptimizeFunctionOnNextCall(testBranch);"
4543 "%OptimizeFunctionOnNextCall(testBool);"
4544 "for (var i = 0; i < 10; i++) {"
4553 template <
typename T>
static void USE(
T) { }
4557 static inline void PersistentHandles() {
4558 USE(PersistentHandles);
4559 Local<String> str = v8_str(
"foo");
4562 Local<Script> scr = Script::Compile(v8_str(
""));
4565 Local<ObjectTemplate> templ = ObjectTemplate::New();
4580 Local<ObjectTemplate> global_template = ObjectTemplate::New();
4581 global_template->Set(v8_str(
"JSNI_Log"),
4584 Context::Scope context_scope(context);
4585 Script::Compile(v8_str(
"JSNI_Log('LOG')"))->Run();
4590 static const char* kSimpleExtensionSource =
4599 const char* extension_names[] = {
"simpletest" };
4602 Context::Scope lock(context);
4608 static const char* kEmbeddedExtensionSource =
4609 "function Ret54321(){return 54321;}~~@@$"
4610 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
4611 static const int kEmbeddedExtensionSourceValidLen = 34;
4617 kEmbeddedExtensionSource));
4618 const char* extension_names[] = {
"srclentest_fail" };
4626 for (
int source_len = kEmbeddedExtensionSourceValidLen - 1;
4627 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
4632 kEmbeddedExtensionSource, 0, 0,
4634 const char* extension_names[1] = { extension_name.
start() };
4637 if (source_len == kEmbeddedExtensionSourceValidLen) {
4638 Context::Scope lock(context);
4649 static const char* kEvalExtensionSource1 =
4650 "function UseEval1() {"
4652 " return eval('x');"
4656 static const char* kEvalExtensionSource2 =
4660 " return eval('x');"
4662 " this.UseEval2 = e;"
4670 const char* extension_names[] = {
"evaltest1",
"evaltest2" };
4673 Context::Scope lock(context);
4676 result = Script::Compile(v8_str(
"UseEval2()"))->Run();
4681 static const char* kWithExtensionSource1 =
4682 "function UseWith1() {"
4684 " with({x:87}) { return x; }"
4689 static const char* kWithExtensionSource2 =
4693 " with ({x:87}) { return x; }"
4695 " this.UseWith2 = e;"
4703 const char* extension_names[] = {
"withtest1",
"withtest2" };
4706 Context::Scope lock(context);
4709 result = Script::Compile(v8_str(
"UseWith2()"))->Run();
4716 Extension* extension =
new Extension(
"autotest", kSimpleExtensionSource);
4717 extension->set_auto_enable(
true);
4720 Context::Scope lock(context);
4726 static const char* kSyntaxErrorInExtensionSource =
4735 kSyntaxErrorInExtensionSource));
4736 const char* extension_names[] = {
"syntaxerror" };
4743 static const char* kExceptionInExtensionSource =
4752 kExceptionInExtensionSource));
4753 const char* extension_names[] = {
"exception" };
4760 static const char* kNativeCallInExtensionSource =
4761 "function call_runtime_last_index_of(x) {"
4762 " return %StringLastIndexOf(x, 'bob', 10);"
4766 static const char* kNativeCallTest =
4767 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
4773 kNativeCallInExtensionSource));
4774 const char* extension_names[] = {
"nativecall" };
4777 Context::Scope lock(context);
4788 : Extension(name, source),
4797 if (args.
Length() >= 1)
return (args[0]);
4807 const char* name =
"nativedecl";
4809 "native function foo();"));
4810 const char* extension_names[] = { name };
4813 Context::Scope lock(context);
4821 const char* name =
"nativedeclerr";
4824 "native\nfunction foo();"));
4825 const char* extension_names[] = { name };
4834 const char* name =
"nativedeclerresc";
4839 "nativ\\u0065 function foo();"));
4840 const char* extension_names[] = { name };
4847 static void CheckDependencies(
const char* name,
const char* expected) {
4851 CHECK_EQ(String::New(expected), context->
Global()->Get(v8_str(
"loaded")));
4863 static const char* kEDeps[] = {
"D" };
4865 static const char* kDDeps[] = {
"B",
"C" };
4867 static const char* kBCDeps[] = {
"A" };
4871 CheckDependencies(
"A",
"undefinedA");
4872 CheckDependencies(
"B",
"undefinedAB");
4873 CheckDependencies(
"C",
"undefinedAC");
4874 CheckDependencies(
"D",
"undefinedABCD");
4875 CheckDependencies(
"E",
"undefinedABCDE");
4877 static const char* exts[2] = {
"C",
"E" };
4880 CHECK_EQ(v8_str(
"undefinedACBDE"), context->
Global()->Get(v8_str(
"loaded")));
4884 static const char* kExtensionTestScript =
4885 "native function A();"
4886 "native function B();"
4887 "native function C();"
4889 " if (i == 0) return A();"
4890 " if (i == 1) return B();"
4891 " if (i == 2) return C();"
4898 args.
This()->Set(v8_str(
"data"), args.
Data());
4913 static int lookup_count = 0;
4917 if (name->
Equals(v8_str(
"A"))) {
4919 }
else if (name->
Equals(v8_str(
"B"))) {
4921 }
else if (name->
Equals(v8_str(
"C"))) {
4932 static const char* exts[1] = {
"functiontest" };
4945 static const char* exts[1] = {
"functiontest" };
4948 for (
int i = 0; i < 10; i++) {
4952 Script::Compile(v8_str(
"(new A()).data"))->Run());
4954 Script::Compile(v8_str(
"(new B()).data"))->Run());
4956 Script::Compile(v8_str(
"(new C()).data"))->Run());
4961 static const char* last_location;
4962 static const char* last_message;
4964 if (last_location ==
NULL) {
4965 last_location = location;
4966 last_message = message;
4976 static const char* aDeps[] = {
"B" };
4978 static const char* bDeps[] = {
"A" };
4980 last_location =
NULL;
4988 static const char* js_code_causing_huge_string_flattening =
4990 "for (var i = 0; i < 30; i++) {"
5006 Local<Script> script =
5007 Script::Compile(String::New(js_code_causing_huge_string_flattening));
5008 last_location =
NULL;
5029 Script::Compile(v8_str(
"throw Error()"))->Run();
5053 return Local<Script>(*script_);
5070 const AccessorInfo& info) {
5079 prev->Set(v8_str(
"next"), obj);
5095 const char* extension_list[] = {
"v8/gc" };
5098 Context::Scope context_scope(context);
5101 context->Global()->Set(v8_str(
"whammy"), interceptor);
5104 "for (var i = 0; i < 10000; i++) {"
5105 " var obj = whammy.length;"
5106 " if (last) last.next = obj;"
5121 *(
reinterpret_cast<bool*
>(data)) =
true;
5127 Context::Scope context_scope(context);
5136 bool object_a_disposed =
false;
5137 object_a.
MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
5139 HEAP->PerformScavenge();
5140 CHECK(object_a_disposed);
5144 static void InvokeScavenge() {
5145 HEAP->PerformScavenge();
5149 static void InvokeMarkSweep() {
5157 *(
reinterpret_cast<bool*
>(data)) =
true;
5165 *(
reinterpret_cast<bool*
>(data)) =
true;
5172 Context::Scope context_scope(context);
5174 static const int kNumberOfGCTypes = 2;
5176 {&ForceScavenge, &ForceMarkSweep};
5178 typedef void (*GCInvoker)();
5179 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
5181 for (
int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
5182 for (
int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
5188 bool disposed =
false;
5189 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]);
5190 object.MarkIndependent();
5191 invoke_gc[outer_gc]();
5200 *(
reinterpret_cast<bool*
>(data)) =
true;
5206 Context::Scope context_scope(context);
5214 object->Set(y_str, y_str);
5216 bool revived =
false;
5217 object.MakeWeak(&revived, &RevivingCallback);
5218 object.MarkIndependent();
5219 HEAP->PerformScavenge();
5221 HEAP->CollectAllGarbage(
true);
5226 CHECK(object->Get(y_str)->Equals(y_str));
5253 args_fun = context->
Global()->Get(v8_str(
"f")).
As<Function>();
5254 v8_compile(
"f(1, 2, 3)")->Run();
5259 const AccessorInfo&) {
5265 const AccessorInfo&) {
5271 const AccessorInfo&) {
5272 if (!name->Equals(v8_str(
"foo"))) {
5301 CHECK(v8_compile(
"delete k.foo")->Run()->IsFalse());
5302 CHECK(v8_compile(
"delete k.bar")->Run()->IsTrue());
5304 CHECK_EQ(v8_compile(
"k.foo")->Run(), v8_str(
"foo"));
5305 CHECK(v8_compile(
"k.bar")->Run()->IsUndefined());
5307 CHECK(v8_compile(
"delete k[2]")->Run()->IsFalse());
5308 CHECK(v8_compile(
"delete k[4]")->Run()->IsTrue());
5310 CHECK_EQ(v8_compile(
"k[2]")->Run(), v8_num(2));
5311 CHECK(v8_compile(
"k[4]")->Run()->IsUndefined());
5317 if (name->Equals(v8_str(
"foo")) ||
5318 name->Equals(v8_str(
"bar")) ||
5319 name->Equals(v8_str(
"baz"))) {
5364 "k[4294967295] = 0;"
5366 "k[4294967296] = 0;"
5370 "k[30000000000] = 0;"
5373 "for (var prop in k) {"
5374 " result.push(prop);"
5413 static v8::Handle<Value> PGetter(Local<String> name,
const AccessorInfo& info) {
5417 CHECK_EQ(info.Holder(), global->
Get(v8_str(
"o1")));
5418 if (name->Equals(v8_str(
"p1"))) {
5420 }
else if (name->Equals(v8_str(
"p2"))) {
5422 }
else if (name->Equals(v8_str(
"p3"))) {
5424 }
else if (name->Equals(v8_str(
"p4"))) {
5436 "o1.__proto__ = { };"
5437 "var o2 = { __proto__: o1 };"
5438 "var o3 = { __proto__: o2 };"
5439 "var o4 = { __proto__: o3 };"
5440 "for (var i = 0; i < 10; i++) o4.p4;"
5441 "for (var i = 0; i < 10; i++) o3.p3;"
5442 "for (var i = 0; i < 10; i++) o2.p2;"
5443 "for (var i = 0; i < 10; i++) o1.p1;");
5448 const AccessorInfo& info) {
5452 CHECK_EQ(info.Holder(), global->
Get(v8_str(
"o1")));
5453 if (name->Equals(v8_str(
"p1"))) {
5455 }
else if (name->Equals(v8_str(
"p2"))) {
5457 }
else if (name->Equals(v8_str(
"p3"))) {
5459 }
else if (name->Equals(v8_str(
"p4"))) {
5483 p_getter_count2 = 0;
5495 for (
int i = 0; i < 100; i++) {
5499 context->
Global()->Set(v8_str(
"o2"), obj);
5501 Script::Compile(v8_str(
"o.__proto__ === o2.__proto__"))->Run();
5503 context->
Global()->Set(v8_str(
"o"), obj);
5510 if (*a == 0 && *b == 0)
return 0;
5511 if (*a != *b)
return 0 + *a - *b;
5520 if (n-- == 0)
return 0;
5521 if (*a == 0 && *b == 0)
return 0;
5522 if (*a != *b)
return 0 + *a - *b;
5530 int len = str->Utf8Length();
5534 len = str->Utf8Length();
5546 const int kStride = 4;
5549 "for (var i = 0; i < 0xd800; i += 4) {"
5550 " left = left + String.fromCharCode(i);"
5554 "for (var i = 0; i < 0xd800; i += 4) {"
5555 " right = String.fromCharCode(i) + right;"
5558 Handle<String> left_tree = global->
Get(v8_str(
"left")).As<String>();
5559 Handle<String> right_tree = global->
Get(v8_str(
"right")).As<String>();
5562 CHECK_EQ(0xd800 / kStride, left_tree->Length());
5563 CHECK_EQ(0xd800 / kStride, right_tree->Length());
5566 char utf8buf[0xd800 * 3];
5571 memset(utf8buf, 0x1, 1000);
5572 len = str2->
WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen);
5575 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5577 memset(utf8buf, 0x1, 1000);
5578 len = str2->
WriteUtf8(utf8buf, 8, &charlen);
5581 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203\1", 9));
5583 memset(utf8buf, 0x1, 1000);
5584 len = str2->
WriteUtf8(utf8buf, 7, &charlen);
5587 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5589 memset(utf8buf, 0x1, 1000);
5590 len = str2->
WriteUtf8(utf8buf, 6, &charlen);
5593 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5595 memset(utf8buf, 0x1, 1000);
5596 len = str2->
WriteUtf8(utf8buf, 5, &charlen);
5599 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5601 memset(utf8buf, 0x1, 1000);
5602 len = str2->
WriteUtf8(utf8buf, 4, &charlen);
5605 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
5607 memset(utf8buf, 0x1, 1000);
5608 len = str2->
WriteUtf8(utf8buf, 3, &charlen);
5611 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
5613 memset(utf8buf, 0x1, 1000);
5614 len = str2->
WriteUtf8(utf8buf, 2, &charlen);
5617 CHECK_EQ(0, strncmp(utf8buf,
"ab\1", 3));
5619 memset(utf8buf, 0x1,
sizeof(utf8buf));
5622 (0x80 + (0x800 - 0x80) * 2 + (0xd800 - 0x800) * 3) / kStride;
5624 len = left_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
5626 CHECK_EQ(0xd800 / kStride, charlen);
5627 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[utf8_expected - 3]));
5628 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[utf8_expected - 2]));
5630 static_cast<unsigned char>(utf8buf[utf8_expected - 1]));
5631 CHECK_EQ(1, utf8buf[utf8_expected]);
5633 memset(utf8buf, 0x1,
sizeof(utf8buf));
5636 len = right_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
5638 CHECK_EQ(0xd800 / kStride, charlen);
5639 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[0]));
5640 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[1]));
5641 CHECK_EQ(0xc0 - kStride, static_cast<unsigned char>(utf8buf[2]));
5642 CHECK_EQ(1, utf8buf[utf8_expected]);
5644 memset(buf, 0x1,
sizeof(buf));
5645 memset(wbuf, 0x1,
sizeof(wbuf));
5648 len = str->
Write(wbuf);
5651 uint16_t answer1[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5652 CHECK_EQ(0, StrCmp16(answer1, wbuf));
5654 memset(buf, 0x1,
sizeof(buf));
5655 memset(wbuf, 0x1,
sizeof(wbuf));
5658 len = str->
Write(wbuf, 0, 4);
5660 CHECK_EQ(0, strncmp(
"abcd\1", buf, 5));
5661 uint16_t answer2[] = {
'a',
'b',
'c',
'd', 0x101};
5662 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5));
5664 memset(buf, 0x1,
sizeof(buf));
5665 memset(wbuf, 0x1,
sizeof(wbuf));
5668 len = str->
Write(wbuf, 0, 5);
5670 CHECK_EQ(0, strncmp(
"abcde\1", buf, 6));
5671 uint16_t answer3[] = {
'a',
'b',
'c',
'd',
'e', 0x101};
5672 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6));
5674 memset(buf, 0x1,
sizeof(buf));
5675 memset(wbuf, 0x1,
sizeof(wbuf));
5678 len = str->
Write(wbuf, 0, 6);
5681 uint16_t answer4[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5682 CHECK_EQ(0, StrCmp16(answer4, wbuf));
5684 memset(buf, 0x1,
sizeof(buf));
5685 memset(wbuf, 0x1,
sizeof(wbuf));
5688 len = str->
Write(wbuf, 4, -1);
5692 CHECK_EQ(0, StrCmp16(answer5, wbuf));
5694 memset(buf, 0x1,
sizeof(buf));
5695 memset(wbuf, 0x1,
sizeof(wbuf));
5698 len = str->
Write(wbuf, 4, 6);
5701 CHECK_EQ(0, StrCmp16(answer5, wbuf));
5703 memset(buf, 0x1,
sizeof(buf));
5704 memset(wbuf, 0x1,
sizeof(wbuf));
5707 len = str->
Write(wbuf, 4, 1);
5709 CHECK_EQ(0, strncmp(
"e\1", buf, 2));
5711 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2));
5713 memset(buf, 0x1,
sizeof(buf));
5714 memset(wbuf, 0x1,
sizeof(wbuf));
5717 len = str->
Write(wbuf, 3, 1);
5719 CHECK_EQ(0, strncmp(
"d\1", buf, 2));
5721 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2));
5723 memset(wbuf, 0x1,
sizeof(wbuf));
5725 len = str->
Write(wbuf, 0, 6, String::NO_NULL_TERMINATION);
5728 uint16_t answer8a[] = {
'a',
'b',
'c',
'd',
'e'};
5729 uint16_t answer8b[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5730 CHECK_EQ(0, StrNCmp16(answer8a, wbuf, 5));
5731 CHECK_NE(0, StrCmp16(answer8b, wbuf));
5733 CHECK_EQ(0, StrCmp16(answer8b, wbuf));
5735 memset(buf, 0x1,
sizeof(buf));
5737 len = str->
WriteAscii(buf, 0, 6, String::NO_NULL_TERMINATION);
5740 CHECK_EQ(0, strncmp(
"abcde", buf, 5));
5745 memset(utf8buf, 0x1,
sizeof(utf8buf));
5747 len = str2->
WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen,
5748 String::NO_NULL_TERMINATION);
5752 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203", 8));
5753 CHECK_NE(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5755 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5759 static void Utf16Helper(
5762 const char* lengths_name,
5764 Local<v8::Array> a =
5765 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
5766 Local<v8::Array> alens =
5767 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
5768 for (
int i = 0; i < len; i++) {
5769 Local<v8::String>
string =
5770 Local<v8::String>::Cast(a->Get(i));
5771 Local<v8::Number> expected_len =
5772 Local<v8::Number>::Cast(alens->Get(i));
5773 CHECK_EQ(expected_len->Value() !=
string->Length(),
5774 string->MayContainNonAscii());
5776 CHECK_EQ(static_cast<int>(expected_len->Value()), length);
5781 static uint16_t StringGet(Handle<String> str,
int index) {
5784 return istring->Get(index);
5788 static void WriteUtf8Helper(
5791 const char* lengths_name,
5793 Local<v8::Array> b =
5794 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
5795 Local<v8::Array> alens =
5796 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
5799 for (
int i = 0; i < len; i++) {
5800 Local<v8::String>
string =
5801 Local<v8::String>::Cast(b->Get(i));
5802 Local<v8::Number> expected_len =
5803 Local<v8::Number>::Cast(alens->Get(i));
5804 int utf8_length =
static_cast<int>(expected_len->Value());
5805 for (
int j = utf8_length + 1; j >= 0; j--) {
5806 memset(reinterpret_cast<void*>(&buffer), 42,
sizeof(buffer));
5807 memset(reinterpret_cast<void*>(&buffer2), 42,
sizeof(buffer2));
5810 string->WriteUtf8(buffer, j, &nchars, String::NO_OPTIONS);
5812 string->WriteUtf8(buffer2, j, &nchars, String::NO_NULL_TERMINATION);
5813 CHECK_GE(utf8_length + 1, utf8_written);
5814 CHECK_GE(utf8_length, utf8_written2);
5815 for (
int k = 0; k < utf8_written2; k++) {
5818 CHECK(nchars * 3 >= utf8_written - 1);
5819 CHECK(nchars <= utf8_written);
5820 if (j == utf8_length + 1) {
5821 CHECK_EQ(utf8_written2, utf8_length);
5822 CHECK_EQ(utf8_written2 + 1, utf8_written);
5824 CHECK_EQ(buffer[utf8_written], 42);
5825 if (j > utf8_length) {
5826 if (utf8_written != 0)
CHECK_EQ(buffer[utf8_written - 1], 0);
5827 if (utf8_written > 1)
CHECK_NE(buffer[utf8_written - 2], 42);
5828 Handle<String> roundtrip = v8_str(buffer);
5829 CHECK(roundtrip->Equals(
string));
5831 if (utf8_written != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
5833 if (utf8_written2 != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
5835 uint16_t trail = StringGet(
string, nchars - 1);
5836 uint16_t lead = StringGet(
string, nchars - 2);
5837 if (((lead & 0xfc00) == 0xd800) &&
5838 ((trail & 0xfc00) == 0xdc00)) {
5839 unsigned char u1 = buffer2[utf8_written2 - 4];
5840 unsigned char u2 = buffer2[utf8_written2 - 3];
5841 unsigned char u3 = buffer2[utf8_written2 - 2];
5842 unsigned char u4 = buffer2[utf8_written2 - 1];
5847 uint32_t c = 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
5849 CHECK_EQ((u3 & 0x3f), ((c >> 6) & 0x3f));
5850 CHECK_EQ((u2 & 0x3f), ((c >> 12) & 0x3f));
5863 "var pad = '01234567890123456789';"
5865 "var plens = [20, 3, 3];"
5866 "p.push('01234567890123456789');"
5867 "var lead = 0xd800;"
5868 "var trail = 0xdc00;"
5869 "p.push(String.fromCharCode(0xd800));"
5870 "p.push(String.fromCharCode(0xdc00));"
5875 "for (var i = 0; i < 3; i++) {"
5876 " p[1] = String.fromCharCode(lead++);"
5877 " for (var j = 0; j < 3; j++) {"
5878 " p[2] = String.fromCharCode(trail++);"
5879 " a.push(p[i] + p[j]);"
5880 " b.push(p[i] + p[j]);"
5881 " c.push(p[i] + p[j]);"
5882 " alens.push(plens[i] + plens[j]);"
5890 "for (var m = 0; m < 9; m++) {"
5891 " for (var n = 0; n < 9; n++) {"
5892 " a2.push(a[m] + a[n]);"
5893 " b2.push(b[m] + b[n]);"
5894 " var newc = 'x' + c[m] + c[n] + 'y';"
5895 " c2.push(newc.substring(1, newc.length - 1));"
5896 " var utf = alens[m] + alens[n];"
5899 " if ((m % 3) == 1 && n >= 6) utf -= 2;"
5900 " a2lens.push(utf);"
5903 Utf16Helper(context,
"a",
"alens", 9);
5904 Utf16Helper(context,
"a2",
"a2lens", 81);
5905 WriteUtf8Helper(context,
"b",
"alens", 9);
5906 WriteUtf8Helper(context,
"b2",
"a2lens", 81);
5907 WriteUtf8Helper(context,
"c2",
"a2lens", 81);
5911 static bool SameSymbol(Handle<String>
s1, Handle<String>
s2) {
5914 return *is1 == *is2;
5918 static void SameSymbolHelper(
const char* a,
const char* b) {
5921 CHECK(SameSymbol(symbol1, symbol2));
5931 CHECK(SameSymbol(symbol1, symbol2));
5933 SameSymbolHelper(
"\360\220\220\205",
5934 "\355\240\201\355\260\205");
5935 SameSymbolHelper(
"\355\240\201\355\260\206",
5936 "\360\220\220\206");
5937 SameSymbolHelper(
"x\360\220\220\205",
5938 "x\355\240\201\355\260\205");
5939 SameSymbolHelper(
"x\355\240\201\355\260\206",
5940 "x\360\220\220\206");
5942 "var sym0 = 'benedictus';"
5943 "var sym0b = 'S\303\270ren';"
5944 "var sym1 = '\355\240\201\355\260\207';"
5945 "var sym2 = '\360\220\220\210';"
5946 "var sym3 = 'x\355\240\201\355\260\207';"
5947 "var sym4 = 'x\360\220\220\210';"
5948 "if (sym1.length != 2) throw sym1;"
5949 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
5950 "if (sym2.length != 2) throw sym2;"
5951 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);"
5952 "if (sym3.length != 3) throw sym3;"
5953 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);"
5954 "if (sym4.length != 3) throw sym4;"
5955 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);");
5963 Local<Value>
s0 = global->
Get(v8_str(
"sym0"));
5964 Local<Value> s0b = global->
Get(v8_str(
"sym0b"));
5965 Local<Value> s1 = global->
Get(v8_str(
"sym1"));
5966 Local<Value> s2 = global->
Get(v8_str(
"sym2"));
5967 Local<Value>
s3 = global->
Get(v8_str(
"sym3"));
5968 Local<Value>
s4 = global->
Get(v8_str(
"sym4"));
5969 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0))));
5970 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b))));
5971 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1))));
5972 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2))));
5973 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3))));
5974 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4))));
5986 str = v8_str(
"42asdf");
5989 str = v8_str(
"-42");
5992 str = v8_str(
"4294967295");
6019 CHECK(reference_error->IsObject());
6022 CHECK(syntax_error->IsObject());
6025 CHECK(type_error->IsObject());
6028 CHECK(error->IsObject());
6033 static v8::Handle<Value> YGetter(Local<String> name,
const AccessorInfo& info) {
6039 static void YSetter(Local<String> name,
6041 const AccessorInfo& info) {
6042 if (info.This()->Has(name)) {
6043 info.This()->Delete(name);
6045 info.This()->Set(name, value);
6055 context->
Global()->Set(v8_str(
"holder"), holder);
6057 "holder.y = 11; holder.y = 12; holder.y");
6074 for (
int i = 0; i < 10; i++) {
6088 static bool g_security_callback_result =
false;
6089 static bool NamedSecurityTestCallback(Local<v8::Object> global,
6092 Local<Value> data) {
6098 return g_security_callback_result;
6102 static bool IndexedSecurityTestCallback(Local<v8::Object> global,
6105 Local<Value> data) {
6111 return g_security_callback_result;
6115 static int trouble_nesting = 0;
6121 Local<v8::Object> arg_this = Context::GetCurrent()->Global();
6122 Local<Value> trouble_callee = (trouble_nesting == 3) ?
6123 arg_this->Get(v8_str(
"trouble_callee")) :
6124 arg_this->Get(v8_str(
"trouble_caller"));
6125 CHECK(trouble_callee->IsFunction());
6126 return Function::Cast(*trouble_callee)->Call(arg_this, 0,
NULL);
6130 static int report_count = 0;
6147 global->
Set(v8_str(
"trouble"), fun->GetFunction());
6149 Script::Compile(v8_str(
"function trouble_callee() {"
6153 "function trouble_caller() {"
6156 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
6157 CHECK(trouble->IsFunction());
6158 Local<Value> trouble_callee = global->
Get(v8_str(
"trouble_callee"));
6159 CHECK(trouble_callee->IsFunction());
6160 Local<Value> trouble_caller = global->
Get(v8_str(
"trouble_caller"));
6161 CHECK(trouble_caller->IsFunction());
6162 Function::Cast(*trouble_caller)->Call(global, 0,
NULL);
6167 static const char* script_resource_name =
"ExceptionInNativeScript.js";
6173 CHECK_EQ(script_resource_name, *name);
6176 CHECK_EQ(
" new o.foo();", *source_line);
6186 global->
Set(v8_str(
"trouble"), fun->GetFunction());
6188 Script::Compile(v8_str(
"function trouble() {\n"
6192 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
6193 CHECK(trouble->IsFunction());
6194 Function::Cast(*trouble)->Call(global, 0,
NULL);
6199 TEST(CompilationErrorUsingTryCatchHandler) {
6203 Script::Compile(v8_str(
"This doesn't &*&@#$&*^ compile."));
6209 TEST(TryCatchFinallyUsingTryCatchHandler) {
6213 Script::Compile(v8_str(
"try { throw ''; } catch (e) {}"))->Run();
6215 Script::Compile(v8_str(
"try { throw ''; } finally {}"))->Run();
6218 Script::Compile(v8_str(
"(function() {"
6219 "try { throw ''; } finally { return; }"
6222 Script::Compile(v8_str(
"(function()"
6223 " { try { throw ''; } finally { throw 0; }"
6234 IndexedSecurityTestCallback);
6237 Context::New(
NULL, global_template);
6243 global0->
Set(v8_str(
"0"), v8_num(999));
6253 Context::New(
NULL, global_template);
6257 global1->
Set(v8_str(
"othercontext"), global0);
6260 v8_compile(
"othercontext.foo = 222; othercontext[0] = 888;");
6270 { g_security_callback_result =
true;
6274 global2->
Set(v8_str(
"othercontext"), global0);
6276 v8_compile(
"othercontext.foo = 333; othercontext[0] = 888;");
6297 Local<Value>
foo = v8_str(
"foo");
6298 Local<Value>
bar = v8_str(
"bar");
6304 Script::Compile(v8_str(
"spy=function(){return spy;}"))->Run();
6305 Local<Value> spy = env1->
Global()->Get(v8_str(
"spy"));
6306 CHECK(spy->IsFunction());
6309 Script::Compile(v8_str(
"spy2=function(){return new this.Array();}"))->Run();
6310 Local<Value> spy2 = env1->
Global()->Get(v8_str(
"spy2"));
6311 CHECK(spy2->IsFunction());
6315 env2->SetSecurityToken(foo);
6317 Context::Scope scope_env2(env2);
6318 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0,
NULL);
6319 CHECK(result->IsFunction());
6323 env2->SetSecurityToken(bar);
6324 Context::Scope scope_env2(env2);
6328 Function::Cast(*spy2)->Call(env2->Global(), 0,
NULL);
6345 { Context::Scope scope(other);
6346 other_object = other->Global()->Get(v8_str(
"Object"));
6347 other->Global()->Set(v8_num(42), v8_num(87));
6350 current->
Global()->Set(v8_str(
"other"), other->Global());
6351 CHECK(v8_compile(
"other")->Run()->Equals(other->Global()));
6358 for (
int i = 0; i < 5; i++) {
6359 CHECK(!access_other0->Run()->Equals(other_object));
6360 CHECK(access_other0->Run()->IsUndefined());
6361 CHECK(!access_other1->Run()->Equals(v8_num(87)));
6362 CHECK(access_other1->Run()->IsUndefined());
6368 v8_compile(
"function F() { };"
6369 "F.prototype = other;"
6370 "var f = new F();")->Run();
6373 for (
int j = 0; j < 5; j++) {
6374 CHECK(!access_f0->Run()->Equals(other_object));
6375 CHECK(access_f0->Run()->IsUndefined());
6376 CHECK(!access_f1->Run()->Equals(v8_num(87)));
6377 CHECK(access_f1->Run()->IsUndefined());
6383 { Context::Scope scope(other);
6384 other->Global()->Set(v8_str(
"__proto__"), current->
Global());
6389 current->
Global()->Set(v8_str(
"foo"), v8_num(100));
6390 current->
Global()->Set(v8_num(99), v8_num(101));
6393 Local<Script> access_f2 = v8_compile(
"f.foo");
6394 Local<Script> access_f3 = v8_compile(
"f[99]");
6395 for (
int k = 0; k < 5; k++) {
6396 CHECK(!access_f2->Run()->Equals(v8_num(100)));
6397 CHECK(access_f2->Run()->IsUndefined());
6398 CHECK(!access_f3->Run()->Equals(v8_num(101)));
6399 CHECK(access_f3->Run()->IsUndefined());
6410 Local<Value>
foo = v8_str(
"foo");
6411 Local<Value>
bar = v8_str(
"bar");
6415 env2->SetSecurityToken(foo);
6417 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6418 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6421 env2->SetSecurityToken(bar);
6423 Context::Scope scope_env2(env2);
6424 Local<Value> result =
6425 Script::Compile(v8_str(
"delete env1.prop"))->Run();
6426 CHECK(result->IsFalse());
6430 Local<Value> v = env1->
Global()->Get(v8_str(
"prop"));
6431 CHECK(v->IsNumber());
6443 Local<Value>
foo = v8_str(
"foo");
6444 Local<Value>
bar = v8_str(
"bar");
6448 env2->SetSecurityToken(foo);
6450 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6451 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6454 Local<String> test = v8_str(
"propertyIsEnumerable.call(env1, 'prop')");
6456 Context::Scope scope_env2(env2);
6457 Local<Value> result = Script::Compile(test)->Run();
6458 CHECK(result->IsTrue());
6462 env2->SetSecurityToken(bar);
6464 Context::Scope scope_env2(env2);
6465 Local<Value> result = Script::Compile(test)->Run();
6466 CHECK(result->IsFalse());
6478 Local<Value>
foo = v8_str(
"foo");
6479 Local<Value>
bar = v8_str(
"bar");
6483 env2->SetSecurityToken(foo);
6485 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6486 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6492 env2->SetSecurityToken(bar);
6494 Context::Scope scope_env2(env2);
6495 Local<Value> result =
6496 CompileRun(
"(function(){var obj = {'__proto__':env1};"
6497 "for (var p in obj)"
6498 " if (p == 'prop') return false;"
6499 "return true;})()");
6500 CHECK(result->IsTrue());
6511 Local<v8::Object> global1 = env1->
Global();
6513 Local<Value>
foo = v8_str(
"foo");
6517 env2->SetSecurityToken(foo);
6523 Local<v8::Object> global2 = env2->Global();
6525 CompileRun(
"function getProp() {return prop;}");
6527 env1->
Global()->Set(v8_str(
"getProp"),
6528 global2->Get(v8_str(
"getProp")));
6532 env2->DetachGlobal();
6534 CHECK(!env2->Global()->Equals(global2));
6538 env3->SetSecurityToken(v8_str(
"bar"));
6541 Local<v8::Object> global3 = env3->Global();
6543 CHECK(global3->Get(v8_str(
"prop"))->IsUndefined());
6544 CHECK(global3->Get(v8_str(
"getProp"))->IsUndefined());
6551 Local<Value> get_prop = global1->Get(v8_str(
"getProp"));
6552 CHECK(get_prop->IsFunction());
6554 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0,
NULL);
6555 CHECK(!try_catch.HasCaught());
6561 Local<Value> r = global3->Get(v8_str(
"prop2"));
6562 CHECK(r->IsUndefined());
6577 Local<Value>
foo = v8_str(
"foo");
6581 env2->SetSecurityToken(foo);
6590 env1->
Global()->Set(v8_str(
"other"), env2->Global());
6593 Local<Value> result = CompileRun(
"other.p");
6594 CHECK(result->IsInt32());
6595 CHECK_EQ(42, result->Int32Value());
6598 Local<v8::Object> global2 = env2->Global();
6599 env2->DetachGlobal();
6603 result = CompileRun(
"other.p");
6604 CHECK(result->IsUndefined());
6612 env3->SetSecurityToken(foo);
6621 result = CompileRun(
"other.p");
6622 CHECK(result->IsInt32());
6623 CHECK_EQ(24, result->Int32Value());
6626 env3->SetSecurityToken(v8_str(
"bar"));
6631 result = CompileRun(
"other.p");
6632 CHECK(result->IsUndefined());
6635 env3->DetachGlobal();
6636 env2->ReattachGlobal(global2);
6640 result = CompileRun(
"other.p");
6641 CHECK(result->IsInt32());
6642 CHECK_EQ(42, result->Int32Value());
6650 static bool NamedAccessBlocker(Local<v8::Object> global,
6653 Local<Value> data) {
6654 return Context::GetCurrent()->Global()->Equals(global) ||
6655 allowed_access_type[
type];
6659 static bool IndexedAccessBlocker(Local<v8::Object> global,
6662 Local<Value> data) {
6663 return Context::GetCurrent()->Global()->Equals(global) ||
6664 allowed_access_type[
type];
6668 static int g_echo_value = -1;
6670 const AccessorInfo& info) {
6671 return v8_num(g_echo_value);
6675 static void EchoSetter(Local<String> name,
6677 const AccessorInfo&) {
6678 if (value->IsNumber())
6679 g_echo_value = value->Int32Value();
6684 const AccessorInfo& info) {
6690 static void UnreachableSetter(Local<String>, Local<Value>,
6691 const AccessorInfo&) {
6701 IndexedAccessBlocker);
6705 v8_str(
"accessible_prop"),
6706 EchoGetter, EchoSetter,
6711 global_template->
SetAccessor(v8_str(
"blocked_prop"),
6712 UnreachableGetter, UnreachableSetter,
6724 "function getter() { return 'getter'; };\n"
6725 "function setter() { return 'setter'; }\n"
6726 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
6728 Local<Value> getter = global0->
Get(v8_str(
"getter"));
6729 Local<Value> setter = global0->
Get(v8_str(
"setter"));
6732 global0->
Set(239, v8_str(
"239"));
6736 "function el_getter() { return 'el_getter'; };\n"
6737 "function el_setter() { return 'el_setter'; };\n"
6738 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
6740 Local<Value> el_getter = global0->
Get(v8_str(
"el_getter"));
6741 Local<Value> el_setter = global0->
Get(v8_str(
"el_setter"));
6749 global1->
Set(v8_str(
"other"), global0);
6752 CompileRun(
"other.blocked_prop = 1");
6754 ExpectUndefined(
"other.blocked_prop");
6756 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
6757 ExpectFalse(
"propertyIsEnumerable.call(other, 'blocked_prop')");
6761 ExpectUndefined(
"other.blocked_prop");
6764 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
6766 ExpectTrue(
"propertyIsEnumerable.call(other, 'blocked_prop')");
6770 CompileRun(
"other[239] = 1");
6772 ExpectUndefined(
"other[239]");
6773 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239')");
6774 ExpectFalse(
"propertyIsEnumerable.call(other, '239')");
6778 ExpectUndefined(
"other[239]");
6780 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239').value");
6782 ExpectTrue(
"propertyIsEnumerable.call(other, '239')");
6786 CompileRun(
"other.js_accessor_p = 2");
6788 ExpectUndefined(
"other.js_accessor_p");
6790 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
6794 ExpectUndefined(
"other.js_accessor_p");
6796 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
6798 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
6800 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
6807 ExpectString(
"other.js_accessor_p",
"getter");
6809 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
6811 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
6813 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
6822 ExpectUndefined(
"other.js_accessor_p");
6824 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
6826 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
6828 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
6838 ExpectString(
"other.js_accessor_p",
"getter");
6840 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
6842 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
6844 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
6851 CompileRun(
"other[42] = 2");
6853 ExpectUndefined(
"other[42]");
6854 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42')");
6858 ExpectUndefined(
"other[42]");
6859 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
6860 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
6861 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
6868 ExpectString(
"other[42]",
"el_getter");
6869 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
6870 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
6871 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
6880 ExpectUndefined(
"other[42]");
6881 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
6882 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
6883 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
6893 ExpectString(
"other[42]",
"el_getter");
6894 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
6895 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
6896 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
6905 value = CompileRun(
"other.accessible_prop = 3");
6910 value = CompileRun(
"other.accessible_prop");
6915 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
6916 CHECK(value->IsNumber());
6919 value = CompileRun(
"propertyIsEnumerable.call(other, 'accessible_prop')");
6920 CHECK(value->IsTrue());
6925 CompileRun(
"(function(){var obj = {'__proto__':other};"
6926 "for (var p in obj)"
6927 " if (p == 'accessible_prop' || p == 'blocked_prop') {"
6930 "return true;})()");
6931 CHECK(value->IsTrue());
6945 IndexedAccessBlocker);
6949 v8_str(
"accessible_prop"),
6950 EchoGetter, EchoSetter,
6956 global_template->
SetAccessor(v8_str(
"blocked_prop"),
6957 UnreachableGetter, UnreachableSetter,
6970 global1->
Set(v8_str(
"other"), global0);
6973 ExpectTrue(
"Object.keys(other).indexOf('blocked_prop') == -1");
6975 ExpectUndefined(
"other.blocked_prop");
6978 CompileRun(
"Object.defineProperty(\n"
6979 " other, 'blocked_prop', {configurable: false})");
6980 ExpectUndefined(
"other.blocked_prop");
6982 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
6985 ExpectTrue(
"Object.isExtensible(other)");
6986 CompileRun(
"Object.preventExtensions(other)");
6987 ExpectTrue(
"Object.isExtensible(other)");
6990 CompileRun(
"Object.freeze(other)");
6991 ExpectTrue(
"Object.isExtensible(other)");
6993 CompileRun(
"Object.seal(other)");
6994 ExpectTrue(
"Object.isExtensible(other)");
6999 CompileRun(
"other.accessible_prop = 42");
7004 CompileRun(
"Object.defineProperty(other, 'accessible_prop', {value: -1})");
7005 value = CompileRun(
"other.accessible_prop == 42");
7010 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
7013 Local<Value> data) {
7018 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
7021 Local<Value> data) {
7032 GetOwnPropertyNamesIndexedBlocker);
7046 global1->
Set(v8_str(
"other"), global0);
7056 value = CompileRun(
"Object.getOwnPropertyNames(other).length == 0");
7059 value = CompileRun(
"Object.getOwnPropertyNames(object).length == 0");
7060 CHECK(value->IsTrue());
7071 result->
Set(0, v8_str(
"x"));
7082 NamedPropertyEnumerator);
7089 CompileRun(
"Object.getOwnPropertyNames(object).join(',')");
7095 const AccessorInfo& info) {
7118 global_template->
SetAccessor(v8_str(
"unreachable"),
7119 UnreachableGetter, 0,
7126 Local<v8::Object> global = context0->Global();
7128 global->Set(v8_str(
"accessible"), v8_num(11));
7136 global1->
Set(v8_str(
"other"), global);
7143 value = v8_compile(
"other.unreachable")->Run();
7144 CHECK(value->IsUndefined());
7153 static int named_access_count = 0;
7154 static int indexed_access_count = 0;
7156 static bool NamedAccessCounter(Local<v8::Object> global,
7159 Local<Value> data) {
7160 named_access_count++;
7165 static bool IndexedAccessCounter(Local<v8::Object> global,
7168 Local<Value> data) {
7169 indexed_access_count++;
7176 named_access_count = 0;
7177 indexed_access_count = 0;
7189 IndexedAccessCounter);
7190 Local<v8::Object>
object = object_template->
NewInstance();
7200 global1->
Set(v8_str(
"obj"),
object);
7205 CompileRun(
"function testProp(obj) {"
7206 " for (var i = 0; i < 10; i++) obj.prop = 1;"
7207 " for (var j = 0; j < 10; j++) obj.prop;"
7210 value = CompileRun(
"testProp(obj)");
7216 CompileRun(
"var p = 'prop';"
7217 "function testKeyed(obj) {"
7218 " for (var i = 0; i < 10; i++) obj[p] = 1;"
7219 " for (var j = 0; j < 10; j++) obj[p];"
7224 value = CompileRun(
"testKeyed(obj)");
7229 CompileRun(
"testKeyed({ a: 0 })");
7230 CompileRun(
"testKeyed({ b: 0 })");
7231 value = CompileRun(
"testKeyed(obj)");
7237 CompileRun(
"function testIndexed(obj) {"
7238 " for (var i = 0; i < 10; i++) obj[0] = 1;"
7239 " for (var j = 0; j < 10; j++) obj[0];"
7242 value = CompileRun(
"testIndexed(obj)");
7245 CHECK_EQ(21, indexed_access_count);
7247 CompileRun(
"testIndexed(new Array(1))");
7249 value = CompileRun(
"testIndexed(obj)");
7252 CHECK_EQ(42, indexed_access_count);
7256 CompileRun(
"obj.f = function() {}");
7257 CompileRun(
"function testCallNormal(obj) {"
7258 " for (var i = 0; i < 10; i++) obj.f();"
7260 CompileRun(
"testCallNormal(obj)");
7264 value = CompileRun(
"delete obj.prop");
7267 CompileRun(
"var o = { x: 0 }; delete o.x; testProp(o);");
7269 value = CompileRun(
"testProp(obj);");
7275 CompileRun(
"o.f = function() {}; testCallNormal(o)");
7278 value = CompileRun(
"testCallNormal(obj)");
7288 static bool NamedAccessFlatten(Local<v8::Object> global,
7291 Local<Value> data) {
7295 CHECK(name->IsString());
7297 memset(buf, 0x1,
sizeof(buf));
7298 len = name.As<String>()->WriteAscii(buf);
7303 memset(buf, 0x1,
sizeof(buf));
7304 len = name.As<String>()->Write(buf2);
7311 static bool IndexedAccessFlatten(Local<v8::Object> global,
7314 Local<Value> data) {
7325 named_access_count = 0;
7326 indexed_access_count = 0;
7338 IndexedAccessFlatten);
7339 Local<v8::Object>
object = object_template->
NewInstance();
7349 global1->
Set(v8_str(
"obj"),
object);
7353 value = v8_compile(
"var p = 'as' + 'df';")->Run();
7354 value = v8_compile(
"obj[p];")->Run();
7364 Local<String>,
const AccessorInfo&) {
7370 Local<String>, Local<Value> value,
const AccessorInfo&) {
7377 const AccessorInfo& info) {
7383 uint32_t, Local<Value> value,
const AccessorInfo&) {
7389 named_access_count = 0;
7390 indexed_access_count = 0;
7403 IndexedAccessCounter);
7405 AccessControlNamedSetter);
7407 AccessControlIndexedSetter);
7408 Local<v8::Object>
object = object_template->
NewInstance();
7418 global1->
Set(v8_str(
"obj"),
object);
7424 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x = 1;")->Run();
7425 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x;"
7431 value = v8_compile(
"var p = 'x';")->Run();
7432 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p] = 1;")->Run();
7433 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p];"
7441 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0] = 1;")->Run();
7442 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0];"
7446 CHECK_EQ(21, indexed_access_count);
7471 Local<ObjectTemplate> instance = t->InstanceTemplate();
7473 instance->Set(v8_str(
"x"), v8_num(42));
7474 instance->Set(v8_str(
"f"),
7477 Local<Value> o = t->GetFunction()->NewInstance();
7479 context->
Global()->Set(v8_str(
"i"), o);
7480 Local<Value> value = Script::Compile(v8_str(
"i.x"))->Run();
7483 value = Script::Compile(v8_str(
"i.f()"))->Run();
7489 GlobalObjectInstancePropertiesGet(Local<String> key,
const AccessorInfo&) {
7498 Local<Value> global_object;
7501 t->InstanceTemplate()->SetNamedPropertyHandler(
7502 GlobalObjectInstancePropertiesGet);
7504 instance_template->Set(v8_str(
"x"), v8_num(42));
7505 instance_template->Set(v8_str(
"f"),
7510 const char* script =
7511 "function wrapper(call) {"
7512 " var x = 0, y = 1;"
7513 " for (var i = 0; i < 1000; i++) {"
7519 "for (var i = 0; i < 17; i++) wrapper(false);"
7521 "try { wrapper(true); } catch (e) { thrown = 1; };"
7528 global_object = env->
Global();
7530 Local<Value> value = Script::Compile(v8_str(
"x"))->Run();
7532 value = Script::Compile(v8_str(
"f()"))->Run();
7534 value = Script::Compile(v8_str(script))->Run();
7541 Local<Value> value = Script::Compile(v8_str(
"x"))->Run();
7543 value = Script::Compile(v8_str(
"f()"))->Run();
7545 value = Script::Compile(v8_str(script))->Run();
7554 Local<Value> global_object;
7565 const char* script =
7566 "function bar(x, y) { try { } finally { } }"
7567 "function baz(x) { try { } finally { } }"
7568 "function bom(x) { try { } finally { } }"
7569 "function foo(x) { bar([x], bom(2)); }"
7570 "for (var i = 0; i < 10000; i++) foo(1);"
7578 global_object = env->
Global();
7579 foo = Script::Compile(v8_str(script))->Run();
7585 env->
Global()->Set(v8_str(
"foo"), foo);
7586 Script::Compile(v8_str(
"foo()"))->Run();
7597 static int shadow_y;
7598 static int shadow_y_setter_call_count;
7599 static int shadow_y_getter_call_count;
7602 static void ShadowYSetter(Local<String>, Local<Value>,
const AccessorInfo&) {
7603 shadow_y_setter_call_count++;
7609 const AccessorInfo& info) {
7611 shadow_y_getter_call_count++;
7612 return v8_num(shadow_y);
7617 const AccessorInfo& info) {
7623 const AccessorInfo&) {
7629 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
7636 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
7637 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
7638 Local<ObjectTemplate> proto = t->PrototypeTemplate();
7639 Local<ObjectTemplate> instance = t->InstanceTemplate();
7643 proto->Set(v8_str(
"f"),
7647 proto->Set(v8_str(
"x"), v8_num(12));
7649 instance->SetAccessor(v8_str(
"y"), ShadowYGetter, ShadowYSetter);
7651 Local<Value> o = t->GetFunction()->NewInstance();
7652 context->
Global()->Set(v8_str(
"__proto__"), o);
7654 Local<Value> value =
7655 Script::Compile(v8_str(
"this.propertyIsEnumerable(0)"))->Run();
7656 CHECK(value->IsBoolean());
7657 CHECK(!value->BooleanValue());
7659 value = Script::Compile(v8_str(
"x"))->Run();
7662 value = Script::Compile(v8_str(
"f()"))->Run();
7665 Script::Compile(v8_str(
"y = 43"))->Run();
7666 CHECK_EQ(1, shadow_y_setter_call_count);
7667 value = Script::Compile(v8_str(
"y"))->Run();
7668 CHECK_EQ(1, shadow_y_getter_call_count);
7678 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
7680 t1->SetHiddenPrototype(
true);
7681 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
7683 t2->SetHiddenPrototype(
true);
7684 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
7686 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
7688 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
7689 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
7690 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
7691 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
7694 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7695 o0->Set(v8_str(
"__proto__"), o1);
7696 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7697 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7698 o0->Set(v8_str(
"__proto__"), o2);
7699 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7700 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7701 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7702 o0->Set(v8_str(
"__proto__"), o3);
7703 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7704 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7705 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7706 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
7711 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
7712 CHECK(proto->IsObject());
7722 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
7724 t1->SetHiddenPrototype(
true);
7725 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
7727 t2->SetHiddenPrototype(
true);
7728 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
7730 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
7732 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
7733 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
7734 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
7735 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
7738 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7739 CHECK(o0->SetPrototype(o1));
7740 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7741 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7742 CHECK(o1->SetPrototype(o2));
7743 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7744 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7745 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7746 CHECK(o2->SetPrototype(o3));
7747 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7748 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7749 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7750 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
7755 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
7756 CHECK(proto->IsObject());
7760 Local<Value> proto0 = o0->GetPrototype();
7761 CHECK(proto0->IsObject());
7764 Local<Value> proto1 = o1->GetPrototype();
7765 CHECK(proto1->IsObject());
7768 Local<Value> proto2 = o2->GetPrototype();
7769 CHECK(proto2->IsObject());
7778 i::FLAG_allow_natives_syntax =
true;
7783 t1->SetHiddenPrototype(
true);
7784 t1->InstanceTemplate()->Set(v8_str(
"foo"), v8_num(1));
7786 t2->SetHiddenPrototype(
true);
7787 t2->InstanceTemplate()->Set(v8_str(
"fuz1"), v8_num(2));
7789 t2->InstanceTemplate()->Set(v8_str(
"fuz2"), v8_num(2));
7791 t3->SetHiddenPrototype(
true);
7792 t3->InstanceTemplate()->Set(v8_str(
"boo"), v8_num(3));
7794 t4->InstanceTemplate()->Set(v8_str(
"baz"), v8_num(4));
7798 for (
int i = 1; i <= 1000; i++) {
7800 t2->InstanceTemplate()->Set(v8_str(name_buf.
start()), v8_num(2));
7803 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
7804 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
7805 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
7806 Local<v8::Object> o4 = t4->GetFunction()->NewInstance();
7809 CHECK(o4->SetPrototype(o3));
7810 CHECK(o3->SetPrototype(o2));
7811 CHECK(o2->SetPrototype(o1));
7815 context->
Global()->Set(v8_str(
"obj"), o4);
7816 CompileRun(
"var names = %GetLocalPropertyNames(obj);");
7818 ExpectInt32(
"names.length", 1006);
7819 ExpectTrue(
"names.indexOf(\"baz\") >= 0");
7820 ExpectTrue(
"names.indexOf(\"boo\") >= 0");
7821 ExpectTrue(
"names.indexOf(\"foo\") >= 0");
7822 ExpectTrue(
"names.indexOf(\"fuz1\") >= 0");
7823 ExpectTrue(
"names.indexOf(\"fuz2\") >= 0");
7824 ExpectFalse(
"names[1005] == undefined");
7834 t1->ReadOnlyPrototype();
7835 context->
Global()->Set(v8_str(
"func1"), t1->GetFunction());
7839 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
7840 " return (descriptor['writable'] == false);"
7841 "})()")->BooleanValue());
7842 CHECK_EQ(42, CompileRun(
"func1.prototype.x")->Int32Value());
7844 CompileRun(
"func1.prototype = {}; func1.prototype.x")->Int32Value());
7848 context->
Global()->Set(v8_str(
"func2"), t2->GetFunction());
7852 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
7853 " return (descriptor['writable'] == true);"
7854 "})()")->BooleanValue());
7855 CHECK_EQ(42, CompileRun(
"func2.prototype.x")->Int32Value());
7865 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
7866 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
7868 CHECK(o0->SetPrototype(o1));
7872 CHECK(!o1->SetPrototype(o0));
7873 CHECK(!try_catch.HasCaught());
7874 ASSERT(!i::Isolate::Current()->has_pending_exception());
7876 CHECK_EQ(42, CompileRun(
"function f() { return 42; }; f()")->Int32Value());
7884 "function Foo() { };"
7885 "function Throw() { throw 5; };"
7887 "x.__defineSetter__('set', Throw);"
7888 "x.__defineGetter__('get', Throw);");
7889 Local<v8::Object> x =
7890 Local<v8::Object>::Cast(context->
Global()->Get(v8_str(
"x")));
7893 x->Get(v8_str(
"get"));
7895 x->Get(v8_str(
"get"));
7897 x->Get(v8_str(
"get"));
7899 x->Get(v8_str(
"get"));
7907 templ->SetClassName(v8_str(
"Fun"));
7908 Local<Function> cons = templ->GetFunction();
7909 context->
Global()->Set(v8_str(
"Fun"), cons);
7910 Local<v8::Object> inst = cons->NewInstance();
7912 CHECK(obj->IsJSObject());
7913 Local<Value> value = CompileRun(
"(new Fun()).constructor === Fun");
7914 CHECK(value->BooleanValue());
7918 static Handle<Value> ConstructorCallback(
const Arguments& args) {
7922 if (args.IsConstructCall()) {
7923 Local<Object> Holder = args.Holder();
7924 This = Object::New();
7925 Local<Value> proto = Holder->GetPrototype();
7926 if (proto->IsObject()) {
7927 This->SetPrototype(proto);
7933 This->Set(v8_str(
"a"), args[0]);
7938 static Handle<Value> FakeConstructorCallback(
const Arguments& args) {
7949 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
7950 Local<Object> instance = instance_template->NewInstance();
7951 context->
Global()->Set(v8_str(
"obj"), instance);
7957 value = CompileRun(
"(function() { var o = new obj(28); return o.a; })()");
7959 CHECK(value->IsInt32());
7962 Local<Value> args1[] = { v8_num(28) };
7963 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1);
7964 CHECK(value_obj1->IsObject());
7966 value = object1->Get(v8_str(
"a"));
7967 CHECK(value->IsInt32());
7973 "(function() { var o = new obj('tipli'); return o.a; })()");
7975 CHECK(value->IsString());
7976 String::AsciiValue string_value1(value->ToString());
7979 Local<Value> args2[] = { v8_str(
"tipli") };
7980 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2);
7981 CHECK(value_obj2->IsObject());
7983 value = object2->Get(v8_str(
"a"));
7985 CHECK(value->IsString());
7986 String::AsciiValue string_value2(value->ToString());
7990 value = CompileRun(
"(function() { var o = new obj(true); return o.a; })()");
7992 CHECK(value->IsBoolean());
7993 CHECK_EQ(
true, value->BooleanValue());
7995 Handle<Value> args3[] = {
v8::True() };
7996 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3);
7997 CHECK(value_obj3->IsObject());
7999 value = object3->Get(v8_str(
"a"));
8001 CHECK(value->IsBoolean());
8002 CHECK_EQ(
true, value->BooleanValue());
8006 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4);
8007 CHECK(value_obj4->IsObject());
8009 value = object4->Get(v8_str(
"a"));
8011 CHECK(value->IsUndefined());
8014 Handle<Value> args5[] = {
v8::Null() };
8015 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5);
8016 CHECK(value_obj5->IsObject());
8018 value = object5->Get(v8_str(
"a"));
8020 CHECK(value->IsNull());
8025 Local<Object> instance = instance_template->NewInstance();
8026 context->
Global()->Set(v8_str(
"obj2"), instance);
8031 value = CompileRun(
"new obj2(28)");
8033 String::AsciiValue exception_value1(try_catch.
Exception());
8034 CHECK_EQ(
"TypeError: object is not a function", *exception_value1);
8037 Local<Value> args[] = { v8_num(29) };
8038 value = instance->CallAsConstructor(1, args);
8040 String::AsciiValue exception_value2(try_catch.
Exception());
8041 CHECK_EQ(
"TypeError: #<Object> is not a function", *exception_value2);
8047 instance_template->SetCallAsFunctionHandler(
ThrowValue);
8048 Local<Object> instance = instance_template->NewInstance();
8049 context->
Global()->Set(v8_str(
"obj3"), instance);
8054 value = CompileRun(
"new obj3(22)");
8056 String::AsciiValue exception_value1(try_catch.
Exception());
8060 Local<Value> args[] = { v8_num(23) };
8061 value = instance->CallAsConstructor(1, args);
8063 String::AsciiValue exception_value2(try_catch.
Exception());
8069 { Local<FunctionTemplate> function_template =
8070 FunctionTemplate::New(FakeConstructorCallback);
8071 Local<Function>
function = function_template->GetFunction();
8072 Local<Object> instance1 =
function;
8073 context->
Global()->Set(v8_str(
"obj4"), instance1);
8078 CHECK(instance1->IsObject());
8079 CHECK(instance1->IsFunction());
8081 value = CompileRun(
"new obj4(28)");
8083 CHECK(value->IsObject());
8085 Local<Value> args1[] = { v8_num(28) };
8086 value = instance1->CallAsConstructor(1, args1);
8088 CHECK(value->IsObject());
8091 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
8092 Local<Object> instance2 = instance_template->NewInstance();
8093 context->
Global()->Set(v8_str(
"obj5"), instance2);
8096 CHECK(instance2->IsObject());
8097 CHECK(!instance2->IsFunction());
8099 value = CompileRun(
"new obj5(28)");
8101 CHECK(!value->IsObject());
8103 Local<Value> args2[] = { v8_num(28) };
8104 value = instance2->CallAsConstructor(1, args2);
8106 CHECK(!value->IsObject());
8115 templ->SetClassName(v8_str(
"Fun"));
8116 Local<Function> cons = templ->GetFunction();
8117 context->
Global()->Set(v8_str(
"Fun"), cons);
8118 Local<Value> value = CompileRun(
8121 " (new Fun()).blah()"
8123 " var str = String(e);"
8124 " if (str.indexOf('TypeError') == -1) return 1;"
8125 " if (str.indexOf('[object Fun]') != -1) return 2;"
8126 " if (str.indexOf('#<Fun>') == -1) return 3;"
8141 Local<Script> script =
8142 Script::Compile(v8_str(
"function f(x) { "
8144 " with (x) { return eval('foo'); }"
8147 "result1 = f(new Object());"
8148 "result2 = f(this);"
8149 "var x = new Object();"
8150 "x.eval = function(x) { return 1; };"
8151 "result3 = f(x);"));
8153 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result1"))->Int32Value());
8154 CHECK_EQ(0, current->
Global()->Get(v8_str(
"result2"))->Int32Value());
8155 CHECK_EQ(1, current->
Global()->Get(v8_str(
"result3"))->Int32Value());
8159 Script::Compile(v8_str(
"function f(x) { "
8161 " with (x) { return eval('bar'); }"
8163 "result4 = f(this)"));
8165 CHECK(!try_catch.HasCaught());
8166 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result4"))->Int32Value());
8177 Local<String> token = v8_str(
"<security token>");
8182 current->
Global()->Set(v8_str(
"other"), other->
Global());
8185 Local<Script> script =
8186 Script::Compile(v8_str(
"other.eval('var foo = 1234')"));
8188 Local<Value>
foo = other->
Global()->Get(v8_str(
"foo"));
8195 Script::Compile(v8_str(
"other.eval('na = 1234')"));
8197 CHECK_EQ(1234, other->
Global()->Get(v8_str(
"na"))->Int32Value());
8204 Script::Compile(v8_str(
"var bar = 42; other.eval('bar');"));
8205 Local<Value> result = script->Run();
8206 CHECK(try_catch.HasCaught());
8212 Script::Compile(v8_str(
"(function() { "
8214 " return other.eval('baz');"
8216 result = script->Run();
8217 CHECK(try_catch.HasCaught());
8222 other->
Global()->Set(v8_str(
"bis"), v8_num(1234));
8223 script = Script::Compile(v8_str(
"other.eval('bis')"));
8224 CHECK_EQ(1234, script->Run()->Int32Value());
8225 CHECK(!try_catch.HasCaught());
8230 script = Script::Compile(v8_str(
"other.eval('this == t')"));
8231 result = script->Run();
8232 CHECK(result->IsTrue());
8233 CHECK(!try_catch.HasCaught());
8238 Script::Compile(v8_str(
"with({x:2}){other.eval('x')}"));
8239 result = script->Run();
8240 CHECK(try_catch.HasCaught());
8246 Script::Compile(v8_str(
"other.y = 1; eval.call(other, 'y')"));
8247 result = script->Run();
8248 CHECK(try_catch.HasCaught());
8264 CompileRun(
"var x = 42;"
8267 " return function(s) { return e(s); }"
8275 context1->Global()->Set(v8_str(
"fun"), fun);
8278 context0->DetachGlobal();
8280 x_value = CompileRun(
"fun('x')");
8295 Local<String> token = v8_str(
"<security token>");
8300 current->
Global()->Set(v8_str(
"other"), other->
Global());
8303 Local<Script> script =
8304 Script::Compile(v8_str(
"other.eval('new Date(42)')"));
8305 Local<Value> value = script->Run();
8306 CHECK_EQ(42.0, value->NumberValue());
8313 if (args[0]->IsInt32()) {
8314 return v8_num(-args[0]->Int32Value());
8331 instance_template->SetCallAsFunctionHandler(call_as_function);
8332 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8333 context->
Global()->Set(v8_str(
"obj"), instance);
8338 value = CompileRun(
"obj(42)");
8342 value = CompileRun(
"(function(o){return o(49)})(obj)");
8347 value = CompileRun(
"[obj]['0'](45)");
8351 value = CompileRun(
"obj.call = Function.prototype.call;"
8352 "obj.call(null, 87)");
8358 const char* apply_99 =
"Function.prototype.call.apply(obj, [this, 99])";
8359 value = CompileRun(apply_99);
8363 const char* call_17 =
"Function.prototype.call.call(obj, this, 17)";
8364 value = CompileRun(call_17);
8370 value = CompileRun(
"new obj(43)");
8372 CHECK_EQ(-43, value->Int32Value());
8377 value = instance->CallAsFunction(instance, 1, args);
8385 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8386 context->
Global()->Set(v8_str(
"obj2"), instance);
8392 value = CompileRun(
"obj2(28)");
8393 CHECK(value.IsEmpty());
8395 String::AsciiValue exception_value1(try_catch.
Exception());
8396 CHECK_EQ(
"TypeError: Property 'obj2' of object #<Object> is not a function",
8401 value = CompileRun(
"obj2(28)");
8403 value = instance->CallAsFunction(instance, 1, args);
8404 CHECK(value.IsEmpty());
8406 String::AsciiValue exception_value2(try_catch.
Exception());
8407 CHECK_EQ(
"TypeError: [object Object] is not a function", *exception_value2);
8413 instance_template->SetCallAsFunctionHandler(
ThrowValue);
8414 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8415 context->
Global()->Set(v8_str(
"obj3"), instance);
8421 value = CompileRun(
"obj3(22)");
8423 String::AsciiValue exception_value1(try_catch.
Exception());
8428 value = instance->CallAsFunction(instance, 1, args);
8430 String::AsciiValue exception_value2(try_catch.
Exception());
8443 instance_template->SetCallAsFunctionHandler(call_as_function);
8444 Local<Object> instance = instance_template->NewInstance();
8447 CHECK(instance->IsCallable());
8452 Local<Object> instance = instance_template->NewInstance();
8455 CHECK(!instance->IsCallable());
8459 { Local<FunctionTemplate> function_template =
8460 FunctionTemplate::New(call_as_function);
8461 Local<Function>
function = function_template->GetFunction();
8462 Local<Object> instance =
function;
8465 CHECK(instance->IsCallable());
8469 { Local<FunctionTemplate> function_template = FunctionTemplate::New();
8470 Local<Function>
function = function_template->GetFunction();
8471 Local<Object> instance =
function;
8474 CHECK(instance->IsCallable());
8480 static int CountHandles() {
8485 static int Recurse(
int depth,
int iterations) {
8487 if (depth == 0)
return CountHandles();
8488 for (
int i = 0; i < iterations; i++) {
8491 return Recurse(depth - 1, iterations);
8496 static const int kIterations = 500;
8497 static const int kNesting = 200;
8502 for (
int i = 0; i < kIterations; i++) {
8507 CHECK_EQ(kIterations, CountHandles());
8510 for (
int j = 0; j < kIterations; j++) {
8512 CHECK_EQ(j + 1 + kIterations, CountHandles());
8515 CHECK_EQ(kIterations, CountHandles());
8518 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
8524 const AccessorInfo& info) {
8534 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
8535 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
8536 Local<Function>
function = fun_templ->GetFunction();
8537 context->
Global()->Set(v8_str(
"constructor"),
function);
8539 "var o = new constructor();"
8540 "o.hasOwnProperty('ostehaps');");
8544 "o.hasOwnProperty('ostehaps');");
8545 CHECK_EQ(
true, value->BooleanValue());
8547 "var p = new constructor();"
8548 "p.hasOwnProperty('ostehaps');");
8549 CHECK_EQ(
false, value->BooleanValue());
8555 const AccessorInfo& info) {
8566 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
8567 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
8568 Local<Function>
function = fun_templ->GetFunction();
8569 context->
Global()->Set(v8_str(
"constructor"),
function);
8572 "function makestr(size) {"
8574 " case 1: return 'f';"
8575 " case 2: return 'fo';"
8576 " case 3: return 'foo';"
8578 " return makestr(size >> 1) + makestr((size + 1) >> 1);"
8580 "var x = makestr(12345);"
8581 "x = makestr(31415);"
8582 "x = makestr(23456);");
8584 "var o = new constructor();"
8585 "o.__proto__ = new String(x);"
8586 "o.hasOwnProperty('ostehaps');");
8592 const AccessorInfo& info);
8609 const AccessorInfo& info) {
8612 CHECK_EQ(isolate, info.GetIsolate());
8613 CHECK_EQ(v8_str(
"data"), info.Data());
8621 CheckInterceptorLoadIC(InterceptorLoadICGetter,
8623 "for (var i = 0; i < 1000; i++) {"
8635 const AccessorInfo& info) {
8637 return v8_str(
"x")->Equals(name)
8643 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8646 "for (var i = 0; i < 1000; i++) {"
8654 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8656 "o.__proto__ = { 'y': 239 };"
8657 "for (var i = 0; i < 1000; i++) {"
8658 " result = o.y + o.x;"
8665 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8667 "o.__proto__.y = 239;"
8668 "for (var i = 0; i < 1000; i++) {"
8669 " result = o.y + o.x;"
8676 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8678 "for (var i = 0; i < 1000; i++) {"
8679 " result = (o.y == undefined) ? 239 : 42;"
8686 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8687 "fst = new Object(); fst.__proto__ = o;"
8688 "snd = new Object(); snd.__proto__ = fst;"
8690 "for (var i = 0; i < 1000; i++) {"
8695 "for (var i = 0; i < 1000; i++) {"
8706 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8707 "proto = new Object();"
8708 "o.__proto__ = proto;"
8710 "for (var i = 0; i < 1000; i++) {"
8715 "for (var i = 0; i < 1000; i++) {"
8726 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8727 "proto1 = new Object();"
8728 "proto2 = new Object();"
8729 "o.__proto__ = proto1;"
8730 "proto1.__proto__ = proto2;"
8732 "for (var i = 0; i < 1000; i++) {"
8738 "for (var i = 0; i < 1000; i++) {"
8746 static int interceptor_load_not_handled_calls = 0;
8748 const AccessorInfo& info) {
8749 ++interceptor_load_not_handled_calls;
8757 interceptor_load_not_handled_calls = 0;
8758 CheckInterceptorLoadIC(InterceptorLoadNotHandled,
8759 "receiver = new Object();"
8760 "receiver.__proto__ = o;"
8761 "proto = new Object();"
8762 "/* Make proto a slow-case object. */"
8763 "for (var i = 0; i < 1000; i++) {"
8764 " proto[\"xxxxxxxx\" + i] = [];"
8767 "o.__proto__ = proto;"
8769 "for (var i = 0; i < 1000; i++) {"
8770 " result += receiver.x;"
8774 CHECK_EQ(1000, interceptor_load_not_handled_calls);
8782 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8783 "o.__proto__ = this;"
8784 "this.__proto__.y = 239;"
8785 "for (var i = 0; i < 10; i++) {"
8786 " if (o.y != 239) throw 'oops: ' + o.y;"
8791 "for (var i = 0; i < 10; i++) {"
8799 static void SetOnThis(Local<String> name,
8801 const AccessorInfo& info) {
8802 info.This()->ForceSet(name, value);
8818 "for (var i = 0; i < 7; i++) {"
8826 "r = { __proto__: o };"
8828 "for (var i = 0; i < 7; i++) {"
8831 CHECK_EQ(239, value->Int32Value());
8851 "for (var i = 0; i < 7; i++) {"
8852 " result = o.x + o.y;"
8859 "r = { __proto__: o };"
8861 "for (var i = 0; i < 7; i++) {"
8862 " result = r.x + r.y;"
8864 CHECK_EQ(239 + 42, value->Int32Value());
8878 "fst = new Object(); fst.__proto__ = o;"
8879 "snd = new Object(); snd.__proto__ = fst;"
8881 "for (var i = 0; i < 7; i++) {"
8886 "for (var i = 0; i < 7; i++) {"
8889 "result + result1");
8909 "for (var i = 0; i < 7; i++) {"
8914 "for (var i = 0; i < 7; i++) {"
8929 templ_p->
SetAccessor(v8_str(
"y"), Return239, SetOnThis);
8936 "inbetween = new Object();"
8937 "o.__proto__ = inbetween;"
8938 "inbetween.__proto__ = p;"
8939 "for (var i = 0; i < 10; i++) {"
8945 "for (var i = 0; i < 10; i++) {"
8961 templ_p->
SetAccessor(v8_str(
"y"), Return239, SetOnThis);
8968 "o.__proto__ = this;"
8969 "this.__proto__ = p;"
8970 "for (var i = 0; i < 10; i++) {"
8971 " if (o.y != 239) throw 'oops: ' + o.y;"
8976 "for (var i = 0; i < 10; i++) {"
8985 const AccessorInfo& info) {
8987 CHECK(v8_str(
"x")->Equals(name));
8993 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
8994 "o.x == undefined ? 1 : 0",
9000 Local<String> key, Local<Value> value,
const AccessorInfo&) {
9001 CHECK(v8_str(
"x")->Equals(key));
9012 InterceptorStoreICSetter,
9013 0, 0, 0, v8_str(
"data"));
9017 "for (var i = 0; i < 1000; i++) {"
9030 "for (var i = 0; i < 1000; i++) {"
9045 const AccessorInfo& info) {
9047 CHECK(v8_str(
"x")->Equals(name));
9060 v8_compile(
"function f(x) { return x + 1; }; f")->Run();
9063 "for (var i = 0; i < 1000; i++) {"
9064 " result = o.x(41);"
9079 "o.x = function f(x) { return x + 1; };"
9081 "for (var i = 0; i < 7; i++) {"
9082 " result = o.x(41);"
9090 const AccessorInfo& info) {
9092 CHECK(v8_str(
"x")->Equals(name));
9093 return call_ic_function4;
9107 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9109 "o.__proto__.x = function(x) { return x + 1; };"
9111 "for (var i = 0; i < 1000; i++) {"
9112 " result = o.x(42);"
9127 "proto1 = new Object();"
9128 "proto2 = new Object();"
9129 "o.__proto__ = proto1;"
9130 "proto1.__proto__ = proto2;"
9131 "proto2.y = function(x) { return x + 1; };"
9133 "for (var i = 0; i < 7; i++) {"
9136 "proto1.y = function(x) { return x - 1; };"
9138 "for (var i = 0; i < 7; i++) {"
9139 " result += o.y(42);"
9154 "function inc(x) { return x + 1; };"
9158 "for (var i = 0; i < 1000; i++) {"
9159 " result = o.x(42);"
9167 const AccessorInfo& info) {
9169 if (v8_str(
"x")->Equals(name))
9170 return call_ic_function5;
9172 return Local<Value>();
9186 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9188 "function inc(x) { return x + 1; };"
9192 "for (var i = 0; i < 1000; i++) {"
9193 " result = o.x(42);"
9201 const AccessorInfo& info) {
9203 if (v8_str(
"x")->Equals(name))
9204 return call_ic_function6;
9206 return Local<Value>();
9213 i::FLAG_allow_natives_syntax =
true;
9220 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9222 "function inc(x) { return x + 1; };"
9227 " for (var i = 0; i < 1000; i++) {"
9228 " result = o.x(42);"
9235 "%OptimizeFunctionOnNextCall(test);"
9250 "function inc(x) { return x + 1; };"
9252 "proto1 = new Object();"
9253 "proto2 = new Object();"
9254 "o.__proto__ = proto1;"
9255 "proto1.__proto__ = proto2;"
9258 "for (var i = 0; i < 7; i++) {"
9261 "proto1.y = function(x) { return x - 1; };"
9263 "for (var i = 0; i < 7; i++) {"
9264 " result += o.y(42);"
9280 "function inc(x) { return x + 1; };"
9282 "o.__proto__ = this;"
9283 "this.__proto__.y = inc;"
9285 "for (var i = 0; i < 7; i++) {"
9286 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
9288 "this.y = function(x) { return x - 1; };"
9290 "for (var i = 0; i < 7; i++) {"
9291 " result += o.y(42);"
9308 " o.__proto__ = this;"
9309 " for (var i = 0; i < 10; i++) {"
9310 " var v = o.parseFloat('239');"
9311 " if (v != 239) throw v;"
9315 " for (var i = 0; i < 10; i++) {"
9316 " result += o.parseFloat('239');"
9326 const AccessorInfo& info) {
9330 if ((*call_count) % 20 == 0) {
9342 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
9352 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
9355 CHECK(args.
Holder()->HasRealNamedProperty(v8_str(
"foo")));
9360 static void GenerateSomeGarbage() {
9363 "for (var i = 0; i < 1000; i++) {"
9364 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
9366 "garbage = undefined;");
9371 static int count = 0;
9372 if (count++ % 3 == 0) {
9373 HEAP-> CollectAllGarbage(
true);
9374 GenerateSomeGarbage();
9384 nativeobject_templ->
Set(
"callback",
9387 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
9391 " for (var i = 1; i <= 30; i++) {"
9392 " nativeobject.callback();"
9408 nativeobject_templ->
Set(
"callback",
9411 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
9416 " for (var i = 1; i <= 5; i++) {"
9417 " try { nativeobject.callback(); } catch (e) { result += e; }"
9427 if (++p_getter_count % 3 == 0) {
9428 HEAP->CollectAllGarbage(
true);
9429 GenerateSomeGarbage();
9444 " for (var i = 0; i < 30; i++) o1.p1;"
9465 "for (var i = 0; i < 5; i++) {"
9466 " try { o1.p1; } catch (e) { result += e; }"
9474 int interceptor_call_count = 0;
9479 v8_str(
"method_data"),
9482 proto_templ->
Set(v8_str(
"method"), method_templ);
9489 GenerateSomeGarbage();
9493 "for (var i = 0; i < 100; i++) {"
9494 " result = o.method(41);"
9496 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9497 CHECK_EQ(100, interceptor_call_count);
9501 int interceptor_call_count = 0;
9506 v8_str(
"method_data"),
9509 proto_templ->
Set(v8_str(
"method"), method_templ);
9516 GenerateSomeGarbage();
9520 "var receiver = {};"
9521 "receiver.__proto__ = o;"
9523 "for (var i = 0; i < 100; i++) {"
9524 " result = receiver.method(41);"
9526 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9527 CHECK_EQ(100, interceptor_call_count);
9531 int interceptor_call_count = 0;
9536 v8_str(
"method_data"),
9539 proto_templ->
Set(v8_str(
"method"), method_templ);
9546 GenerateSomeGarbage();
9550 "var receiver = {};"
9551 "receiver.__proto__ = o;"
9553 "var saved_result = 0;"
9554 "for (var i = 0; i < 100; i++) {"
9555 " result = receiver.method(41);"
9557 " saved_result = result;"
9558 " receiver = {method: function(x) { return x - 1 }};"
9561 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9562 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9563 CHECK_GE(interceptor_call_count, 50);
9567 int interceptor_call_count = 0;
9572 v8_str(
"method_data"),
9575 proto_templ->
Set(v8_str(
"method"), method_templ);
9582 GenerateSomeGarbage();
9586 "var receiver = {};"
9587 "receiver.__proto__ = o;"
9589 "var saved_result = 0;"
9590 "for (var i = 0; i < 100; i++) {"
9591 " result = receiver.method(41);"
9593 " saved_result = result;"
9594 " o.method = function(x) { return x - 1 };"
9597 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9598 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9599 CHECK_GE(interceptor_call_count, 50);
9603 int interceptor_call_count = 0;
9608 v8_str(
"method_data"),
9611 proto_templ->
Set(v8_str(
"method"), method_templ);
9618 GenerateSomeGarbage();
9623 "var receiver = {};"
9624 "receiver.__proto__ = o;"
9626 "var saved_result = 0;"
9627 "for (var i = 0; i < 100; i++) {"
9628 " result = receiver.method(41);"
9630 " saved_result = result;"
9635 CHECK_EQ(v8_str(
"TypeError: Object 333 has no method 'method'"),
9637 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9638 CHECK_GE(interceptor_call_count, 50);
9642 int interceptor_call_count = 0;
9647 v8_str(
"method_data"),
9650 proto_templ->
Set(v8_str(
"method"), method_templ);
9657 GenerateSomeGarbage();
9662 "var receiver = {};"
9663 "receiver.__proto__ = o;"
9665 "var saved_result = 0;"
9666 "for (var i = 0; i < 100; i++) {"
9667 " result = receiver.method(41);"
9669 " saved_result = result;"
9670 " receiver = {method: receiver.method};"
9674 CHECK_EQ(v8_str(
"TypeError: Illegal invocation"),
9676 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9677 CHECK_GE(interceptor_call_count, 50);
9685 v8_str(
"method_data"),
9688 proto_templ->
Set(v8_str(
"method"), method_templ);
9693 GenerateSomeGarbage();
9697 "for (var i = 0; i < 100; i++) {"
9698 " result = o.method(41);"
9701 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9709 v8_str(
"method_data"),
9712 proto_templ->
Set(v8_str(
"method"), method_templ);
9714 CHECK(!templ.IsEmpty());
9717 GenerateSomeGarbage();
9721 "var receiver = {};"
9722 "receiver.__proto__ = o;"
9724 "for (var i = 0; i < 100; i++) {"
9725 " result = receiver.method(41);"
9728 CHECK_EQ(42, context->Global()->Get(v8_str(
"result"))->Int32Value());
9736 v8_str(
"method_data"),
9739 proto_templ->
Set(v8_str(
"method"), method_templ);
9741 CHECK(!templ.IsEmpty());
9744 GenerateSomeGarbage();
9748 "var receiver = {};"
9749 "receiver.__proto__ = o;"
9751 "var saved_result = 0;"
9752 "for (var i = 0; i < 100; i++) {"
9753 " result = receiver.method(41);"
9755 " saved_result = result;"
9756 " receiver = {method: function(x) { return x - 1 }};"
9759 CHECK_EQ(40, context->Global()->Get(v8_str(
"result"))->Int32Value());
9760 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
9768 v8_str(
"method_data"),
9771 proto_templ->
Set(v8_str(
"method"), method_templ);
9773 CHECK(!templ.IsEmpty());
9776 GenerateSomeGarbage();
9781 "var receiver = {};"
9782 "receiver.__proto__ = o;"
9784 "var saved_result = 0;"
9785 "for (var i = 0; i < 100; i++) {"
9786 " result = receiver.method(41);"
9788 " saved_result = result;"
9793 CHECK_EQ(v8_str(
"TypeError: Object 333 has no method 'method'"),
9795 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
9802 Local<String> name,
const AccessorInfo& info) {
9804 if (v8_str(
"x")->Equals(name)) {
9820 "proto = new Object();"
9821 "proto.y = function(x) { return x + 1; };"
9822 "proto.z = function(x) { return x - 1; };"
9823 "o.__proto__ = proto;"
9826 "for (var i = 0; i < 10; i++) {"
9827 " if (i == 5) { method = 'z'; };"
9828 " result += o[method](41);"
9830 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9843 keyed_call_ic_function =
9844 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9847 "proto2 = new Object();"
9848 "o.y = function(x) { return x + 1; };"
9849 "proto2.y = function(x) { return x + 2; };"
9850 "o.__proto__ = proto1;"
9851 "proto1.__proto__ = proto2;"
9854 "for (var i = 0; i < 10; i++) {"
9855 " if (i == 5) { method = 'y'; };"
9856 " result += o[method](41);"
9858 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9871 "function inc(x) { return x + 1; };"
9873 "function dec(x) { return x - 1; };"
9875 "o.__proto__ = this;"
9876 "this.__proto__.x = inc;"
9877 "this.__proto__.y = dec;"
9880 "for (var i = 0; i < 10; i++) {"
9881 " if (i == 5) { method = 'y'; };"
9882 " result += o[method](41);"
9884 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9897 "function len(x) { return x.length; };"
9898 "o.__proto__ = this;"
9899 "var m = 'parseFloat';"
9901 "for (var i = 0; i < 10; i++) {"
9904 " saved_result = result;"
9906 " result = o[m]('239');"
9908 CHECK_EQ(3, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9909 CHECK_EQ(239, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9921 "var o = new Object();"
9922 "o.__proto__ = proto;"
9923 "o.method = function(x) { return x + 1; };"
9926 "for (var i = 0; i < 10; i++) {"
9927 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
9928 " result += o[m](41);"
9930 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9943 "var proto = new Object();"
9944 "o.__proto__ = proto;"
9945 "proto.method = function(x) { return x + 1; };"
9948 "for (var i = 0; i < 10; i++) {"
9949 " if (i == 5) { proto.method = function(x) { return x - 1; }; };"
9950 " result += o[m](41);"
9952 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9956 static int interceptor_call_count = 0;
9959 const AccessorInfo& info) {
9961 if (v8_str(
"x")->Equals(name) && interceptor_call_count++ < 20) {
9976 call_ic_function2 = v8_compile(
"function h(x) { return x; }; h")->Run();
9979 " for (var i = 0; i < 1000; i++) {"
9980 " try { x; } catch(e) { return true; }"
9986 interceptor_call_count = 0;
9989 " for (var i = 0; i < 1000; i++) {"
9990 " try { x(42); } catch(e) { return true; }"
9999 static int interceptor_ic_exception_get_count = 0;
10002 Local<String> name,
10003 const AccessorInfo& info) {
10005 if (v8_str(
"x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) {
10008 if (interceptor_ic_exception_get_count == 20) {
10018 interceptor_ic_exception_get_count = 0;
10023 call_ic_function3 = v8_compile(
"function h(x) { return x; }; h")->Run();
10026 " for (var i = 0; i < 100; i++) {"
10027 " try { x; } catch(e) { return true; }"
10033 interceptor_ic_exception_get_count = 0;
10034 value = CompileRun(
10036 " for (var i = 0; i < 100; i++) {"
10037 " try { x(42); } catch(e) { return true; }"
10046 static int interceptor_ic_exception_set_count = 0;
10049 Local<String> key, Local<Value> value,
const AccessorInfo&) {
10051 if (++interceptor_ic_exception_set_count > 20) {
10061 interceptor_ic_exception_set_count = 0;
10068 " for (var i = 0; i < 100; i++) {"
10069 " try { x = 42; } catch(e) { return true; }"
10084 templ->
Set(
"x", v8_num(42));
10086 context->
Global()->Set(v8_str(
"obj"), obj);
10099 templ->
Set(
"42", v8_num(42));
10101 context->
Global()->Set(v8_str(
"obj"), obj);
10111 templ->
InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10113 env->
Global()->Set(v8_str(
"obj"),
10115 ExpectTrue(
"obj.x === 42");
10116 ExpectTrue(
"!obj.propertyIsEnumerable('x')");
10120 static Handle<Value> ThrowingGetter(Local<String> name,
10121 const AccessorInfo& info) {
10132 Local<FunctionTemplate> templ = FunctionTemplate::New();
10133 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
10134 instance_templ->SetAccessor(v8_str(
"f"), ThrowingGetter);
10136 Local<Object> instance = templ->GetFunction()->NewInstance();
10138 Local<Object> another = Object::New();
10139 another->SetPrototype(instance);
10141 Local<Object> with_js_getter = CompileRun(
10143 "o.__defineGetter__('f', function() { throw undefined; });\n"
10145 CHECK(!with_js_getter.IsEmpty());
10147 TryCatch try_catch;
10150 CHECK(try_catch.HasCaught());
10152 CHECK(result.IsEmpty());
10154 result = another->GetRealNamedProperty(v8_str(
"f"));
10155 CHECK(try_catch.HasCaught());
10157 CHECK(result.IsEmpty());
10159 result = another->GetRealNamedPropertyInPrototypeChain(v8_str(
"f"));
10160 CHECK(try_catch.HasCaught());
10162 CHECK(result.IsEmpty());
10164 result = another->Get(v8_str(
"f"));
10165 CHECK(try_catch.HasCaught());
10167 CHECK(result.IsEmpty());
10169 result = with_js_getter->GetRealNamedProperty(v8_str(
"f"));
10170 CHECK(try_catch.HasCaught());
10172 CHECK(result.IsEmpty());
10174 result = with_js_getter->Get(v8_str(
"f"));
10175 CHECK(try_catch.HasCaught());
10177 CHECK(result.IsEmpty());
10181 static Handle<Value> ThrowingCallbackWithTryCatch(
const Arguments& args) {
10182 TryCatch try_catch;
10186 CompileRun(
"throw 'from JS';");
10187 CHECK(try_catch.HasCaught());
10188 CHECK(!i::Isolate::Current()->has_pending_exception());
10189 CHECK(!i::Isolate::Current()->has_scheduled_exception());
10194 static int call_depth;
10197 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
10198 TryCatch try_catch;
10202 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) {
10203 if (--call_depth) CompileRun(
"throw 'ThrowInJS';");
10207 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) {
10212 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
10213 Handle<String> errorMessageString = message->Get();
10214 CHECK(!errorMessageString.IsEmpty());
10215 message->GetStackTrace();
10216 message->GetScriptResourceName();
10223 Local<Function> func =
10224 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction();
10225 context->
Global()->Set(v8_str(
"func"), func);
10229 for (
unsigned i = 0; i <
sizeof(callbacks)/
sizeof(callbacks[0]); i++) {
10231 if (callback !=
NULL) {
10232 V8::AddMessageListener(callback);
10238 "var thrown = false;\n"
10239 "try { func(); } catch(e) { thrown = true; }\n"
10241 if (callback !=
NULL) {
10242 V8::RemoveMessageListeners(callback);
10249 const AccessorInfo& info) {
10256 const AccessorInfo& info) {
10263 i::FLAG_es5_readonly =
true;
10269 Local<ObjectTemplate> parent_instance_templ =
10270 parent_templ->InstanceTemplate();
10271 parent_instance_templ->SetAccessor(v8_str(
"f"), ParentGetter);
10275 Local<ObjectTemplate> child_instance_templ =
10276 child_templ->InstanceTemplate();
10277 child_templ->Inherit(parent_templ);
10280 child_instance_templ->SetAccessor(v8_str(
"f"), ChildGetter);
10282 child_instance_templ->SetAccessor(v8_str(
"g"), ParentGetter);
10283 child_instance_templ->SetAccessor(v8_str(
"g"), ChildGetter);
10287 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate();
10288 child_proto_templ->SetAccessor(v8_str(
"h"), ParentGetter, 0,
10294 child_instance_templ->SetAccessor(v8_str(
"i"), ChildGetter, 0,
10300 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance();
10303 context->
Global()->Set(v8_str(
"o"), instance);
10304 Local<Value> value = v8_compile(
"o.f")->Run();
10306 CHECK_EQ(42, value->Int32Value());
10307 value = v8_compile(
"o.g")->Run();
10308 CHECK_EQ(42, value->Int32Value());
10311 value = v8_compile(
"o.h = 3; o.h")->Run();
10315 value = v8_compile(
"o.i = 3; o.i")->Run();
10316 CHECK_EQ(42, value->Int32Value());
10331 templ->SetCallHandler(IsConstructHandler);
10335 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
10336 Local<Value> value = v8_compile(
"f()")->Run();
10337 CHECK(!value->BooleanValue());
10338 value = v8_compile(
"new f()")->Run();
10339 CHECK(value->BooleanValue());
10346 templ->SetClassName(v8_str(
"MyClass"));
10350 Local<String> customized_tostring = v8_str(
"customized toString");
10353 v8_compile(
"Object.prototype.toString = function() {"
10354 " return 'customized toString';"
10358 Local<v8::Object> instance = templ->GetFunction()->NewInstance();
10359 Local<String> value = instance->ToString();
10360 CHECK(value->IsString() && value->Equals(customized_tostring));
10363 value = instance->ObjectProtoToString();
10364 CHECK(value->IsString() && value->Equals(v8_str(
"[object MyClass]")));
10367 value = context->
Global()->ObjectProtoToString();
10368 CHECK(value->IsString() && value->Equals(v8_str(
"[object global]")));
10371 Local<Value>
object = v8_compile(
"new Object()")->Run();
10372 value =
object.As<
v8::Object>()->ObjectProtoToString();
10373 CHECK(value->IsString() && value->Equals(v8_str(
"[object Object]")));
10380 v8_compile(
"function Parent() {};"
10381 "function Child() {};"
10382 "Child.prototype = new Parent();"
10383 "var outer = { inner: function() { } };"
10384 "var p = new Parent();"
10385 "var c = new Child();"
10386 "var x = new outer.inner();")->Run();
10388 Local<v8::Value> p = context->
Global()->Get(v8_str(
"p"));
10389 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals(
10390 v8_str(
"Parent")));
10392 Local<v8::Value> c = context->
Global()->Get(v8_str(
"c"));
10393 CHECK(c->IsObject() && c->ToObject()->GetConstructorName()->Equals(
10396 Local<v8::Value> x = context->
Global()->Get(v8_str(
"x"));
10397 CHECK(x->IsObject() && x->ToObject()->GetConstructorName()->Equals(
10398 v8_str(
"outer.inner")));
10402 bool ApiTestFuzzer::fuzzing_ =
false;
10405 int ApiTestFuzzer::active_tests_;
10406 int ApiTestFuzzer::tests_being_run_;
10407 int ApiTestFuzzer::current_;
10413 if (!fuzzing_)
return;
10415 test->ContextSwitch();
10421 bool ApiTestFuzzer::NextThread() {
10422 int test_position = GetNextTestNumber();
10424 if (test_position == current_) {
10426 printf(
"Stay with %s\n", test_name);
10429 if (kLogThreading) {
10430 printf(
"Switch from %s to %s\n",
10434 current_ = test_position;
10452 if (active_tests_ == 0) {
10453 all_tests_done_->
Signal();
10461 static unsigned linear_congruential_generator;
10465 linear_congruential_generator = i::FLAG_testing_prng_seed;
10468 int start = count * part / (
LAST_PART + 1);
10469 int end = (count * (part + 1) / (
LAST_PART + 1)) - 1;
10470 active_tests_ = tests_being_run_ = end - start + 1;
10471 for (
int i = 0; i < tests_being_run_; i++) {
10474 for (
int i = 0; i < active_tests_; i++) {
10480 static void CallTestNumber(
int test_number) {
10490 all_tests_done_->
Wait();
10494 int ApiTestFuzzer::GetNextTestNumber() {
10497 next_test = (linear_congruential_generator >> 16) % tests_being_run_;
10498 linear_congruential_generator *= 1664525u;
10499 linear_congruential_generator += 1013904223u;
10505 void ApiTestFuzzer::ContextSwitch() {
10507 if (NextThread()) {
10521 if (fuzzer !=
NULL) fuzzer->
Join();
10553 printf(
"Start test %d\n", test_number_);
10554 CallTestNumber(test_number_);
10556 printf(
"End test %d\n", test_number_);
10564 const char* code =
"throw 7;";
10576 exception = Local<Value>::New(try_catch.
Exception());
10587 const char* code =
"throw 7;";
10593 return v8_str(
"foo");
10606 Local<Function> fun = fun_templ->GetFunction();
10607 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
10608 Local<Script> script = v8_compile(
"(function () {"
10616 CHECK_EQ(91, script->Run()->Int32Value());
10626 Local<v8::FunctionTemplate> fun_templ =
10628 Local<Function> fun = fun_templ->GetFunction();
10629 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
10630 Local<Script> script = v8_compile(
"(function () {"
10638 CHECK_EQ(91, script->Run()->Int32Value());
10663 Local<v8::FunctionTemplate> fun_templ =
10665 Local<Function> fun = fun_templ->GetFunction();
10666 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
10667 Local<Script> script = v8_compile(
"(function () {"
10668 " unlock_for_a_moment();"
10671 CHECK_EQ(42, script->Run()->Int32Value());
10677 Local<v8::FunctionTemplate> fun_templ =
10679 Local<Function> fun = fun_templ->GetFunction();
10680 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
10681 Local<Script> script = v8_compile(
"(function () {"
10682 " unlock_for_a_moment();"
10685 CHECK_EQ(42, script->Run()->Int32Value());
10690 static int GetGlobalObjectsCount() {
10691 i::Isolate::Current()->heap()->EnsureHeapIsIterable();
10693 i::HeapIterator it;
10695 if (object->IsJSGlobalObject()) count++;
10700 static void CheckSurvivingGlobalObjectsCount(
int expected) {
10708 int count = GetGlobalObjectsCount();
10710 if (count != expected)
HEAP->TracePathToGlobal();
10721 for (
int i = 0; i < 5; i++) {
10725 CheckSurvivingGlobalObjectsCount(0);
10729 v8_compile(
"Date")->Run();
10731 CheckSurvivingGlobalObjectsCount(0);
10735 v8_compile(
"/aaa/")->Run();
10737 CheckSurvivingGlobalObjectsCount(0);
10740 const char* extension_list[] = {
"v8/gc" };
10743 v8_compile(
"gc();")->Run();
10745 CheckSurvivingGlobalObjectsCount(0);
10799 to_be_disposed = handle2;
10834 const char* sources[nof] = {
10835 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
10839 for (
int i = 0; i < nof; i++) {
10840 const char* source = sources[i];
10843 CompileRun(source);
10847 CompileRun(source);
10869 CHECK(!str.IsEmpty());
10875 static int64_t cast(intptr_t x) {
return static_cast<int64_t
>(x); }
10882 const intptr_t kSize = 1024*1024;
10938 const char* resource_name,
10946 CHECK(!message.IsEmpty());
10947 CHECK_EQ(10 + line_offset, message->GetLineNumber());
10948 CHECK_EQ(91, message->GetStartPosition());
10949 CHECK_EQ(92, message->GetEndPosition());
10950 CHECK_EQ(2, message->GetStartColumn());
10951 CHECK_EQ(3, message->GetEndColumn());
10953 CHECK_EQ(
" throw 'nirk';", *line);
10963 "function Foo() {\n"
10967 "function Bar() {\n"
10971 "function Baz() {\n"
10977 const char* resource_name;
10979 resource_name =
"test.js";
10981 CheckTryCatchSourceInfo(script, resource_name, 0);
10983 resource_name =
"test1.js";
10986 CheckTryCatchSourceInfo(script, resource_name, 0);
10988 resource_name =
"test2.js";
10991 CheckTryCatchSourceInfo(script, resource_name, 7);
11021 Local<ObjectTemplate> t = ObjectTemplate::New();
11023 context->
Global()->Set(v8_str(
"obj"), t->NewInstance());
11044 for (
int i = 0; i < elmc; i++) {
11053 const char* elmv[]) {
11057 for (
int i = 0; i < elmc; i++) {
11070 "result[1] = {a: 1, b: 2};"
11071 "result[2] = [1, 2, 3];"
11072 "var proto = {x: 1, y: 2, z: 3};"
11073 "var x = { __proto__: proto, w: 0, z: 1 };"
11075 "result;"))->Run();
11079 const char** elmv0 =
NULL;
11083 const char* elmv1[] = {
"a",
"b"};
11087 const char* elmv2[] = {
"0",
"1",
"2"};
11091 const char* elmv3[] = {
"w",
"z",
"x",
"y"};
11094 const char* elmv4[] = {
"w",
"z"};
11104 "result[1] = {a: 1, b: 2};"
11105 "result[2] = [1, 2, 3];"
11106 "var proto = {x: 1, y: 2, z: 3};"
11107 "var x = { __proto__: proto, w: 0, z: 1 };"
11109 "result;"))->Run();
11113 const char** elmv0 =
NULL;
11119 for (uint32_t i = 0; i < props->
Length(); i++) {
11120 printf(
"p[%d]\n", i);
11124 static bool NamedSetAccessBlocker(Local<v8::Object> obj,
11127 Local<Value> data) {
11132 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
11135 Local<Value> data) {
11143 Local<ObjectTemplate> templ = ObjectTemplate::New();
11144 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
11145 IndexedSetAccessBlocker);
11146 templ->Set(v8_str(
"x"),
v8::True());
11147 Local<v8::Object> instance = templ->NewInstance();
11148 context->
Global()->Set(v8_str(
"obj"), instance);
11149 Local<Value> value = CompileRun(
"obj.x");
11150 CHECK(value->BooleanValue());
11154 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
11157 Local<Value> data) {
11162 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
11165 Local<Value> data) {
11174 Local<ObjectTemplate> templ = ObjectTemplate::New();
11175 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
11176 IndexedGetAccessBlocker);
11177 templ->Set(v8_str(
"a"), v8_str(
"a"));
11182 for (
char i =
'0'; i <=
'9' ; i++) {
11184 for (
char j =
'0'; j <=
'9'; j++) {
11186 for (
char k =
'0'; k <=
'9'; k++) {
11194 Local<v8::Object> instance_1 = templ->NewInstance();
11195 context->
Global()->Set(v8_str(
"obj_1"), instance_1);
11197 Local<Value> value_1 = CompileRun(
"obj_1.a");
11198 CHECK(value_1->IsUndefined());
11200 Local<v8::Object> instance_2 = templ->NewInstance();
11201 context->
Global()->Set(v8_str(
"obj_2"), instance_2);
11203 Local<Value> value_2 = CompileRun(
"obj_2.a");
11204 CHECK(value_2->IsUndefined());
11214 IndexedSetAccessBlocker);
11217 CHECK(!internal_template->constructor()->IsUndefined());
11220 CHECK(!constructor->access_check_info()->IsUndefined());
11222 CHECK(!context0.IsEmpty());
11223 CHECK(!constructor->access_check_info()->IsUndefined());
11234 IndexedGetAccessBlocker,
11238 Context::Scope context_scope(context);
11241 context->Global()->Set(v8_str(
"a"), v8_num(1));
11242 CompileRun(
"function f1() {return a;}"
11243 "function f2() {return a;}"
11244 "function g1() {return h();}"
11245 "function g2() {return h();}"
11246 "function h() {return 1;}");
11247 Local<Function>
f1 =
11248 Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11249 Local<Function>
f2 =
11250 Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11251 Local<Function> g1 =
11252 Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11253 Local<Function> g2 =
11254 Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11255 Local<Function> h =
11256 Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
11264 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11265 for (
int i = 0; i < 4; i++) {
11266 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11270 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11271 for (
int i = 0; i < 4; i++) {
11272 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11276 context->DetachGlobal();
11277 context->Global()->TurnOnAccessCheck();
11280 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11281 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11284 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11285 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11288 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
11292 static const char* kPropertyA =
"a";
11293 static const char* kPropertyH =
"h";
11295 static bool NamedGetAccessBlockAandH(Local<v8::Object> obj,
11298 Local<Value> data) {
11299 if (!name->IsString())
return false;
11315 IndexedGetAccessBlocker,
11319 Context::Scope context_scope(context);
11322 context->Global()->Set(v8_str(
"a"), v8_num(1));
11323 static const char* source =
"function f1() {return a;}"
11324 "function f2() {return a;}"
11325 "function g1() {return h();}"
11326 "function g2() {return h();}"
11327 "function h() {return 1;}";
11329 CompileRun(source);
11330 Local<Function>
f1;
11331 Local<Function>
f2;
11332 Local<Function> g1;
11333 Local<Function> g2;
11335 f1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11336 f2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11337 g1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11338 g2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11339 h = Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
11347 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11348 for (
int i = 0; i < 4; i++) {
11349 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11353 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11354 for (
int i = 0; i < 4; i++) {
11355 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11360 context->DetachGlobal();
11361 context->Global()->TurnOnAccessCheck();
11364 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11365 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11368 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11369 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11372 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
11376 CompileRun(source);
11377 f1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11378 f2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11379 g1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11380 g2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11381 CHECK(context->Global()->Get(v8_str(
"h"))->IsUndefined());
11384 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11385 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11388 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11389 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11400 const char* script =
"function foo(a) { return a+1; }";
11412 const char* script =
"function foo(a) { return 1 * * 2; }";
11422 const char* script =
" The Definintive Guide";
11433 const char* script =
"function foo(a) { return a+1; }";
11438 int serialized_data_length = sd->
Length();
11439 char* serialized_data = i::NewArray<char>(serialized_data_length);
11440 memcpy(serialized_data, sd->
Data(), serialized_data_length);
11452 delete deserialized_sd;
11459 const char* data =
"DONT CARE";
11460 int invalid_size = 3;
11470 TEST(PreCompileInvalidPreparseDataError) {
11475 const char* script =
"function foo(){ return 5;}\n"
11476 "function bar(){ return 6 + 7;} foo();";
11482 const int kFunctionEntrySize = i::FunctionEntry::kSize;
11483 const int kFunctionEntryStartOffset = 0;
11484 const int kFunctionEntryEndOffset = 1;
11485 unsigned* sd_data =
11486 reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
11489 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
11492 Local<String> source = String::New(script);
11493 Local<Script> compiled_script = Script::New(source,
NULL, sd);
11495 String::AsciiValue exception_value(try_catch.
Message()->Get());
11496 CHECK_EQ(
"Uncaught SyntaxError: Invalid preparser data for function bar",
11505 sd_data =
reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
11506 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
11508 compiled_script = Script::New(source,
NULL, sd);
11521 const char* cstring =
"function foo(a) { return a+1; }";
11535 sd_from_external_string->
Data(),
11536 sd_from_cstring->
Length()));
11540 sd_from_string->
Data(),
11541 sd_from_cstring->
Length()));
11544 delete sd_from_cstring;
11545 delete sd_from_external_string;
11546 delete sd_from_string;
11558 for (
int i = 0; i < 2; i++) {
11561 context->
Global()->Delete(v8_str(
"tmp"));
11562 CompileRun(
"for (var j = 0; j < 10; j++) new RegExp('');");
11565 for (
int i = 0; i < 2; i++) {
11568 context->
Global()->Delete(v8_str(
"tmp"));
11569 CompileRun(
"for (var j = 0; j < 10; j++) RegExp('')");
11582 Local<String> token = v8_str(
"<security token>");
11583 context0->SetSecurityToken(token);
11584 context1->SetSecurityToken(token);
11589 CompileRun(
"Object.prototype.x = 42; function C() {};");
11595 context1->Global()->Set(v8_str(
"other"), context0->Global());
11596 Local<Value> value = CompileRun(
"var instance = new other.C(); instance.x");
11597 CHECK(value->IsInt32());
11598 CHECK_EQ(42, value->Int32Value());
11614 gc_during_regexp_ = 0;
11615 regexp_success_ =
false;
11616 gc_success_ =
false;
11617 GCThread gc_thread(
this);
11621 LongRunningRegExp();
11627 CHECK(regexp_success_);
11628 CHECK(gc_success_);
11633 static const int kRequiredGCs = 5;
11638 : Thread(
"GCThread"), test_(test) {}
11639 virtual void Run() {
11640 test_->CollectGarbage();
11646 void CollectGarbage() {
11648 while (gc_during_regexp_ < kRequiredGCs) {
11657 gc_success_ =
true;
11660 void LongRunningRegExp() {
11663 while (gc_during_regexp_ < kRequiredGCs) {
11664 int gc_before = gc_count_;
11667 const char* c_source =
11668 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
11669 ".exec('aaaaaaaaaaaaaaab') === null";
11670 Local<String> source = String::New(c_source);
11671 Local<Script> script = Script::Compile(source);
11672 Local<Value> result = script->Run();
11673 if (!result->BooleanValue()) {
11674 gc_during_regexp_ = kRequiredGCs;
11680 const char* c_source =
11681 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
11682 ".exec('aaaaaaaaaaaaaaaab')[0] === 'aaaaaaaaaaaaaaaa'";
11683 Local<String> source = String::New(c_source);
11684 Local<Script> script = Script::Compile(source);
11685 Local<Value> result = script->Run();
11686 if (!result->BooleanValue()) {
11687 gc_during_regexp_ = kRequiredGCs;
11691 int gc_after = gc_count_;
11692 gc_during_regexp_ += gc_after - gc_before;
11696 regexp_success_ =
true;
11701 int gc_during_regexp_;
11702 bool regexp_success_;
11713 Local<Context> local_env;
11716 local_env = env.
local();
11720 CHECK(!local_env.IsEmpty());
11721 local_env->Enter();
11737 gc_during_apply_ = 0;
11738 apply_success_ =
false;
11739 gc_success_ =
false;
11740 GCThread gc_thread(
this);
11744 LongRunningApply();
11750 CHECK(apply_success_);
11751 CHECK(gc_success_);
11756 static const int kRequiredGCs = 2;
11761 : Thread(
"GCThread"), test_(test) {}
11762 virtual void Run() {
11763 test_->CollectGarbage();
11769 void CollectGarbage() {
11771 while (gc_during_apply_ < kRequiredGCs) {
11779 gc_success_ =
true;
11782 void LongRunningApply() {
11785 while (gc_during_apply_ < kRequiredGCs) {
11786 int gc_before = gc_count_;
11788 const char* c_source =
11789 "function do_very_little(bar) {"
11792 "for (var i = 0; i < 100000; i++) {"
11793 " do_very_little.apply(this, ['bar']);"
11795 Local<String> source = String::New(c_source);
11796 Local<Script> script = Script::Compile(source);
11797 Local<Value> result = script->Run();
11799 CHECK(!result.IsEmpty());
11801 int gc_after = gc_count_;
11802 gc_during_apply_ += gc_after - gc_before;
11805 apply_success_ =
true;
11810 int gc_during_apply_;
11811 bool apply_success_;
11822 Local<Context> local_env;
11825 local_env = env.
local();
11829 CHECK(!local_env.IsEmpty());
11830 local_env->Enter();
11846 "rv.alpha = 'hello';" \
11851 Local<Value> val = CompileRun(sample);
11852 CHECK(val->IsObject());
11853 Local<v8::Object> obj = val.As<
v8::Object>();
11854 obj->
Set(v8_str(
"gamma"), v8_str(
"cloneme"));
11856 CHECK_EQ(v8_str(
"hello"), obj->Get(v8_str(
"alpha")));
11858 CHECK_EQ(v8_str(
"cloneme"), obj->Get(v8_str(
"gamma")));
11861 Local<v8::Object> clone = obj->Clone();
11862 CHECK_EQ(v8_str(
"hello"), clone->Get(v8_str(
"alpha")));
11864 CHECK_EQ(v8_str(
"cloneme"), clone->Get(v8_str(
"gamma")));
11897 static void MorphAString(
i::String*
string,
11900 CHECK(i::StringShape(
string).IsExternal());
11903 CHECK(string->
map() ==
HEAP->external_ascii_string_map());
11905 string->set_map(
HEAP->external_string_map());
11913 string->set_map(
HEAP->external_ascii_string_map());
11924 char utf_buffer[129];
11925 const char* c_string =
"Now is the time for all good men"
11926 " to come to the aid of the party";
11927 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
11938 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
11940 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
11942 env->
Global()->Set(v8_str(
"lhs"), lhs);
11943 env->
Global()->Set(v8_str(
"rhs"), rhs);
11946 "var cons = lhs + rhs;"
11947 "var slice = lhs.substring(1, lhs.length - 1);"
11948 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);");
11950 CHECK(!lhs->MayContainNonAscii());
11951 CHECK(!rhs->MayContainNonAscii());
11957 Handle<String> cons = v8_compile(
"cons")->Run().As<String>();
11958 CHECK_EQ(128, cons->Utf8Length());
11960 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars));
11964 "Now is the time for all good men to come to the aid of the party"
11965 "Now is the time for all good men to come to the aid of the party"));
11969 "/[^a-z]/.test(cons);"
11970 "/[^a-z]/.test(slice);"
11971 "/[^a-z]/.test(slice_on_cons);");
11972 const char* expected_cons =
11973 "Now is the time for all good men to come to the aid of the party"
11974 "Now is the time for all good men to come to the aid of the party";
11975 const char* expected_slice =
11976 "ow is the time for all good men to come to the aid of the part";
11977 const char* expected_slice_on_cons =
11978 "ow is the time for all good men to come to the aid of the party"
11979 "Now is the time for all good men to come to the aid of the part";
11980 CHECK_EQ(String::New(expected_cons),
11981 env->
Global()->Get(v8_str(
"cons")));
11982 CHECK_EQ(String::New(expected_slice),
11983 env->
Global()->Get(v8_str(
"slice")));
11984 CHECK_EQ(String::New(expected_slice_on_cons),
11985 env->
Global()->Get(v8_str(
"slice_on_cons")));
11997 const char* ascii_sources[] = {
12005 for (
int i = 0; ascii_sources[i] !=
NULL; i++) {
12006 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
12020 : block_(i::OS::CreateSemaphore(0)),
12022 morphs_during_regexp_(0),
12023 ascii_resource_(i::Vector<const char>(
"aaaaaaaaaaaaaab", 15)),
12024 uc16_resource_(i::Vector<const
uint16_t>(two_byte_content_, 15)) {}
12027 regexp_success_ =
false;
12028 morph_success_ =
false;
12032 for (
int i = 0; i < 14; i++) {
12033 two_byte_content_[i] =
'a';
12035 two_byte_content_[14] =
'b';
12039 input_ =
FACTORY->NewExternalStringFromAscii(&ascii_resource_);
12044 i::Isolate::Current()->global_context()->global()->SetProperty(
12050 MorphThread morph_thread(
this);
12051 morph_thread.Start();
12053 LongRunningRegExp();
12056 morph_thread.Join();
12059 CHECK(regexp_success_);
12060 CHECK(morph_success_);
12065 static const int kRequiredModifications = 5;
12066 static const int kMaxModifications = 100;
12071 : Thread(
"MorphThread"), test_(test) {}
12072 virtual void Run() {
12073 test_->MorphString();
12079 void MorphString() {
12081 while (morphs_during_regexp_ < kRequiredModifications &&
12082 morphs_ < kMaxModifications) {
12087 MorphAString(
string, &ascii_resource_, &uc16_resource_);
12092 morph_success_ =
true;
12095 void LongRunningRegExp() {
12097 while (morphs_during_regexp_ < kRequiredModifications &&
12098 morphs_ < kMaxModifications) {
12099 int morphs_before = morphs_;
12103 const char* c_source =
12104 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
12105 ".exec(input) === null";
12106 Local<String> source = String::New(c_source);
12107 Local<Script> script = Script::Compile(source);
12108 Local<Value> result = script->Run();
12109 CHECK(result->IsTrue());
12111 int morphs_after = morphs_;
12112 morphs_during_regexp_ += morphs_after - morphs_before;
12114 regexp_success_ =
true;
12117 i::uc16 two_byte_content_[15];
12120 int morphs_during_regexp_;
12121 bool regexp_success_;
12122 bool morph_success_;
12135 Local<Context> local_env;
12138 local_env = env.
local();
12142 CHECK(!local_env.IsEmpty());
12143 local_env->Enter();
12155 i::FLAG_es5_readonly =
true;
12166 CompileRun(
"function f() { x = 42; return x; }; f()");
12169 res = CompileRun(
"function f() { eval('1'); y = 43; return y; }; f()");
12172 res = CompileRun(
"function f() { with (this) { y = 44 }; return y; }; f()");
12176 static int force_set_set_count = 0;
12177 static int force_set_get_count = 0;
12182 force_set_get_count++;
12193 force_set_set_count++;
12200 force_set_set_count++;
12205 force_set_get_count = 0;
12206 force_set_set_count = 0;
12207 pass_on_get =
false;
12212 templ->
SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
12219 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12222 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12225 CHECK_EQ(6, global->
Get(simple_property)->Int32Value());
12230 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
12234 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
12240 CHECK_EQ(8, global->
Get(access_property)->Int32Value());
12246 force_set_get_count = 0;
12247 force_set_set_count = 0;
12248 pass_on_get =
false;
12259 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12263 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12269 pass_on_get =
true;
12270 CHECK(global->
Get(some_property)->IsUndefined());
12276 CHECK_EQ(8, global->
Get(some_property)->Int32Value());
12281 pass_on_get =
false;
12282 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12301 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12304 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12307 CHECK(global->
Get(simple_property)->IsUndefined());
12311 static int force_delete_interceptor_count = 0;
12312 static bool pass_on_delete =
false;
12318 force_delete_interceptor_count++;
12319 if (pass_on_delete) {
12328 force_delete_interceptor_count = 0;
12329 pass_on_delete =
false;
12342 CHECK_EQ(0, force_delete_interceptor_count);
12344 CHECK_EQ(1, force_delete_interceptor_count);
12345 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
12348 pass_on_delete =
true;
12350 CHECK_EQ(2, force_delete_interceptor_count);
12351 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
12355 CHECK(global->
Get(some_property)->IsUndefined());
12356 CHECK_EQ(2, force_delete_interceptor_count);
12366 CompileRun(
"this.__proto__ = { foo: 'horse' };"
12367 "var foo = 'fish';"
12368 "function f() { return foo.length; }");
12370 CompileRun(
"for (var i = 0; i < 4; i++) f();");
12372 CHECK_EQ(4, CompileRun(
"f()")->Int32Value());
12374 CHECK(context->
Global()->ForceDelete(v8_str(
"foo")));
12378 CHECK_EQ(5, CompileRun(
"f()")->Int32Value());
12383 i::FLAG_allow_natives_syntax =
true;
12391 CompileRun(
"var G = 42; function foo() { return G; }");
12394 ctx2->Global()->Set(v8_str(
"o"), foo);
12396 "function f() { return o(); }"
12397 "for (var i = 0; i < 10; ++i) f();"
12398 "%OptimizeFunctionOnNextCall(f);"
12403 CHECK(ctx1->Global()->ForceDelete(G_property));
12410 " return e.toString();"
12413 "ReferenceError: G is not defined");
12432 CHECK(Context::GetCurrent() == calling_context0);
12433 CHECK(Context::GetCalling() == calling_context1);
12434 CHECK(Context::GetEntered() == calling_context2);
12442 calling_context0 = Context::New();
12443 calling_context1 = Context::New();
12444 calling_context2 = Context::New();
12447 Local<String> token = v8_str(
"<security token>");
12448 calling_context0->SetSecurityToken(token);
12449 calling_context1->SetSecurityToken(token);
12450 calling_context2->SetSecurityToken(token);
12453 calling_context0->Enter();
12454 Local<v8::FunctionTemplate> callback_templ =
12456 calling_context0->Global()->Set(v8_str(
"callback"),
12457 callback_templ->GetFunction());
12458 calling_context0->Exit();
12462 calling_context1->Enter();
12463 calling_context1->Global()->Set(v8_str(
"context0"),
12464 calling_context0->Global());
12465 CompileRun(
"function f() { context0.callback() }");
12466 calling_context1->Exit();
12470 calling_context2->Enter();
12471 calling_context2->Global()->Set(v8_str(
"context1"),
12472 calling_context1->Global());
12473 CompileRun(
"context1.f()");
12474 calling_context2->Exit();
12480 calling_context0.
Clear();
12481 calling_context1.
Clear();
12482 calling_context2.
Clear();
12489 i::FLAG_es52_globals =
true;
12493 CompileRun(
"__proto__.x = 42");
12514 CHECK(!obj->
Get(foo_string)->IsUndefined());
12523 CompileRun(
"function f(obj) { return obj.x; }\n"
12524 "var obj = { x: { foo: 42 }, y: 87 };\n"
12527 "for (var i = 0; i < 5; i++) f(obj);");
12532 CHECK_EQ(42, CompileRun(
"f(this).foo")->Int32Value());
12539 const int kElementCount = 260;
12540 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
12543 FACTORY->NewExternalArray(kElementCount,
12548 for (
int i = 0; i < kElementCount; i++) {
12549 pixels->set(i, i % 256);
12553 for (
int i = 0; i < kElementCount; i++) {
12554 CHECK_EQ(i % 256, pixels->get_scalar(i));
12565 context->
Global()->Set(v8_str(
"pixels"), obj);
12568 result = CompileRun(
"pixels[1]");
12569 CHECK_EQ(1, result->Int32Value());
12571 result = CompileRun(
"var sum = 0;"
12572 "for (var i = 0; i < 8; i++) {"
12573 " sum += pixels[i] = pixels[i] = -i;"
12576 CHECK_EQ(-28, result->Int32Value());
12578 result = CompileRun(
"var sum = 0;"
12579 "for (var i = 0; i < 8; i++) {"
12580 " sum += pixels[i] = pixels[i] = 0;"
12583 CHECK_EQ(0, result->Int32Value());
12585 result = CompileRun(
"var sum = 0;"
12586 "for (var i = 0; i < 8; i++) {"
12587 " sum += pixels[i] = pixels[i] = 255;"
12590 CHECK_EQ(8 * 255, result->Int32Value());
12592 result = CompileRun(
"var sum = 0;"
12593 "for (var i = 0; i < 8; i++) {"
12594 " sum += pixels[i] = pixels[i] = 256 + i;"
12597 CHECK_EQ(2076, result->Int32Value());
12599 result = CompileRun(
"var sum = 0;"
12600 "for (var i = 0; i < 8; i++) {"
12601 " sum += pixels[i] = pixels[i] = i;"
12604 CHECK_EQ(28, result->Int32Value());
12606 result = CompileRun(
"var sum = 0;"
12607 "for (var i = 0; i < 8; i++) {"
12608 " sum += pixels[i];"
12611 CHECK_EQ(28, result->Int32Value());
12618 i::USE(no_failure);
12624 i::USE(no_failure);
12626 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
12631 i::USE(no_failure);
12634 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12635 " pixels[i] = (i * 65) - 109;"
12637 "pixels[1] + pixels[6];");
12638 CHECK_EQ(255, result->Int32Value());
12642 i::Smi::cast(jsobj->GetElement(2)->ToObjectChecked())->value());
12644 i::Smi::cast(jsobj->GetElement(3)->ToObjectChecked())->value());
12646 i::Smi::cast(jsobj->GetElement(4)->ToObjectChecked())->value());
12648 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
12650 i::Smi::cast(jsobj->GetElement(6)->ToObjectChecked())->value());
12652 i::Smi::cast(jsobj->GetElement(7)->ToObjectChecked())->value());
12653 result = CompileRun(
"var sum = 0;"
12654 "for (var i = 0; i < 8; i++) {"
12655 " sum += pixels[i];"
12658 CHECK_EQ(984, result->Int32Value());
12660 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12661 " pixels[i] = (i * 1.1);"
12663 "pixels[1] + pixels[6];");
12664 CHECK_EQ(8, result->Int32Value());
12674 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12675 " pixels[7] = undefined;"
12678 CHECK_EQ(0, result->Int32Value());
12681 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12682 " pixels[6] = '2.3';"
12685 CHECK_EQ(2, result->Int32Value());
12688 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12689 " pixels[5] = NaN;"
12692 CHECK_EQ(0, result->Int32Value());
12695 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12696 " pixels[8] = Infinity;"
12699 CHECK_EQ(255, result->Int32Value());
12701 i::Smi::cast(jsobj->GetElement(8)->ToObjectChecked())->value());
12703 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
12704 " pixels[9] = -Infinity;"
12707 CHECK_EQ(0, result->Int32Value());
12710 result = CompileRun(
"pixels[3] = 33;"
12711 "delete pixels[3];"
12713 CHECK_EQ(33, result->Int32Value());
12715 result = CompileRun(
"pixels[0] = 10; pixels[1] = 11;"
12716 "pixels[2] = 12; pixels[3] = 13;"
12717 "pixels.__defineGetter__('2',"
12718 "function() { return 120; });"
12720 CHECK_EQ(12, result->Int32Value());
12722 result = CompileRun(
"var js_array = new Array(40);"
12723 "js_array[0] = 77;"
12727 result = CompileRun(
"pixels[1] = 23;"
12728 "pixels.__proto__ = [];"
12729 "js_array.__proto__ = pixels;"
12730 "js_array.concat(pixels);");
12734 result = CompileRun(
"pixels[1] = 23;");
12735 CHECK_EQ(23, result->Int32Value());
12739 result = CompileRun(
"pixels[256] = 255;");
12740 CHECK_EQ(255, result->Int32Value());
12741 result = CompileRun(
"var i = 0;"
12742 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
12744 CHECK_EQ(255, result->Int32Value());
12748 result = CompileRun(
"function pa_load(p) {"
12750 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
12753 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12754 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
12755 "just_ints = new Object();"
12756 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
12757 "for (var i = 0; i < 10; ++i) {"
12758 " result = pa_load(just_ints);"
12761 CHECK_EQ(32640, result->Int32Value());
12764 result = CompileRun(
"function pa_load(p, start) {"
12766 " for (var j = start; j < 256; j++) { sum += p[j]; }"
12769 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12770 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
12771 "for (var i = 0; i < 10; ++i) {"
12772 " result = pa_load(pixels,-10);"
12775 CHECK_EQ(0, result->Int32Value());
12778 result = CompileRun(
"function pa_load(p) {"
12780 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
12783 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12784 "just_ints = new Object();"
12785 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
12786 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
12787 "for (var i = 0; i < 10; ++i) {"
12788 " result = pa_load(pixels);"
12791 CHECK_EQ(32640, result->Int32Value());
12795 result = CompileRun(
"function pa_load(p, start) {"
12797 " for (var j = start; j < 256; j++) { sum += p[j]; }"
12800 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12801 "just_ints = new Object();"
12802 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
12803 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
12804 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
12805 "for (var i = 0; i < 10; ++i) {"
12806 " result = pa_load(pixels,-10);"
12809 CHECK_EQ(0, result->Int32Value());
12814 result = CompileRun(
"function pa_load(p) {"
12816 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
12819 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12820 "just_ints = new Object();"
12821 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
12822 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
12823 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
12824 "sparse_array = new Object();"
12825 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
12826 "sparse_array[1000000] = 3;"
12827 "for (var i = 0; i < 10; ++i) {"
12828 " result = pa_load(sparse_array);"
12831 CHECK_EQ(32640, result->Int32Value());
12834 result = CompileRun(
"function pa_store(p) {"
12835 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
12837 "pa_store(pixels);"
12839 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
12841 CHECK_EQ(48896, result->Int32Value());
12845 result = CompileRun(
"function pa_store(p,start) {"
12846 " for (var j = 0; j < 256; j++) {"
12847 " p[j+start] = j * 2;"
12850 "pa_store(pixels,0);"
12851 "pa_store(pixels,-128);"
12853 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
12855 CHECK_EQ(65280, result->Int32Value());
12859 result = CompileRun(
"function pa_store(p,start) {"
12860 " for (var j = 0; j < 256; j++) {"
12861 " p[j+start] = j * 2;"
12864 "pa_store(pixels,0);"
12865 "just_ints = new Object();"
12866 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
12867 "pa_store(just_ints, 0);"
12868 "pa_store(pixels,-128);"
12870 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
12872 CHECK_EQ(65280, result->Int32Value());
12876 result = CompileRun(
"function pa_store(p) {"
12877 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
12879 "pa_store(pixels);"
12880 "just_ints = new Object();"
12881 "pa_store(just_ints);"
12882 "pa_store(pixels);"
12884 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
12886 CHECK_EQ(48896, result->Int32Value());
12889 result = CompileRun(
"function pa_load(p) {"
12891 " for (var i=0; i<256; ++i) {"
12896 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
12897 "for (var i = 0; i < 5000; ++i) {"
12898 " result = pa_load(pixels);"
12901 CHECK_EQ(32640, result->Int32Value());
12904 result = CompileRun(
"function pa_init(p) {"
12905 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
12907 "function pa_load(p) {"
12909 " for (var i=0; i<256; ++i) {"
12914 "for (var i = 0; i < 5000; ++i) {"
12915 " pa_init(pixels);"
12917 "result = pa_load(pixels);"
12919 CHECK_EQ(32640, result->Int32Value());
12928 for (
int size = 0; size < 100; size += 10) {
12929 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(size));
12942 const AccessorInfo& info) {
12950 Local<Value> value,
12951 const AccessorInfo& info) {
12960 const int kElementCount = 260;
12961 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
12964 FACTORY->NewExternalArray(kElementCount,
12967 for (
int i = 0; i < kElementCount; i++) {
12968 pixels->set(i, i % 256);
12972 NotHandledIndexedPropertySetter);
12975 context->
Global()->Set(v8_str(
"pixels"), obj);
12978 result = CompileRun(
"var sum = 0;"
12979 "for (var i = 0; i < 8; i++) {"
12980 " sum += pixels[i] = pixels[i] = -i;"
12983 CHECK_EQ(-28, result->Int32Value());
12984 result = CompileRun(
"pixels.hasOwnProperty('1')");
12985 CHECK(result->BooleanValue());
12991 switch (array_type) {
13018 template <
class ExternalArrayClass,
class ElementType>
13024 const int kElementCount = 40;
13025 int element_size = ExternalArrayElementSize(array_type);
13026 ElementType* array_data =
13027 static_cast<ElementType*
>(malloc(kElementCount * element_size));
13030 FACTORY->NewExternalArray(kElementCount, array_type, array_data));
13033 for (
int i = 0; i < kElementCount; i++) {
13034 array->set(i, static_cast<ElementType>(i));
13038 for (
int i = 0; i < kElementCount; i++) {
13040 static_cast<int64_t>(array->get_scalar(i)));
13041 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
13051 1, static_cast<int>(jsobj->GetElement(1)->ToObjectChecked()->Number()));
13053 context->
Global()->Set(v8_str(
"ext_array"), obj);
13056 result = CompileRun(
"ext_array[1]");
13057 CHECK_EQ(1, result->Int32Value());
13060 result = CompileRun(
"var sum = 0;"
13061 "for (var i = 0; i < 8; i++) {"
13062 " sum += ext_array[i] = ext_array[i] = -i;"
13065 CHECK_EQ(-28, result->Int32Value());
13068 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13069 " ext_array[i] = i;"
13072 "for (var i = 0; i < 8; i++) {"
13073 " sum += ext_array[i];"
13076 CHECK_EQ(28, result->Int32Value());
13079 result = CompileRun(
"for (var i = 8; --i >= 0; ) {"
13080 " ext_array[i] = i;"
13083 "for (var i = 0; i < 8; i++) {"
13084 " sum += ext_array[i];"
13087 CHECK_EQ(28, result->Int32Value());
13090 result = CompileRun(
"var sum = 0;"
13091 "for (var i = 0; i < 16; i+=2) {"
13092 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);"
13095 CHECK_EQ(-28, result->Int32Value());
13098 result = CompileRun(
"for (var i = 0; i < 16; i+=2) {"
13099 " ext_array[i] = (i * 0.5);"
13102 "for (var i = 0; i < 16; i+=2) {"
13103 " sum += ext_array[i];"
13106 CHECK_EQ(28, result->Int32Value());
13109 result = CompileRun(
"for (var i = 14; i >= 0; i-=2) {"
13110 " ext_array[i] = (i * 0.5);"
13113 "for (var i = 0; i < 16; i+=2) {"
13114 " sum += ext_array[i];"
13117 CHECK_EQ(28, result->Int32Value());
13123 const char* boundary_program =
13125 "for (var i = 0; i < 16; i++) {"
13126 " ext_array[i] = %lld;"
13128 " res = ext_array[i];"
13135 result = CompileRun(test_buf.start());
13136 CHECK_EQ(low, result->IntegerValue());
13141 result = CompileRun(test_buf.start());
13142 CHECK_EQ(high, result->IntegerValue());
13145 result = CompileRun(
"var tmp_array = ext_array;"
13147 "for (var i = 0; i < 8; i++) {"
13148 " tmp_array[i] = i;"
13149 " sum += tmp_array[i];"
13157 CHECK_EQ(28, result->Int32Value());
13161 "var caught_exception = false;"
13165 " caught_exception = true;"
13167 "caught_exception;",
13169 result = CompileRun(test_buf.start());
13170 CHECK_EQ(
false, result->BooleanValue());
13174 "var caught_exception = false;"
13176 " ext_array[%d] = 1;"
13178 " caught_exception = true;"
13180 "caught_exception;",
13182 result = CompileRun(test_buf.start());
13183 CHECK_EQ(
false, result->BooleanValue());
13186 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13187 " ext_array[7] = undefined;"
13190 CHECK_EQ(0, result->Int32Value());
13195 static_cast<int>(jsobj->GetElement(7)->ToObjectChecked()->Number()));
13198 jsobj->GetElement(7)->ToObjectChecked()->Number()));
13201 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13202 " ext_array[6] = '2.3';"
13205 CHECK_EQ(2, result->Int32Value());
13207 2, static_cast<int>(jsobj->GetElement(6)->ToObjectChecked()->Number()));
13213 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13214 " ext_array[i] = 5;"
13216 "for (var i = 0; i < 8; i++) {"
13217 " ext_array[i] = NaN;"
13220 CHECK_EQ(0, result->Int32Value());
13222 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13224 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13225 " ext_array[i] = 5;"
13227 "for (var i = 0; i < 8; i++) {"
13228 " ext_array[i] = Infinity;"
13231 int expected_value =
13233 CHECK_EQ(expected_value, result->Int32Value());
13235 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13237 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13238 " ext_array[i] = 5;"
13240 "for (var i = 0; i < 8; i++) {"
13241 " ext_array[i] = -Infinity;"
13244 CHECK_EQ(0, result->Int32Value());
13246 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13249 const char* unsigned_data =
13250 "var source_data = [0.6, 10.6];"
13251 "var expected_results = [0, 10];";
13252 const char* signed_data =
13253 "var source_data = [0.6, 10.6, -0.6, -10.6];"
13254 "var expected_results = [0, 10, 0, -10];";
13255 const char* pixel_data =
13256 "var source_data = [0.6, 10.6];"
13257 "var expected_results = [1, 11];";
13266 "var all_passed = true;"
13267 "for (var i = 0; i < source_data.length; i++) {"
13268 " for (var j = 0; j < 8; j++) {"
13269 " ext_array[j] = source_data[i];"
13271 " all_passed = all_passed &&"
13272 " (ext_array[5] == expected_results[i]);"
13277 (is_pixel_data ? pixel_data : signed_data)));
13278 result = CompileRun(test_buf.start());
13279 CHECK_EQ(
true, result->BooleanValue());
13282 for (
int i = 0; i < kElementCount; i++) {
13283 array->set(i, static_cast<ElementType>(i));
13286 result = CompileRun(
"function ee_op_test_complex_func(sum) {"
13287 " for (var i = 0; i < 40; ++i) {"
13288 " sum += (ext_array[i] += 1);"
13289 " sum += (ext_array[i] -= 1);"
13294 "for (var i=0;i<10000;++i) {"
13295 " sum=ee_op_test_complex_func(sum);"
13298 CHECK_EQ(16000000, result->Int32Value());
13301 result = CompileRun(
"function ee_op_test_count_func(sum) {"
13302 " for (var i = 0; i < 40; ++i) {"
13303 " sum += (++ext_array[i]);"
13304 " sum += (--ext_array[i]);"
13309 "for (var i=0;i<10000;++i) {"
13310 " sum=ee_op_test_count_func(sum);"
13313 CHECK_EQ(16000000, result->Int32Value());
13315 result = CompileRun(
"ext_array[3] = 33;"
13316 "delete ext_array[3];"
13318 CHECK_EQ(33, result->Int32Value());
13320 result = CompileRun(
"ext_array[0] = 10; ext_array[1] = 11;"
13321 "ext_array[2] = 12; ext_array[3] = 13;"
13322 "ext_array.__defineGetter__('2',"
13323 "function() { return 120; });"
13325 CHECK_EQ(12, result->Int32Value());
13327 result = CompileRun(
"var js_array = new Array(40);"
13328 "js_array[0] = 77;"
13332 result = CompileRun(
"ext_array[1] = 23;"
13333 "ext_array.__proto__ = [];"
13334 "js_array.__proto__ = ext_array;"
13335 "js_array.concat(ext_array);");
13339 result = CompileRun(
"ext_array[1] = 23;");
13340 CHECK_EQ(23, result->Int32Value());
13347 const int kXSize = 300;
13348 const int kYSize = 300;
13349 const int kLargeElementCount = kXSize * kYSize * 4;
13350 ElementType* large_array_data =
13351 static_cast<ElementType*
>(malloc(kLargeElementCount * element_size));
13356 kLargeElementCount);
13357 context->
Global()->Set(v8_str(
"large_array"), large_obj);
13359 for (
int x = 0; x < 300; x++) {
13361 int offset = row * 300 * 4;
13362 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13363 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13364 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13365 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13367 offset = row * 300 * 4;
13368 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13369 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13370 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13371 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13373 offset = row * 300 * 4;
13374 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13375 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13376 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13377 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13383 result = CompileRun(
"var failed = false;"
13385 "for (var i = 0; i < 300; i++) {"
13386 " if (large_array[4 * i] != 127 ||"
13387 " large_array[4 * i + 1] != 0 ||"
13388 " large_array[4 * i + 2] != 0 ||"
13389 " large_array[4 * i + 3] != 127) {"
13393 "offset = 150 * 300 * 4;"
13394 "for (var i = 0; i < 300; i++) {"
13395 " if (large_array[offset + 4 * i] != 127 ||"
13396 " large_array[offset + 4 * i + 1] != 0 ||"
13397 " large_array[offset + 4 * i + 2] != 0 ||"
13398 " large_array[offset + 4 * i + 3] != 127) {"
13402 "offset = 298 * 300 * 4;"
13403 "for (var i = 0; i < 300; i++) {"
13404 " if (large_array[offset + 4 * i] != 127 ||"
13405 " large_array[offset + 4 * i + 1] != 0 ||"
13406 " large_array[offset + 4 * i + 2] != 0 ||"
13407 " large_array[offset + 4 * i + 3] != 127) {"
13412 CHECK_EQ(
true, result->BooleanValue());
13413 free(large_array_data);
13420 result = CompileRun(
"ext_array[''] = 23; ext_array['']");
13421 CHECK_EQ(23, result->Int32Value());
13432 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13433 result = CompileRun(
"ext_array['']");
13434 CHECK_EQ(1503, result->Int32Value());
13446 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13447 result = CompileRun(
"ext_array['']");
13448 CHECK_EQ(1503, result->Int32Value());
13460 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13461 result = CompileRun(
"ext_array['']");
13472 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13473 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
13474 "ext_array['']();");
13483 context->
Global()->Set(v8_str(
"ext_array"), obj3);
13500 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13501 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
13502 "ext_array['']();");
13510 ExternalArrayTestHelper<i::ExternalByteArray, int8_t>(
13518 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>(
13526 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
13534 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
13542 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>(
13550 ExternalArrayTestHelper<i::ExternalIntArray, int32_t>(
13558 ExternalArrayTestHelper<i::ExternalUnsignedIntArray, uint32_t>(
13566 ExternalArrayTestHelper<i::ExternalFloatArray, float>(
13574 ExternalArrayTestHelper<i::ExternalDoubleArray, double>(
13582 TestExternalByteArray();
13583 TestExternalUnsignedByteArray();
13584 TestExternalShortArray();
13585 TestExternalUnsignedShortArray();
13586 TestExternalIntArray();
13587 TestExternalUnsignedIntArray();
13588 TestExternalFloatArray();
13595 for (
int size = 0; size < 100; size += 10) {
13596 int element_size = ExternalArrayElementSize(array_type);
13597 void* external_data = malloc(size * element_size);
13600 external_data, array_type, size);
13605 free(external_data);
13626 const char *source =
"foo";
13643 const char *source =
"function foo() { FAIL.FAIL; }; foo();";
13649 CHECK(strstr(*stack,
"at foo (stack-trace-test") !=
NULL);
13655 const char* expected_func_name,
int expected_line_number,
13656 int expected_column,
bool is_eval,
bool is_constructor,
13661 if (*script_name ==
NULL) {
13665 CHECK(strstr(*script_name, expected_script_name) !=
NULL);
13667 CHECK(strstr(*func_name, expected_func_name) !=
NULL);
13677 const char* origin =
"capture-stack-trace-test";
13678 const int kOverviewTest = 1;
13679 const int kDetailedTest = 2;
13683 int testGroup = args[0]->Int32Value();
13684 if (testGroup == kOverviewTest) {
13700 }
else if (testGroup == kDetailedTest) {
13708 #ifdef ENABLE_DEBUGGER_SUPPORT
13709 bool is_eval =
true;
13710 #else // ENABLE_DEBUGGER_SUPPORT
13711 bool is_eval =
false;
13712 #endif // ENABLE_DEBUGGER_SUPPORT
13733 Local<ObjectTemplate> templ = ObjectTemplate::New();
13734 templ->Set(v8_str(
"AnalyzeStackInNativeCode"),
13740 const char *overview_source =
13741 "function bar() {\n"
13742 " var y; AnalyzeStackInNativeCode(1);\n"
13744 "function foo() {\n"
13748 "var x;eval('new foo();');";
13756 const char *detailed_source =
13757 "function bat() {AnalyzeStackInNativeCode(2);\n"
13760 "function baz() {\n"
13763 "eval('new baz();');";
13772 CHECK(!detailed_result.IsEmpty());
13773 CHECK(detailed_result->IsObject());
13777 static void StackTraceForUncaughtExceptionListener(
13788 TEST(CaptureStackTraceForUncaughtException) {
13795 Script::Compile(v8_str(
"function foo() {\n"
13798 "function bar() {\n"
13801 v8_str(
"origin"))->Run();
13803 Local<Value> trouble = global->
Get(v8_str(
"bar"));
13804 CHECK(trouble->IsFunction());
13805 Function::Cast(*trouble)->Call(global, 0,
NULL);
13811 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
13819 "var setters = ['column', 'lineNumber', 'scriptName',\n"
13820 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
13821 " 'isConstructor'];\n"
13822 "for (var i = 0; i < setters.length; i++) {\n"
13823 " var prop = setters[i];\n"
13824 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n"
13826 CompileRun(
"throw 'exception';");
13838 int line_number[] = {1, 2, 5};
13839 for (
int i = 0; i < frame_count; i++) {
13854 const char* source =
13855 "function g() { error; } \n"
13856 "function f() { g(); } \n"
13857 "function t(e) { throw e; } \n"
13860 "} catch (e1) { \n"
13863 " } catch (e2) { \n"
13869 CompileRun(source);
13881 int line_number[] = {3, 7};
13882 for (
int i = 0; i < frame_count; i++) {
13894 const char* source =
13895 "function g() { throw 404; } \n"
13896 "function f() { g(); } \n"
13897 "function t(e) { throw e; } \n"
13900 "} catch (e1) { \n"
13905 CompileRun(source);
13926 const char* source =
13927 "var e = new Error(); \n"
13931 CompileRun(source);
13951 const char* source =
13952 "var e = {__proto__: new Error()} \n"
13956 CompileRun(source);
13968 for (
int i = 0; i < 3; i++) {
13970 stackTrace->
GetFrame(i)->GetScriptNameOrSourceURL();
13980 Local<ObjectTemplate> templ = ObjectTemplate::New();
13981 templ->Set(v8_str(
"AnalyzeStackOfEvalWithSourceURL"),
13985 const char *source =
13986 "function outer() {\n"
13987 "function bar() {\n"
13988 " AnalyzeStackOfEvalWithSourceURL();\n"
13990 "function foo() {\n"
13996 "eval('(' + outer +')()//@ sourceURL=eval_url');";
13997 CHECK(CompileRun(source)->IsUndefined());
14001 static void CreateGarbageInOldSpace() {
14004 for (
int i = 0; i < 1000; i++) {
14011 const intptr_t
MB = 1024 * 1024;
14014 intptr_t initial_size =
HEAP->SizeOfObjects();
14015 CreateGarbageInOldSpace();
14016 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14017 CHECK_GT(size_with_garbage, initial_size + MB);
14018 bool finished =
false;
14019 for (
int i = 0; i < 200 && !finished; i++) {
14022 intptr_t final_size =
HEAP->SizeOfObjects();
14024 CHECK_LT(final_size, initial_size + 1);
14030 const intptr_t
MB = 1024 * 1024;
14031 const int IdlePauseInMs = 900;
14034 intptr_t initial_size =
HEAP->SizeOfObjects();
14035 CreateGarbageInOldSpace();
14036 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14037 CHECK_GT(size_with_garbage, initial_size + MB);
14038 bool finished =
false;
14039 for (
int i = 0; i < 200 && !finished; i++) {
14042 intptr_t final_size =
HEAP->SizeOfObjects();
14044 CHECK_LT(final_size, initial_size + 1);
14050 const intptr_t
MB = 1024 * 1024;
14051 const int IdlePauseInMs = 900;
14054 intptr_t initial_size =
HEAP->SizeOfObjects();
14055 CreateGarbageInOldSpace();
14056 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14057 CHECK_GT(size_with_garbage, initial_size + MB);
14058 bool finished =
false;
14059 for (
int i = 0; i < 200 && !finished; i++) {
14062 intptr_t final_size =
HEAP->SizeOfObjects();
14064 CHECK_LT(final_size, initial_size + 1);
14069 const intptr_t
MB = 1024 * 1024;
14070 const int kShortIdlePauseInMs = 100;
14071 const int kLongIdlePauseInMs = 1000;
14074 intptr_t initial_size =
HEAP->SizeOfObjects();
14078 for (
int i = 0; i < 7; i++) {
14081 CreateGarbageInOldSpace();
14088 CreateGarbageInOldSpace();
14089 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14090 CHECK_GT(size_with_garbage, initial_size + MB);
14091 bool finished =
false;
14092 for (
int i = 0; i < 200 && !finished; i++) {
14095 intptr_t final_size =
HEAP->SizeOfObjects();
14096 CHECK_LT(final_size, initial_size + 1);
14099 static uint32_t* stack_limit;
14102 stack_limit =
reinterpret_cast<uint32_t*
>(
14103 i::Isolate::Current()->stack_guard()->real_climit());
14111 static uint32_t* ComputeStackLimit(uint32_t size) {
14112 uint32_t* answer = &size - (size /
sizeof(size));
14117 if (answer > &size)
return reinterpret_cast<uint32_t*
>(
sizeof(size));
14123 static const int K = 1024;
14124 uint32_t* set_limit = ComputeStackLimit(128 * K);
14134 Local<v8::FunctionTemplate> fun_templ =
14136 Local<Function> fun = fun_templ->GetFunction();
14137 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
14138 CompileRun(
"get_stack_limit();");
14140 CHECK(stack_limit == set_limit);
14145 uint32_t* set_limit;
14148 static const int K = 1024;
14149 set_limit = ComputeStackLimit(128 * K);
14159 Local<v8::FunctionTemplate> fun_templ =
14161 Local<Function> fun = fun_templ->GetFunction();
14162 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
14163 CompileRun(
"get_stack_limit();");
14165 CHECK(stack_limit == set_limit);
14169 CHECK(stack_limit == set_limit);
14191 found_resource1_(
false),
14192 found_resource2_(
false) {}
14200 string->GetExternalStringResource();
14202 if (resource1_ == resource) {
14203 CHECK(!found_resource1_);
14204 found_resource1_ =
true;
14206 if (resource2_ == resource) {
14207 CHECK(!found_resource2_);
14208 found_resource2_ =
true;
14212 CHECK(found_resource1_);
14213 CHECK(found_resource2_);
14219 bool found_resource1_;
14220 bool found_resource2_;
14226 const char*
string =
"Some string";
14227 uint16_t* two_byte_string = AsciiToTwoByteString(
string);
14239 visitor.CheckVisitedResources();
14243 static double DoubleFromBits(uint64_t value) {
14245 memcpy(&target, &value,
sizeof(target));
14250 static uint64_t DoubleToBits(
double value) {
14252 memcpy(&target, &value,
sizeof(target));
14257 static double DoubleToDateTime(
double input) {
14258 double date_limit = 864e13;
14259 if (IsNaN(input) || input < -date_limit || input > date_limit) {
14262 return (input < 0) ? -(floor(-input)) : floor(input);
14267 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
14268 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
14278 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
14279 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
14280 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
14281 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
14282 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
14283 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
14284 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
14288 double date_limit = 864e13;
14290 double test_values[] = {
14312 int num_test_values = 20;
14314 for (
int i = 0; i < num_test_values; i++) {
14315 double test_value = test_values[i];
14320 if (!IsNaN(test_value)) {
14321 CHECK_EQ(test_value, stored_number);
14323 uint64_t stored_bits = DoubleToBits(stored_number);
14325 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
14328 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
14330 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
14337 double expected_stored_date = DoubleToDateTime(test_value);
14339 if (!IsNaN(expected_stored_date)) {
14340 CHECK_EQ(expected_stored_date, stored_date);
14342 uint64_t stored_bits = DoubleToBits(stored_date);
14344 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
14347 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
14349 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
14379 " toString: function () {"
14391 CHECK_EQ(0, strcmp(*value,
"Hey!"));
14405 other_context = Context::New();
14409 const char* source_simple =
"1";
14410 context = Context::New();
14416 context->SetData(obj);
14417 CompileRun(source_simple);
14421 for (gc_count = 1; gc_count < 10; gc_count++) {
14422 other_context->Enter();
14423 CompileRun(source_simple);
14424 other_context->Exit();
14426 if (GetGlobalObjectsCount() == 1)
break;
14429 CHECK_EQ(1, GetGlobalObjectsCount());
14433 const char* source_eval =
"function f(){eval('1')}; f()";
14434 context = Context::New();
14439 CompileRun(source_eval);
14443 for (gc_count = 1; gc_count < 10; gc_count++) {
14444 other_context->Enter();
14445 CompileRun(source_eval);
14446 other_context->Exit();
14448 if (GetGlobalObjectsCount() == 1)
break;
14451 CHECK_EQ(1, GetGlobalObjectsCount());
14455 const char* source_exception =
"function f(){throw 1;} f()";
14456 context = Context::New();
14462 CompileRun(source_exception);
14465 CHECK(!message.IsEmpty());
14466 CHECK_EQ(1, message->GetLineNumber());
14470 for (gc_count = 1; gc_count < 10; gc_count++) {
14471 other_context->Enter();
14472 CompileRun(source_exception);
14473 other_context->Exit();
14475 if (GetGlobalObjectsCount() == 1)
break;
14478 CHECK_EQ(1, GetGlobalObjectsCount());
14489 "function f() {}\n\nfunction g() {}");
14502 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
14510 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
14522 "function f() {}\n\nfunction g() {}");
14539 "function foo() {}\n\n function bar() {}");
14556 "function foo() {}\n\n function bar() {}");
14569 const AccessorInfo& info) {
14574 static void SetterWhichSetsYOnThisTo23(Local<String> name,
14575 Local<Value> value,
14576 const AccessorInfo& info) {
14577 info.This()->Set(v8_str(
"y"), v8_num(23));
14583 Local<ObjectTemplate> templ = ObjectTemplate::New();
14584 templ->SetAccessor(v8_str(
"x"),
14585 GetterWhichReturns42,
14586 SetterWhichSetsYOnThisTo23);
14588 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
14589 CompileRun(
"function C1() {"
14592 "C1.prototype = P;"
14596 "C2.prototype = { };"
14597 "C2.prototype.__proto__ = P;");
14601 for (
int i = 0; i < 10; i++) {
14603 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
14604 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
14608 for (
int i = 0; i < 10; i++) {
14610 CHECK_EQ(42, c2->
Get(v8_str(
"x"))->Int32Value());
14611 CHECK_EQ(23, c2->
Get(v8_str(
"y"))->Int32Value());
14617 Local<String> name,
const AccessorInfo& info) {
14623 Local<String> name, Local<Value> value,
const AccessorInfo& info) {
14624 if (name->Equals(v8_str(
"x"))) {
14625 info.This()->Set(v8_str(
"y"), v8_num(23));
14633 Local<ObjectTemplate> templ = ObjectTemplate::New();
14634 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
14635 NamedPropertySetterWhichSetsYOnThisTo23);
14637 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
14638 CompileRun(
"function C1() {"
14641 "C1.prototype = P;"
14645 "C2.prototype = { };"
14646 "C2.prototype.__proto__ = P;");
14650 for (
int i = 0; i < 10; i++) {
14652 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
14653 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
14657 for (
int i = 0; i < 10; i++) {
14659 CHECK_EQ(23, c2->
Get(v8_str(
"x"))->Int32Value());
14660 CHECK_EQ(42, c2->
Get(v8_str(
"y"))->Int32Value());
14666 const char* source =
"function C1() {"
14669 "C1.prototype = P;";
14677 prototype->
Set(v8_str(
"y"), v8_num(42));
14678 context->
Global()->Set(v8_str(
"P"), prototype);
14681 CompileRun(source);
14686 for (
int i = 0; i < 256; i++) {
14688 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
14689 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
14693 Local<ObjectTemplate> templ = ObjectTemplate::New();
14694 templ->SetAccessor(v8_str(
"x"),
14695 GetterWhichReturns42,
14696 SetterWhichSetsYOnThisTo23);
14697 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
14700 CompileRun(source);
14703 for (
int i = 0; i < 10; i++) {
14705 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
14706 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
14746 CHECK_EQ(1, prologue_call_count_second);
14747 CHECK_EQ(1, epilogue_call_count_second);
14753 CHECK_EQ(2, prologue_call_count_second);
14754 CHECK_EQ(2, epilogue_call_count_second);
14760 CHECK_EQ(2, prologue_call_count_second);
14761 CHECK_EQ(2, epilogue_call_count_second);
14766 i::FLAG_allow_natives_syntax =
true;
14775 " var r0 = %_GetFromCache(0, key0);"
14776 " var r1 = %_GetFromCache(0, key1);"
14777 " var r0_ = %_GetFromCache(0, key0);"
14779 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
14780 " var r1_ = %_GetFromCache(0, key1);"
14782 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
14783 " return 'PASSED';"
14785 HEAP->ClearJSFunctionResultCaches();
14786 ExpectString(code,
"PASSED");
14790 static const int k0CacheSize = 16;
14793 i::FLAG_allow_natives_syntax =
true;
14801 " var r = %_GetFromCache(0, k);"
14802 " for (var i = 0; i < 16; i++) {"
14803 " %_GetFromCache(0, 'a' + i);"
14805 " if (r === %_GetFromCache(0, k))"
14806 " return 'FAILED: k0CacheSize is too small';"
14807 " return 'PASSED';"
14809 HEAP->ClearJSFunctionResultCaches();
14810 ExpectString(code,
"PASSED");
14815 i::FLAG_allow_natives_syntax =
true;
14823 " for (var i = 0; i < 16; i++) keys.push(i);"
14824 " var values = [];"
14825 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
14826 " for (var i = 0; i < 16; i++) {"
14827 " var v = %_GetFromCache(0, keys[i]);"
14828 " if (v.toString() !== values[i].toString())"
14829 " return 'Wrong value for ' + "
14830 " keys[i] + ': ' + v + ' vs. ' + values[i];"
14832 " return 'PASSED';"
14834 HEAP->ClearJSFunctionResultCaches();
14835 ExpectString(code,
"PASSED");
14840 i::FLAG_allow_natives_syntax =
true;
14848 " for (var i = 0; i < 16; i++) keys.push(i);"
14849 " var values = [];"
14850 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
14851 " for (var i = 15; i >= 16; i--) {"
14852 " var v = %_GetFromCache(0, keys[i]);"
14853 " if (v !== values[i])"
14854 " return 'Wrong value for ' + "
14855 " keys[i] + ': ' + v + ' vs. ' + values[i];"
14857 " return 'PASSED';"
14859 HEAP->ClearJSFunctionResultCaches();
14860 ExpectString(code,
"PASSED");
14865 i::FLAG_allow_natives_syntax =
true;
14872 " for (var i = 0; i < 2*16; i++) {"
14873 " %_GetFromCache(0, 'a' + i);"
14875 " return 'PASSED';"
14877 HEAP->ClearJSFunctionResultCaches();
14878 ExpectString(code,
"PASSED");
14887 const char* init_code =
14888 "var str1 = 'abelspendabel';"
14889 "var str2 = str1 + str1 + str1;"
14891 Local<Value> result = CompileRun(init_code);
14893 Local<Value> indexof = CompileRun(
"str2.indexOf('els')");
14894 Local<Value> lastindexof = CompileRun(
"str2.lastIndexOf('dab')");
14896 CHECK(result->IsString());
14898 int length =
string->length();
14899 CHECK(string->IsAsciiRepresentation());
14904 CHECK(string->IsAsciiRepresentation());
14905 CHECK(flat_string->IsAsciiRepresentation());
14911 uc16_buffer[length] = 0;
14915 flat_string->MakeExternal(&resource);
14917 CHECK(flat_string->IsTwoByteRepresentation());
14924 CHECK(string->IsAsciiRepresentation());
14926 CHECK_EQ(0, cons->second()->length());
14927 CHECK(cons->first()->IsTwoByteRepresentation());
14932 Local<Value> reresult = CompileRun(
"str2.match(/abel/g).length;");
14933 CHECK_EQ(6, reresult->Int32Value());
14936 reresult = CompileRun(
"str2.match(/abe./g).length;");
14937 CHECK_EQ(6, reresult->Int32Value());
14939 reresult = CompileRun(
"str2.search(/bel/g);");
14940 CHECK_EQ(1, reresult->Int32Value());
14942 reresult = CompileRun(
"str2.search(/be./g);");
14943 CHECK_EQ(1, reresult->Int32Value());
14945 ExpectTrue(
"/bel/g.test(str2);");
14947 ExpectTrue(
"/be./g.test(str2);");
14949 reresult = CompileRun(
"/bel/g.exec(str2);");
14950 CHECK(!reresult->IsNull());
14952 reresult = CompileRun(
"/be./g.exec(str2);");
14953 CHECK(!reresult->IsNull());
14955 ExpectString(
"str2.substring(2, 10);",
"elspenda");
14957 ExpectString(
"str2.substring(2, 20);",
"elspendabelabelspe");
14959 ExpectString(
"str2.charAt(2);",
"e");
14961 ExpectObject(
"str2.indexOf('els');", indexof);
14963 ExpectObject(
"str2.lastIndexOf('dab');", lastindexof);
14965 reresult = CompileRun(
"str2.charCodeAt(2);");
14966 CHECK_EQ(static_cast<int32_t>(
'e'), reresult->Int32Value());
14973 Local<v8::Value> data) {
14991 IndexedGetAccessBlocker,
14997 context0->
Global()->Set(v8_str(
"x"), v8_num(42));
15003 context1->
Global()->Set(v8_str(
"other"), global0);
15006 ExpectUndefined(
"other.x");
15009 ExpectUndefined(
"other[0]");
15016 result = CompileRun(
"other[0] = new Object()");
15017 CHECK(result->IsObject());
15020 ExpectFalse(
"\'x\' in other");
15023 ExpectFalse(
"0 in other");
15026 ExpectFalse(
"delete other.x");
15036 ExpectUndefined(
"Object.prototype.__defineGetter__.call("
15037 " other, \'x\', function() { return 42; })");
15040 ExpectUndefined(
"Object.prototype.__lookupGetter__.call("
15044 ExpectFalse(
"Object.prototype.hasOwnProperty.call(other, \'0\')");
15058 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15059 printf(
"*** %s\n",
"DefaultIsolateGetCurrent success");
15066 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15067 CHECK(current_isolate != isolate);
15071 last_location = last_message =
NULL;
15082 ExpectString(
"'hello'",
"hello");
15083 current_isolate->
Enter();
15084 ExpectString(
"'still working'",
"still working");
15085 current_isolate->
Exit();
15086 ExpectString(
"'still working 2'",
"still working 2");
15087 current_isolate->
Exit();
15092 ExpectString(
"'still working 3'",
"still working 3");
15101 ExpectString(
"'run some V8'",
"run some V8");
15104 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15105 last_location = last_message =
NULL;
15126 CompileRun(
"var foo = 153;");
15127 ExpectTrue(
"function f() { return foo == 153; }; f()");
15133 ExpectTrue(
"function f() {"
15145 last_location = last_message =
NULL;
15151 ExpectTrue(
"function f() { return bar == 371; }; f()");
15161 ExpectTrue(
"true");
15163 last_location = last_message =
NULL;
15180 CompileRun(
"var foo = 'isolate 1';");
15181 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15195 CompileRun(
"var foo = 'isolate 2';");
15196 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
15203 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15216 ExpectTrue(
"function f() {"
15224 "var isDefaultIsolate = true;"
15234 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
15240 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15252 last_location = last_message =
NULL;
15266 ExpectTrue(
"function f() { return isDefaultIsolate; }; f()");
15270 static int CalcFibonacci(
v8::Isolate* isolate,
int limit) {
15276 " if (n <= 2) return 1;"
15277 " return fib(n-1) + fib(n-2);"
15280 Local<Value> value = CompileRun(code.start());
15281 CHECK(value->IsNumber());
15282 return static_cast<int>(value->NumberValue());
15288 :
Thread(
"IsolateThread"),
15290 fib_limit_(fib_limit),
15294 result_ = CalcFibonacci(isolate_, fib_limit_);
15305 TEST(MultipleIsolatesOnIndividualThreads) {
15335 Persistent<v8::Context> context;
15341 Local<Value> v = CompileRun(
"2");
15342 CHECK(v->IsNumber());
15343 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
15350 Local<Value> v = CompileRun(
"22");
15351 CHECK(v->IsNumber());
15352 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
15368 :
Thread(
"InitDefaultIsolateThread"),
15369 testCase_(testCase),
15373 switch (testCase_) {
15379 static const int K = 1024;
15421 TEST(InitializeDefaultIsolateOnSecondaryThread1) {
15425 TEST(InitializeDefaultIsolateOnSecondaryThread2) {
15429 TEST(InitializeDefaultIsolateOnSecondaryThread3) {
15433 TEST(InitializeDefaultIsolateOnSecondaryThread4) {
15437 TEST(InitializeDefaultIsolateOnSecondaryThread5) {
15441 TEST(InitializeDefaultIsolateOnSecondaryThread6) {
15448 "(function() { return \"a\".charAt(0); })()";
15454 ExpectString(code,
"a");
15455 ExpectString(code,
"a");
15463 CompileRun(
"String.prototype.charAt = function() { return \"not a\"; }");
15464 ExpectString(code,
"not a");
15471 "(function() { return (42).toString(); })()";
15477 ExpectString(code,
"42");
15478 ExpectString(code,
"42");
15486 CompileRun(
"Number.prototype.toString = function() { return \"not 42\"; }");
15487 ExpectString(code,
"not 42");
15494 "(function() { return true.toString(); })()";
15500 ExpectString(code,
"true");
15501 ExpectString(code,
"true");
15509 CompileRun(
"Boolean.prototype.toString = function() { return \"\"; }");
15510 ExpectString(code,
"");
15516 const char* function_code =
15517 "function readCell() { while (true) { return cell; } }";
15524 CompileRun(
"var cell = \"first\";");
15525 ExpectBoolean(
"delete cell",
false);
15526 CompileRun(function_code);
15527 ExpectString(
"readCell()",
"first");
15528 ExpectString(
"readCell()",
"first");
15535 CompileRun(
"cell = \"second\";");
15536 CompileRun(function_code);
15537 ExpectString(
"readCell()",
"second");
15538 ExpectBoolean(
"delete cell",
true);
15539 ExpectString(
"(function() {"
15541 " return readCell();"
15543 " return e.toString();"
15546 "ReferenceError: cell is not defined");
15547 CompileRun(
"cell = \"new_second\";");
15549 ExpectString(
"readCell()",
"new_second");
15550 ExpectString(
"readCell()",
"new_second");
15555 TEST(DontDeleteCellLoadICForceDelete) {
15556 const char* function_code =
15557 "function readCell() { while (true) { return cell; } }";
15563 CompileRun(
"var cell = \"value\";");
15564 ExpectBoolean(
"delete cell",
false);
15565 CompileRun(function_code);
15566 ExpectString(
"readCell()",
"value");
15567 ExpectString(
"readCell()",
"value");
15571 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
15572 ExpectString(
"(function() {"
15574 " return readCell();"
15576 " return e.toString();"
15579 "ReferenceError: cell is not defined");
15584 const char* function_code =
15585 "function readCell() { while (true) { return cell; } }";
15592 ExpectBoolean(
"delete cell",
false);
15593 CompileRun(function_code);
15594 ExpectString(
"readCell()",
"value");
15595 ExpectString(
"readCell()",
"value");
15599 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
15600 ExpectString(
"(function() {"
15602 " return readCell();"
15604 " return e.toString();"
15607 "ReferenceError: cell is not defined");
15623 CHECK(re->IsRegExp());
15624 CHECK(re->GetSource()->Equals(v8_str(
"bar")));
15626 static_cast<int>(re->GetFlags()));
15631 CHECK(re->IsRegExp());
15632 CHECK(re->GetSource()->Equals(v8_str(
"baz")));
15634 static_cast<int>(re->GetFlags()));
15637 CHECK(re->IsRegExp());
15638 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
15641 re = CompileRun(
"/quux/gm").As<
v8::RegExp>();
15642 CHECK(re->IsRegExp());
15643 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
15645 static_cast<int>(re->GetFlags()));
15649 CompileRun(
"RegExp = function() {}");
15652 CHECK(re->IsRegExp());
15653 CHECK(re->GetSource()->Equals(v8_str(
"foobar")));
15659 CHECK(re->IsRegExp());
15660 CHECK(re->GetSource()->Equals(v8_str(
"foobarbaz")));
15662 static_cast<int>(re->GetFlags()));
15664 context->
Global()->Set(v8_str(
"re"), re);
15665 ExpectTrue(
"re.test('FoobarbaZ')");
15674 CHECK(re.IsEmpty());
15675 CHECK(try_catch.HasCaught());
15676 context->
Global()->Set(v8_str(
"ex"), try_catch.Exception());
15677 ExpectTrue(
"ex instanceof SyntaxError");
15702 return v8_str(
"42!");
15708 result->
Set(0, v8_str(
"universalAnswer"));
15719 tmpl->SetNamedPropertyHandler(Getter,
NULL,
NULL,
NULL, Enumerator);
15720 context->
Global()->Set(v8_str(
"o"), tmpl->NewInstance());
15722 "var result = []; for (var k in o) result.push(k); result"));
15724 CHECK_EQ(v8_str(
"universalAnswer"), result->
Get(0));
15733 CompileRun(
"(function() {"
15734 " Object.defineProperty("
15737 " { configurable: true, enumerable: true, value: 3 });"
15738 "})").
As<Function>();
15740 define_property->
Call(proxy, 0,
NULL);
15745 Context::Scope scope(context);
15746 CompileRun(
"Object.prototype").As<
Object>()->
15752 CHECK_EQ(expected, object->
Get(v8_str(
"context_id"))->Int32Value());
15757 HandleScope handle_scope;
15758 Persistent<Context> context1 = Context::New();
15759 InstallContextId(context1, 1);
15760 Persistent<Context> context2 = Context::New();
15761 InstallContextId(context2, 2);
15762 Persistent<Context> context3 = Context::New();
15763 InstallContextId(context3, 3);
15767 Local<Object> object1;
15768 Local<Function> func1;
15770 Context::Scope scope(context1);
15771 object1 = Object::New();
15772 func1 = tmpl->GetFunction();
15775 Local<Object> object2;
15776 Local<Function> func2;
15778 Context::Scope scope(context2);
15779 object2 = Object::New();
15780 func2 = tmpl->GetFunction();
15783 Local<Object> instance1;
15784 Local<Object> instance2;
15787 Context::Scope scope(context3);
15788 instance1 = func1->NewInstance();
15789 instance2 = func2->NewInstance();
15792 CHECK(object1->CreationContext() == context1);
15793 CheckContextId(object1, 1);
15794 CHECK(func1->CreationContext() == context1);
15795 CheckContextId(func1, 1);
15796 CHECK(instance1->CreationContext() == context1);
15797 CheckContextId(instance1, 1);
15798 CHECK(object2->CreationContext() == context2);
15799 CheckContextId(object2, 2);
15800 CHECK(func2->CreationContext() == context2);
15801 CheckContextId(func2, 2);
15802 CHECK(instance2->CreationContext() == context2);
15803 CheckContextId(instance2, 2);
15806 Context::Scope scope(context1);
15807 CHECK(object1->CreationContext() == context1);
15808 CheckContextId(object1, 1);
15809 CHECK(func1->CreationContext() == context1);
15810 CheckContextId(func1, 1);
15811 CHECK(instance1->CreationContext() == context1);
15812 CheckContextId(instance1, 1);
15813 CHECK(object2->CreationContext() == context2);
15814 CheckContextId(object2, 2);
15815 CHECK(func2->CreationContext() == context2);
15816 CheckContextId(func2, 2);
15817 CHECK(instance2->CreationContext() == context2);
15818 CheckContextId(instance2, 2);
15822 Context::Scope scope(context2);
15823 CHECK(object1->CreationContext() == context1);
15824 CheckContextId(object1, 1);
15825 CHECK(func1->CreationContext() == context1);
15826 CheckContextId(func1, 1);
15827 CHECK(instance1->CreationContext() == context1);
15828 CheckContextId(instance1, 1);
15829 CHECK(object2->CreationContext() == context2);
15830 CheckContextId(object2, 2);
15831 CHECK(func2->CreationContext() == context2);
15832 CheckContextId(func2, 2);
15833 CHECK(instance2->CreationContext() == context2);
15834 CheckContextId(instance2, 2);
15837 context1.Dispose();
15838 context2.Dispose();
15839 context3.Dispose();
15844 HandleScope handle_scope;
15845 Persistent<Context> context = Context::New();
15846 InstallContextId(context, 1);
15848 Local<Object>
function;
15850 Context::Scope scope(context);
15851 function = CompileRun(
"function foo() {}; foo").As<
Object>();
15854 CHECK(function->CreationContext() == context);
15855 CheckContextId(
function, 1);
15862 const AccessorInfo& info) {
15863 if (index == 42)
return v8_str(
"yes");
15864 return Handle<v8::Integer>();
15869 const AccessorInfo& info) {
15870 if (property->Equals(v8_str(
"foo")))
return v8_str(
"yes");
15871 return Handle<Value>();
15876 uint32_t index,
const AccessorInfo& info) {
15878 return Handle<v8::Integer>();
15883 Local<String> property,
const AccessorInfo& info) {
15884 if (property->Equals(v8_str(
"foo")))
return v8_num(1).
As<
v8::Integer>();
15885 return Handle<v8::Integer>();
15890 Local<String> property,
const AccessorInfo& info) {
15891 if (property->Equals(v8_str(
"bar")))
return v8_num(1).
As<
v8::Integer>();
15892 return Handle<v8::Integer>();
15897 const AccessorInfo& info) {
15898 return v8_str(
"yes");
15906 Handle<Value> value = CompileRun(
15909 " this.__defineGetter__('baz', function() { return 1; });"
15911 "function Bar() { "
15913 " this.__defineGetter__('bla', function() { return 2; });"
15915 "Bar.prototype = new Foo();"
15917 CHECK(value->IsObject());
15918 Handle<Object>
object = value->ToObject();
15919 CHECK(object->Has(v8_str(
"foo")));
15920 CHECK(!object->HasOwnProperty(v8_str(
"foo")));
15921 CHECK(object->HasOwnProperty(v8_str(
"bar")));
15922 CHECK(object->Has(v8_str(
"baz")));
15923 CHECK(!object->HasOwnProperty(v8_str(
"baz")));
15924 CHECK(object->HasOwnProperty(v8_str(
"bla")));
15927 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15929 Handle<Object> instance = templ->NewInstance();
15930 CHECK(!instance->HasOwnProperty(v8_str(
"42")));
15931 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
15932 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
15935 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15937 Handle<Object> instance = templ->NewInstance();
15938 CHECK(instance->HasOwnProperty(v8_str(
"42")));
15939 CHECK(!instance->HasOwnProperty(v8_str(
"43")));
15940 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
15943 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15945 Handle<Object> instance = templ->NewInstance();
15946 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
15947 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
15950 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15952 Handle<Object> instance = templ->NewInstance();
15953 CHECK(instance->HasOwnProperty(v8_str(
"42")));
15954 CHECK(!instance->HasOwnProperty(v8_str(
"41")));
15957 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15959 Handle<Object> instance = templ->NewInstance();
15960 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
15961 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
15964 Handle<ObjectTemplate> templ = ObjectTemplate::New();
15968 Handle<Object> instance = templ->NewInstance();
15969 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
15970 CHECK(instance->HasOwnProperty(v8_str(
"bar")));
15976 Handle<Value> result = CompileRun(
"eval('42')");
15977 CHECK_EQ(42, result->Int32Value());
15978 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
15979 CHECK_EQ(42, result->Int32Value());
15980 result = CompileRun(
"var f = new Function('return 42'); f()");
15981 CHECK_EQ(42, result->Int32Value());
15986 TryCatch try_catch;
15988 Handle<Value> result = CompileRun(
"eval('42')");
15989 CHECK(result.IsEmpty());
15990 CHECK(try_catch.HasCaught());
15993 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
15994 CHECK(result.IsEmpty());
15995 CHECK(try_catch.HasCaught());
15998 result = CompileRun(
"var f = new Function('return 42'); f()");
15999 CHECK(result.IsEmpty());
16000 CHECK(try_catch.HasCaught());
16055 Handle<Function>
function = templ->GetFunction();
16056 context->
Global()->Set(v8_str(
"f"),
function);
16057 TryCatch try_catch;
16058 CompileRun(
"f.call(2)");
16065 Local<ObjectTemplate> templ = ObjectTemplate::New();
16068 Local<v8::Object> obj = templ->NewInstance();
16069 context->
Global()->Set(v8_str(
"obj"), obj);
16070 obj->Set(v8_str(
"1"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16071 obj->Set(v8_str(
"1"), v8_str(
"foobar"));
16072 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"1")));
16073 obj->Set(v8_num(2), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16074 obj->Set(v8_num(2), v8_str(
"foobar"));
16075 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_num(2)));
16078 obj->Set(v8_str(
"2000000000"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16079 obj->Set(v8_str(
"2000000000"), v8_str(
"foobar"));
16080 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"2000000000")));
16089 CompileRun(
"({'a': 0})");
16099 i::Isolate::Current()->heap()->CollectAllGarbage(
true);
16100 {
i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache();
16101 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) {
16109 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
16112 Local<Value> data) {
16115 name->IsString() &&
16116 name->ToString()->Length() == 9 &&
16117 name->ToString()->Utf8Length() == 9) {
16119 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
16120 return strncmp(buffer,
"__proto__", 9) != 0;
16133 no_proto_template->SetAccessCheckCallbacks(
16134 BlockProtoNamedSecurityTestCallback,
16135 IndexedSecurityTestCallback);
16139 hidden_proto_template->SetHiddenPrototype(
true);
16141 Local<FunctionTemplate> protected_hidden_proto_template =
16143 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
16144 BlockProtoNamedSecurityTestCallback,
16145 IndexedSecurityTestCallback);
16146 protected_hidden_proto_template->SetHiddenPrototype(
true);
16153 Local<Object> simple_object = Object::New();
16156 Local<Object> protected_object =
16157 no_proto_template->NewInstance();
16160 Local<Object> proxy_object =
16164 Local<Object> global_object =
16165 proxy_object->GetPrototype()->ToObject();
16168 Local<Object> hidden_prototype =
16169 hidden_proto_template->GetFunction()->NewInstance();
16170 Local<Object> object_with_hidden =
16172 object_with_hidden->SetPrototype(hidden_prototype);
16175 Local<Object> protected_hidden_prototype =
16176 protected_hidden_proto_template->GetFunction()->NewInstance();
16177 Local<Object> object_with_protected_hidden =
16179 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
16185 Local<ObjectTemplate> global_template = ObjectTemplate::New();
16186 global_template->Set(v8_str(
"simple"), simple_object);
16187 global_template->Set(v8_str(
"protected"), protected_object);
16188 global_template->Set(v8_str(
"global"), global_object);
16189 global_template->Set(v8_str(
"proxy"), proxy_object);
16190 global_template->Set(v8_str(
"hidden"), object_with_hidden);
16191 global_template->Set(v8_str(
"phidden"), object_with_protected_hidden);
16195 Local<Value> result1 = CompileRun(
"Object.getPrototypeOf(simple)");
16196 CHECK(result1->Equals(simple_object->GetPrototype()));
16198 Local<Value> result2 = CompileRun(
"Object.getPrototypeOf(protected)");
16201 Local<Value> result3 = CompileRun(
"Object.getPrototypeOf(global)");
16202 CHECK(result3->Equals(global_object->GetPrototype()));
16204 Local<Value> result4 = CompileRun(
"Object.getPrototypeOf(proxy)");
16207 Local<Value> result5 = CompileRun(
"Object.getPrototypeOf(hidden)");
16208 CHECK(result5->Equals(
16209 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
16211 Local<Value> result6 = CompileRun(
"Object.getPrototypeOf(phidden)");
16220 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
16223 env->
Global()->Set(v8_str(
"Intercept"), intercept->GetFunction());
16224 CompileRun(
"var a = new Object();"
16225 "var b = new Intercept();"
16226 "var c = new Object();"
16230 "for (var i = 0; i < 3; i++) c.x;");
16231 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
16232 ExpectInt32(
"c.x", 23);
16233 CompileRun(
"a.y = 42;"
16234 "for (var i = 0; i < 3; i++) c.x;");
16235 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
16236 ExpectInt32(
"c.x", 23);
16237 ExpectBoolean(
"c.hasOwnProperty('y')",
false);
16238 ExpectInt32(
"c.y", 42);
16242 static void TestReceiver(Local<Value> expected_result,
16243 Local<Value> expected_receiver,
16244 const char* code) {
16245 Local<Value> result = CompileRun(code);
16246 CHECK(result->IsObject());
16247 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
16248 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
16261 foreign_context->Enter();
16262 Local<Value> foreign_function =
16263 CompileRun(
"function func() { return { 0: this.id, "
16265 " toString: function() { "
16272 CHECK(foreign_function->IsFunction());
16273 foreign_context->Exit();
16277 Local<String> password = v8_str(
"Password");
16281 foreign_context->SetSecurityToken(password);
16283 Local<String> i = v8_str(
"i");
16284 Local<String> o = v8_str(
"o");
16285 Local<String>
id = v8_str(
"id");
16287 CompileRun(
"function ownfunc() { return { 0: this.id, "
16289 " toString: function() { "
16296 context->
Global()->Set(v8_str(
"func"), foreign_function);
16299 CHECK(i->Equals(foreign_context->Global()->Get(
id)));
16304 TestReceiver(o, context->
Global(),
"ownfunc.call()");
16305 TestReceiver(o, context->
Global(),
"ownfunc.apply()");
16307 TestReceiver(o, context->
Global(),
"[1].map(ownfunc)[0]");
16308 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/,ownfunc)[1]")));
16309 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[1]")));
16310 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[3]")));
16312 TestReceiver(o, context->
Global(),
"ownfunc()");
16314 TestReceiver(o, context->
Global(),
"(1,ownfunc)()");
16318 TestReceiver(i, foreign_context->Global(),
"func.call()");
16319 TestReceiver(i, foreign_context->Global(),
"func.apply()");
16321 TestReceiver(i, foreign_context->Global(),
16322 "Function.prototype.call.call(func)");
16323 TestReceiver(i, foreign_context->Global(),
16324 "Function.prototype.call.apply(func)");
16325 TestReceiver(i, foreign_context->Global(),
16326 "Function.prototype.apply.call(func)");
16327 TestReceiver(i, foreign_context->Global(),
16328 "Function.prototype.apply.apply(func)");
16330 TestReceiver(i, foreign_context->Global(),
"[1].map(func)[0]");
16332 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/,func)[1]")));
16333 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[1]")));
16334 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[3]")));
16338 TestReceiver(o, context->
Global(),
"func()");
16340 TestReceiver(o, context->
Global(),
"(1,func)()");
16342 foreign_context.Dispose();
16351 callback_fired ^= 1;
16357 callback_fired ^= 2;
16362 int32_t level = args[0]->Int32Value();
16365 i::OS::Print(
"Entering recursion level %d.\n", level);
16369 CompileRun(script_vector.
start());
16385 env->
Global()->Set(v8_str(
"recursion"),
16392 Local<Script> script =
16398 callback_fired = 0;
16404 callback_fired = 0;
16405 Local<Function> recursive_function =
16406 Local<Function>::Cast(env->
Global()->Get(v8_str(
"recursion")));
16408 recursive_function->Call(env->
Global(), 1, args);
16415 CompileRun(
"1+1;");
16421 CompileRun(
"throw 'second exception';");
16425 TEST(CallCompletedCallbackOneException) {
16429 CompileRun(
"throw 'exception';");
16433 TEST(CallCompletedCallbackTwoExceptions) {
16437 CompileRun(
"throw 'first exception';");
16441 static int probes_counter = 0;
16442 static int misses_counter = 0;
16443 static int updates_counter = 0;
16446 static int* LookupCounter(
const char* name) {
16447 if (strcmp(name,
"c:V8.MegamorphicStubCacheProbes") == 0) {
16448 return &probes_counter;
16449 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheMisses") == 0) {
16450 return &misses_counter;
16451 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheUpdates") == 0) {
16452 return &updates_counter;
16458 static const char* kMegamorphicTestProgram =
16459 "function ClassA() { };"
16460 "function ClassB() { };"
16461 "ClassA.prototype.foo = function() { };"
16462 "ClassB.prototype.foo = function() { };"
16463 "function fooify(obj) { obj.foo(); };"
16464 "var a = new ClassA();"
16465 "var b = new ClassB();"
16466 "for (var i = 0; i < 10000; i++) {"
16472 static void StubCacheHelper(
bool primary) {
16473 V8::SetCounterFunction(LookupCounter);
16474 USE(kMegamorphicTestProgram);
16476 i::FLAG_native_code_counters =
true;
16478 i::FLAG_test_primary_stub_cache =
true;
16480 i::FLAG_test_secondary_stub_cache =
true;
16482 i::FLAG_crankshaft =
false;
16485 int initial_probes = probes_counter;
16486 int initial_misses = misses_counter;
16487 int initial_updates = updates_counter;
16488 CompileRun(kMegamorphicTestProgram);
16489 int probes = probes_counter - initial_probes;
16490 int misses = misses_counter - initial_misses;
16491 int updates = updates_counter - initial_updates;
16500 StubCacheHelper(
true);
16505 StubCacheHelper(
false);
16509 static int fatal_error_callback_counter = 0;
16510 static void CountingErrorCallback(
const char* location,
const char* message) {
16511 printf(
"CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
16512 fatal_error_callback_counter++;
16535 CHECK_EQ(0, fatal_error_callback_counter);
16538 i::Isolate::Current()->TearDown();
16540 CHECK_EQ(1, fatal_error_callback_counter);
16542 CHECK_EQ(2, fatal_error_callback_counter);
16544 CHECK_EQ(3, fatal_error_callback_counter);
16546 CHECK_EQ(4, fatal_error_callback_counter);
16548 CHECK_EQ(5, fatal_error_callback_counter);
16550 CHECK_EQ(6, fatal_error_callback_counter);
16552 CHECK_EQ(7, fatal_error_callback_counter);
16554 CHECK_EQ(8, fatal_error_callback_counter);
16556 CHECK_EQ(9, fatal_error_callback_counter);
16564 static void* data1 =
reinterpret_cast<void*
>(0xacce55ed);
16568 static void* data2 =
reinterpret_cast<void*
>(0xdecea5ed);
16588 CHECK_EQ(0, fatal_error_callback_counter);
16591 i::Isolate::Current()->TearDown();
16593 CHECK_EQ(1, fatal_error_callback_counter);
16595 CHECK_EQ(2, fatal_error_callback_counter);
16597 CHECK_EQ(3, fatal_error_callback_counter);
16601 static int instance_checked_getter_count = 0;
16602 static Handle<Value> InstanceCheckedGetter(Local<String> name,
16603 const AccessorInfo& info) {
16605 instance_checked_getter_count++;
16610 static int instance_checked_setter_count = 0;
16611 static void InstanceCheckedSetter(Local<String> name,
16612 Local<Value> value,
16613 const AccessorInfo& info) {
16616 instance_checked_setter_count++;
16620 static void CheckInstanceCheckedResult(
int getters,
16622 bool expects_callbacks,
16623 TryCatch* try_catch) {
16624 if (expects_callbacks) {
16625 CHECK(!try_catch->HasCaught());
16626 CHECK_EQ(getters, instance_checked_getter_count);
16627 CHECK_EQ(setters, instance_checked_setter_count);
16629 CHECK(try_catch->HasCaught());
16630 CHECK_EQ(0, instance_checked_getter_count);
16631 CHECK_EQ(0, instance_checked_setter_count);
16633 try_catch->Reset();
16637 static void CheckInstanceCheckedAccessors(
bool expects_callbacks) {
16638 instance_checked_getter_count = 0;
16639 instance_checked_setter_count = 0;
16640 TryCatch try_catch;
16643 CompileRun(
"obj.foo");
16644 CheckInstanceCheckedResult(1, 0, expects_callbacks, &try_catch);
16645 CompileRun(
"obj.foo = 23");
16646 CheckInstanceCheckedResult(1, 1, expects_callbacks, &try_catch);
16649 CompileRun(
"function test_get(o) { o.foo; }"
16651 CheckInstanceCheckedResult(2, 1, expects_callbacks, &try_catch);
16652 CompileRun(
"test_get(obj);");
16653 CheckInstanceCheckedResult(3, 1, expects_callbacks, &try_catch);
16654 CompileRun(
"test_get(obj);");
16655 CheckInstanceCheckedResult(4, 1, expects_callbacks, &try_catch);
16656 CompileRun(
"function test_set(o) { o.foo = 23; }"
16658 CheckInstanceCheckedResult(4, 2, expects_callbacks, &try_catch);
16659 CompileRun(
"test_set(obj);");
16660 CheckInstanceCheckedResult(4, 3, expects_callbacks, &try_catch);
16661 CompileRun(
"test_set(obj);");
16662 CheckInstanceCheckedResult(4, 4, expects_callbacks, &try_catch);
16665 CompileRun(
"%OptimizeFunctionOnNextCall(test_get);"
16667 CheckInstanceCheckedResult(5, 4, expects_callbacks, &try_catch);
16668 CompileRun(
"%OptimizeFunctionOnNextCall(test_set);"
16670 CheckInstanceCheckedResult(5, 5, expects_callbacks, &try_catch);
16673 CompileRun(
"%DeoptimizeFunction(test_get);"
16674 "%ClearFunctionTypeFeedback(test_get);"
16675 "%DeoptimizeFunction(test_set);"
16676 "%ClearFunctionTypeFeedback(test_set);");
16681 v8::internal::FLAG_allow_natives_syntax =
true;
16685 Local<FunctionTemplate> templ = FunctionTemplate::New();
16686 Local<ObjectTemplate> inst = templ->InstanceTemplate();
16687 inst->SetAccessor(v8_str(
"foo"),
16688 InstanceCheckedGetter, InstanceCheckedSetter,
16693 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
16695 printf(
"Testing positive ...\n");
16696 CompileRun(
"var obj = new f();");
16697 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16698 CheckInstanceCheckedAccessors(
true);
16700 printf(
"Testing negative ...\n");
16701 CompileRun(
"var obj = {};"
16702 "obj.__proto__ = new f();");
16703 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16704 CheckInstanceCheckedAccessors(
false);
16709 v8::internal::FLAG_allow_natives_syntax =
true;
16713 Local<FunctionTemplate> templ = FunctionTemplate::New();
16714 Local<ObjectTemplate> inst = templ->InstanceTemplate();
16716 inst->SetAccessor(v8_str(
"foo"),
16717 InstanceCheckedGetter, InstanceCheckedSetter,
16722 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
16724 printf(
"Testing positive ...\n");
16725 CompileRun(
"var obj = new f();");
16726 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16727 CheckInstanceCheckedAccessors(
true);
16729 printf(
"Testing negative ...\n");
16730 CompileRun(
"var obj = {};"
16731 "obj.__proto__ = new f();");
16732 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16733 CheckInstanceCheckedAccessors(
false);
16738 v8::internal::FLAG_allow_natives_syntax =
true;
16742 Local<FunctionTemplate> templ = FunctionTemplate::New();
16743 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
16744 proto->SetAccessor(v8_str(
"foo"),
16745 InstanceCheckedGetter, InstanceCheckedSetter,
16750 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
16752 printf(
"Testing positive ...\n");
16753 CompileRun(
"var obj = new f();");
16754 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16755 CheckInstanceCheckedAccessors(
true);
16757 printf(
"Testing negative ...\n");
16758 CompileRun(
"var obj = {};"
16759 "obj.__proto__ = new f();");
16760 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16761 CheckInstanceCheckedAccessors(
false);
16763 printf(
"Testing positive with modified prototype chain ...\n");
16764 CompileRun(
"var obj = new f();"
16766 "pro.__proto__ = obj.__proto__;"
16767 "obj.__proto__ = pro;");
16768 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
16769 CheckInstanceCheckedAccessors(
true);
16780 TryCatch try_catch;
16781 const char* trigger_ic =
16783 " throw new Error('test'); \n"
16788 CompileRun(trigger_ic);
16789 CHECK(try_catch.HasCaught());
16790 Local<Message> message = try_catch.Message();
16791 CHECK(!message.IsEmpty());
16792 CHECK_EQ(2, message->GetLineNumber());
16798 TryCatch try_catch;
16799 const char* throw_again =
16801 " throw new Error('test'); \n"
16805 " throw new Error('again'); \n"
16807 CompileRun(throw_again);
16808 CHECK(try_catch.HasCaught());
16809 Local<Message> message = try_catch.Message();
16810 CHECK(!message.IsEmpty());
16811 CHECK_EQ(6, message->GetLineNumber());
static void RunAllTests()
Handle< v8::Array > NonStrictArgsIndexedPropertyEnumerator(const AccessorInfo &info)
v8::Handle< Value > keyed_call_ic_function
static Isolate * GetCurrent()
void MakeWeak(void *parameters, WeakReferenceCallback callback)
void OOMCallback(const char *location, const char *message)
Handle< Array >(* NamedPropertyEnumerator)(const AccessorInfo &info)
Handle< Value > GetScriptData() const
V8EXPORT int Length() const
v8::Persistent< Script > script_
v8::Persistent< v8::Object > some_object
V8EXPORT double NumberValue() const
static Object * Cast(Value *obj)
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
int GetLineNumber() const
void FlattenString(Handle< String > string)
static void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
V8EXPORT int WriteUtf8(char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const
v8::Persistent< Context > calling_context2
V8EXPORT bool HasRealIndexedProperty(uint32_t index)
TestAsciiResourceWithDisposeControl(const char *data, bool dispose)
void set_max_young_space_size(int value)
v8::Handle< v8::Array > CheckThisIndexedPropertyEnumerator(const AccessorInfo &info)
#define CHECK_EQ(expected, value)
V8EXPORT bool IsTrue() const
V8EXPORT uint8_t * GetIndexedPropertiesPixelData()
v8::Handle< Value > call_ic_function
void StoringErrorCallback(const char *location, const char *message)
RegExpStringModificationTest()
v8::Handle< v8::Value > Fail(const v8::Arguments &args)
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
v8::Handle< Value > AnalyzeStackOfEvalWithSourceURL(const v8::Arguments &args)
V8EXPORT bool DeleteHiddenValue(Handle< String > key)
Handle< Boolean > V8EXPORT True()
V8EXPORT Local< String > GetSource() const
void(* CallCompletedCallback)()
Handle< Value >(* NamedPropertySetter)(Local< String > property, Local< Value > value, const AccessorInfo &info)
Handle< Value > HasOwnPropertyAccessorGetter(Local< String > property, const AccessorInfo &info)
Thread(const Options &options)
v8::Handle< Value > ThrowFromC(const v8::Arguments &args)
void SetSecurityToken(Handle< Value > token)
Local< Value > Exception() const
static MapCache * cast(Object *obj)
static bool IsInitialized(v8::Isolate *isolate)
void CallCompletedCallbackNoException()
void HandleCreatingCallback(v8::Persistent< v8::Value > handle, void *)
v8::Persistent< Context > calling_context1
V8EXPORT bool StrictEquals(Handle< Value > that) const
Handle< Value > InterceptorSetter(Local< String > name, Local< Value > value, const AccessorInfo &info)
Local< Object > Holder() const
static void SetAddHistogramSampleFunction(AddHistogramSampleCallback)
bool HasOutOfMemoryException()
V8EXPORT Local< Value > Get(Handle< Value > key)
static Smi * FromInt(int value)
V8EXPORT bool IsNativeError() const
void V8EXPORT RegisterExtension(Extension *extension)
Local< Object > NewInstance()
void PrologueCallback(v8::GCType, v8::GCCallbackFlags)
V8EXPORT Local< Array > GetOwnPropertyNames()
v8::Persistent< v8::Object > to_be_disposed
int echo_named_call_count
void SimpleAccessorSetter(Local< String > name, Local< Value > value, const AccessorInfo &info)
v8::Handle< v8::Integer > CheckThisIndexedPropertyQuery(uint32_t index, const AccessorInfo &info)
value format" "after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false, "print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false, "print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false, "report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true, "garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true, "flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true, "use incremental marking") DEFINE_bool(incremental_marking_steps, true, "do incremental marking steps") DEFINE_bool(trace_incremental_marking, false, "trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true, "Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false, "Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true, "use inline caching") DEFINE_bool(native_code_counters, false, "generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false, "Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true, "Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false, "Never perform compaction on full GC-testing only") DEFINE_bool(compact_code_space, true, "Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true, "Flush inline caches prior to mark compact collection and" "flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0, "Default seed for initializing random generator" "(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true, "allows verbose printing") DEFINE_bool(allow_natives_syntax, false, "allow natives syntax") DEFINE_bool(trace_sim, false, "Trace simulator execution") DEFINE_bool(check_icache, false, "Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8, "Stack alingment in bytes in simulator(4 or 8, 8 is default)") DEFINE_bool(trace_exception, false, "print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false, "preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true, "randomize hashes to avoid predictable hash collisions" "(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0, "Fixed seed to use to hash property keys(0 means random)" "(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false, "activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true, "generate optimized regexp code") DEFINE_bool(testing_bool_flag, true, "testing_bool_flag") DEFINE_int(testing_int_flag, 13, "testing_int_flag") DEFINE_float(testing_float_flag, 2.5, "float-flag") DEFINE_string(testing_string_flag, "Hello, world!", "string-flag") DEFINE_int(testing_prng_seed, 42, "Seed used for threading test randomness") DEFINE_string(testing_serialization_file, "/tmp/serdes", "file in which to serialize heap") DEFINE_bool(help, false, "Print usage message, including flags, on console") DEFINE_bool(dump_counters, false, "Dump counters on exit") DEFINE_string(map_counters, "", "Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT, "Pass all remaining arguments to the script.Alias for\"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#43"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2#define FLAG_MODE_DEFINE_DEFAULTS#1"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flag-definitions.h"1#define FLAG_FULL(ftype, ctype, nam, def, cmt)#define FLAG_READONLY(ftype, ctype, nam, def, cmt)#define DEFINE_implication(whenflag, thenflag)#define DEFINE_bool(nam, def, cmt)#define DEFINE_int(nam, def, cmt)#define DEFINE_float(nam, def, cmt)#define DEFINE_string(nam, def, cmt)#define DEFINE_args(nam, def, cmt)#define FLAG DEFINE_bool(use_strict, false,"enforce strict mode") DEFINE_bool(es5_readonly, false,"activate correct semantics for inheriting readonliness") DEFINE_bool(es52_globals, false,"activate new semantics for global var declarations") DEFINE_bool(harmony_typeof, false,"enable harmony semantics for typeof") DEFINE_bool(harmony_scoping, false,"enable harmony block scoping") DEFINE_bool(harmony_modules, false,"enable harmony modules (implies block scoping)") DEFINE_bool(harmony_proxies, false,"enable harmony proxies") DEFINE_bool(harmony_collections, false,"enable harmony collections (sets, maps, and weak maps)") DEFINE_bool(harmony, false,"enable all harmony features (except typeof)") DEFINE_implication(harmony, harmony_scoping) DEFINE_implication(harmony, harmony_modules) DEFINE_implication(harmony, harmony_proxies) DEFINE_implication(harmony, harmony_collections) DEFINE_implication(harmony_modules, harmony_scoping) DEFINE_bool(packed_arrays, false,"optimizes arrays that have no holes") DEFINE_bool(smi_only_arrays, true,"tracks arrays with only smi values") DEFINE_bool(clever_optimizations, true,"Optimize object size, Array shift, DOM strings and string +") DEFINE_bool(unbox_double_arrays, true,"automatically unbox arrays of doubles") DEFINE_bool(string_slices, true,"use string slices") DEFINE_bool(crankshaft, true,"use crankshaft") DEFINE_string(hydrogen_filter,"","optimization filter") DEFINE_bool(use_range, true,"use hydrogen range analysis") DEFINE_bool(eliminate_dead_phis, true,"eliminate dead phis") DEFINE_bool(use_gvn, true,"use hydrogen global value numbering") DEFINE_bool(use_canonicalizing, true,"use hydrogen instruction canonicalizing") DEFINE_bool(use_inlining, true,"use function inlining") DEFINE_int(max_inlined_source_size, 600,"maximum source size in bytes considered for a single inlining") DEFINE_int(max_inlined_nodes, 196,"maximum number of AST nodes considered for a single inlining") DEFINE_int(max_inlined_nodes_cumulative, 196,"maximum cumulative number of AST nodes considered for inlining") DEFINE_bool(loop_invariant_code_motion, true,"loop invariant code motion") DEFINE_bool(collect_megamorphic_maps_from_stub_cache, true,"crankshaft harvests type feedback from stub cache") DEFINE_bool(hydrogen_stats, false,"print statistics for hydrogen") DEFINE_bool(trace_hydrogen, false,"trace generated hydrogen to file") DEFINE_string(trace_phase,"Z","trace generated IR for specified phases") DEFINE_bool(trace_inlining, false,"trace inlining decisions") DEFINE_bool(trace_alloc, false,"trace register allocator") DEFINE_bool(trace_all_uses, false,"trace all use positions") DEFINE_bool(trace_range, false,"trace range analysis") DEFINE_bool(trace_gvn, false,"trace global value numbering") DEFINE_bool(trace_representation, false,"trace representation types") DEFINE_bool(stress_pointer_maps, false,"pointer map for every instruction") DEFINE_bool(stress_environments, false,"environment for every instruction") DEFINE_int(deopt_every_n_times, 0,"deoptimize every n times a deopt point is passed") DEFINE_bool(trap_on_deopt, false,"put a break point before deoptimizing") DEFINE_bool(deoptimize_uncommon_cases, true,"deoptimize uncommon cases") DEFINE_bool(polymorphic_inlining, true,"polymorphic inlining") DEFINE_bool(use_osr, true,"use on-stack replacement") DEFINE_bool(array_bounds_checks_elimination, false,"perform array bounds checks elimination") DEFINE_bool(array_index_dehoisting, false,"perform array index dehoisting") DEFINE_bool(trace_osr, false,"trace on-stack replacement") DEFINE_int(stress_runs, 0,"number of stress runs") DEFINE_bool(optimize_closures, true,"optimize closures") DEFINE_bool(inline_construct, true,"inline constructor calls") DEFINE_bool(inline_arguments, true,"inline functions with arguments object") DEFINE_int(loop_weight, 1,"loop weight for representation inference") DEFINE_bool(optimize_for_in, true,"optimize functions containing for-in loops") DEFINE_bool(experimental_profiler, true,"enable all profiler experiments") DEFINE_bool(watch_ic_patching, false,"profiler considers IC stability") DEFINE_int(frame_count, 1,"number of stack frames inspected by the profiler") DEFINE_bool(self_optimization, false,"primitive functions trigger their own optimization") DEFINE_bool(direct_self_opt, false,"call recompile stub directly when self-optimizing") DEFINE_bool(retry_self_opt, false,"re-try self-optimization if it failed") DEFINE_bool(count_based_interrupts, false,"trigger profiler ticks based on counting instead of timing") DEFINE_bool(interrupt_at_exit, false,"insert an interrupt check at function exit") DEFINE_bool(weighted_back_edges, false,"weight back edges by jump distance for interrupt triggering") DEFINE_int(interrupt_budget, 5900,"execution budget before interrupt is triggered") DEFINE_int(type_info_threshold, 15,"percentage of ICs that must have type info to allow optimization") DEFINE_int(self_opt_count, 130,"call count before self-optimization") DEFINE_implication(experimental_profiler, watch_ic_patching) DEFINE_implication(experimental_profiler, self_optimization) DEFINE_implication(experimental_profiler, retry_self_opt) DEFINE_implication(experimental_profiler, count_based_interrupts) DEFINE_implication(experimental_profiler, interrupt_at_exit) DEFINE_implication(experimental_profiler, weighted_back_edges) DEFINE_bool(trace_opt_verbose, false,"extra verbose compilation tracing") DEFINE_implication(trace_opt_verbose, trace_opt) DEFINE_bool(debug_code, false,"generate extra code (assertions) for debugging") DEFINE_bool(code_comments, false,"emit comments in code disassembly") DEFINE_bool(enable_sse2, true,"enable use of SSE2 instructions if available") DEFINE_bool(enable_sse3, true,"enable use of SSE3 instructions if available") DEFINE_bool(enable_sse4_1, true,"enable use of SSE4.1 instructions if available") DEFINE_bool(enable_cmov, true,"enable use of CMOV instruction if available") DEFINE_bool(enable_rdtsc, true,"enable use of RDTSC instruction if available") DEFINE_bool(enable_sahf, true,"enable use of SAHF instruction if available (X64 only)") DEFINE_bool(enable_vfp3, true,"enable use of VFP3 instructions if available - this implies ""enabling ARMv7 instructions (ARM only)") DEFINE_bool(enable_armv7, true,"enable use of ARMv7 instructions if available (ARM only)") DEFINE_bool(enable_fpu, true,"enable use of MIPS FPU instructions if available (MIPS only)") DEFINE_string(expose_natives_as, NULL,"expose natives in global object") DEFINE_string(expose_debug_as, NULL,"expose debug in global object") DEFINE_bool(expose_gc, false,"expose gc extension") DEFINE_bool(expose_externalize_string, false,"expose externalize string extension") DEFINE_int(stack_trace_limit, 10,"number of stack frames to capture") DEFINE_bool(builtins_in_stack_traces, false,"show built-in functions in stack traces") DEFINE_bool(disable_native_files, false,"disable builtin natives files") DEFINE_bool(inline_new, true,"use fast inline allocation") DEFINE_bool(stack_trace_on_abort, true,"print a stack trace if an assertion failure occurs") DEFINE_bool(trace, false,"trace function calls") DEFINE_bool(mask_constants_with_cookie, true,"use random jit cookie to mask large constants") DEFINE_bool(lazy, true,"use lazy compilation") DEFINE_bool(trace_opt, false,"trace lazy optimization") DEFINE_bool(trace_opt_stats, false,"trace lazy optimization statistics") DEFINE_bool(opt, true,"use adaptive optimizations") DEFINE_bool(always_opt, false,"always try to optimize functions") DEFINE_bool(prepare_always_opt, false,"prepare for turning on always opt") DEFINE_bool(trace_deopt, false,"trace deoptimization") DEFINE_int(min_preparse_length, 1024,"minimum length for automatic enable preparsing") DEFINE_bool(always_full_compiler, false,"try to use the dedicated run-once backend for all code") DEFINE_bool(trace_bailout, false,"print reasons for falling back to using the classic V8 backend") DEFINE_bool(compilation_cache, true,"enable compilation cache") DEFINE_bool(cache_prototype_transitions, true,"cache prototype transitions") DEFINE_bool(trace_debug_json, false,"trace debugging JSON request/response") DEFINE_bool(debugger_auto_break, true,"automatically set the debug break flag when debugger commands are ""in the queue") DEFINE_bool(enable_liveedit, true,"enable liveedit experimental feature") DEFINE_bool(break_on_abort, true,"always cause a debug break before aborting") DEFINE_int(stack_size, kPointerSize *123,"default size of stack region v8 is allowed to use (in kBytes)") DEFINE_int(max_stack_trace_source_length, 300,"maximum length of function source code printed in a stack trace.") DEFINE_bool(always_inline_smi_code, false,"always inline smi code in non-opt code") DEFINE_int(max_new_space_size, 0,"max size of the new generation (in kBytes)") DEFINE_int(max_old_space_size, 0,"max size of the old generation (in Mbytes)") DEFINE_int(max_executable_size, 0,"max size of executable memory (in Mbytes)") DEFINE_bool(gc_global, false,"always perform global GCs") DEFINE_int(gc_interval,-1,"garbage collect after <n> allocations") DEFINE_bool(trace_gc, false,"print one trace line following each garbage collection") DEFINE_bool(trace_gc_nvp, false,"print one detailed trace line in name=value format ""after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false,"print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false,"print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false,"report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true,"garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true,"flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true,"use incremental marking") DEFINE_bool(incremental_marking_steps, true,"do incremental marking steps") DEFINE_bool(trace_incremental_marking, false,"trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true,"Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false,"Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true,"use inline caching") DEFINE_bool(native_code_counters, false,"generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false,"Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true,"Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false,"Never perform compaction on full GC - testing only") DEFINE_bool(compact_code_space, true,"Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true,"Flush inline caches prior to mark compact collection and ""flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0,"Default seed for initializing random generator ""(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true,"allows verbose printing") DEFINE_bool(allow_natives_syntax, false,"allow natives syntax") DEFINE_bool(trace_sim, false,"Trace simulator execution") DEFINE_bool(check_icache, false,"Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0,"Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8,"Stack alingment in bytes in simulator (4 or 8, 8 is default)") DEFINE_bool(trace_exception, false,"print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false,"preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true,"randomize hashes to avoid predictable hash collisions ""(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0,"Fixed seed to use to hash property keys (0 means random)""(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false,"activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true,"generate optimized regexp code") DEFINE_bool(testing_bool_flag, true,"testing_bool_flag") DEFINE_int(testing_int_flag, 13,"testing_int_flag") DEFINE_float(testing_float_flag, 2.5,"float-flag") DEFINE_string(testing_string_flag,"Hello, world!","string-flag") DEFINE_int(testing_prng_seed, 42,"Seed used for threading test randomness") DEFINE_string(testing_serialization_file,"/tmp/serdes","file in which to serialize heap") DEFINE_bool(help, false,"Print usage message, including flags, on console") DEFINE_bool(dump_counters, false,"Dump counters on exit") DEFINE_string(map_counters,"","Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT,"Pass all remaining arguments to the script. Alias for \"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#47"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2 namespace{struct Flag{enum FlagType{TYPE_BOOL, TYPE_INT, TYPE_FLOAT, TYPE_STRING, TYPE_ARGS} name
V8EXPORT bool IsBooleanObject() const
static Handle< T > cast(Handle< S > that)
Local< String > Get() const
static void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit=10, StackTrace::StackTraceOptions options=StackTrace::kOverview)
static Array * Cast(Value *obj)
void AllowCodeGenerationFromStrings(bool allow)
static V8EXPORT Local< String > New(const char *data, int length=-1)
Local< Function > Callee() const
void SetData(Handle< String > data)
v8::Handle< Value > AnalyzeStackInNativeCode(const v8::Arguments &args)
bool IsAsciiRepresentation()
UC16VectorResource(i::Vector< const i::uc16 > vector)
static ExternalTwoByteString * cast(Object *obj)
void checkStackFrame(const char *expected_script_name, const char *expected_func_name, int expected_line_number, int expected_column, bool is_eval, bool is_constructor, v8::Handle< v8::StackFrame > frame)
v8::Handle< Value > ProvokeOutOfMemory(const v8::Arguments &args)
static V8EXPORT Local< String > NewSymbol(const char *data, int length=-1)
Local< ObjectTemplate > InstanceTemplate()
Handle< Primitive > V8EXPORT Null()
v8::Handle< Script > getScript()
v8::Persistent< Context > calling_context0
~RegExpStringModificationTest()
V8EXPORT bool HasRealNamedCallbackProperty(Handle< String > key)
V8EXPORT Local< Value > GetHiddenValue(Handle< String > key)
static Handle< T > Cast(Handle< S > that)
static Local< Value > Error(Handle< String > message)
void SetIndexedPropertyHandler(IndexedPropertyGetter getter, IndexedPropertySetter setter=0, IndexedPropertyQuery query=0, IndexedPropertyDeleter deleter=0, IndexedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
Handle< Object > SetAccessor(Handle< JSObject > obj, Handle< AccessorInfo > info)
V8EXPORT Local< Array > GetPropertyNames()
V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType()
V8EXPORT Local< Value > Call(Handle< Object > recv, int argc, Handle< Value > argv[])
V8EXPORT bool IsRegExp() const
virtual void VisitExternalString(v8::Handle< v8::String > string)
#define ASSERT(condition)
v8::Handle< Value > WhammyPropertyGetter(Local< String > name, const AccessorInfo &info)
void CheckProperties(v8::Handle< v8::Value > val, int elmc, const char *elmv[])
void DisposingCallback(v8::Persistent< v8::Value > handle, void *)
v8::Handle< v8::Value > DirectGetterCallback(Local< String > name, const v8::AccessorInfo &info)
V8EXPORT void * GetIndexedPropertiesExternalArrayData()
v8::Handle< Script > call_recursively_script
Local< Value > Data() const
static V8EXPORT Local< Value > Wrap(void *data)
kPropertyAccessorsOffset kNamedPropertyHandlerOffset instance_template
Local< Value > GetInternalField(int index)
V8EXPORT Local< String > ToString() const
v8::Handle< Value > JSCheck(const v8::Arguments &args)
Handle< Value >(* IndexedPropertySetter)(uint32_t index, Local< Value > value, const AccessorInfo &info)
static intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes)
void SetVerbose(bool value)
virtual size_t length() const
virtual const char * data() const
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
v8::Handle< Value > CThrowCountDown(const v8::Arguments &args)
static ExternalAsciiString * cast(Object *obj)
void NewPersistentHandleCallback(v8::Persistent< v8::Value > handle, void *)
static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback)
static void * Unwrap(Handle< Value > obj)
V8EXPORT void SetIndexedPropertiesToExternalArrayData(void *data, ExternalArrayType array_type, int number_of_elements)
Handle< Value > EmptyInterceptorSetter(Local< String > name, Local< Value > value, const AccessorInfo &info)
V8EXPORT bool Equals(Handle< Value > that) const
V8EXPORT Handle< Value > GetScriptId() const
static void VisitExternalResources(ExternalResourceVisitor *visitor)
v8::Handle< Value > call_ic_function3
void CallCompletedCallbackException()
v8::Handle< v8::Value > ThrowingDirectApiCallback(const v8::Arguments &args)
Handle< Value > GetScriptResourceName() const
static void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter=kGCTypeAll)
static Smi * cast(Object *object)
Handle< String > FlattenGetString(Handle< String > string)
V8EXPORT bool IsExternal() const
V8EXPORT bool HasIndexedPropertiesInExternalArrayData()
v8::Persistent< Value > xValue
V8EXPORT void SetInternalField(int index, Handle< Value > value)
v8::Handle< Value > CheckThisNamedPropertySetter(Local< String > property, Local< Value > value, const AccessorInfo &info)
void SetClassName(Handle< String > name)
static V8EXPORT Local< Integer > NewFromUnsigned(uint32_t value)
Handle< Value >(* IndexedPropertyGetter)(uint32_t index, const AccessorInfo &info)
void CheckCodeGenerationAllowed()
static v8::Handle< v8::Value > Echo(const v8::Arguments &args)
Local< StackFrame > GetFrame(uint32_t index) const
static const char * GetVersion()
V8EXPORT Local< Value > GetRealNamedProperty(Handle< String > key)
V8EXPORT bool IsExternalAscii() const
V8EXPORT bool IsStringObject() const
V8EXPORT ScriptOrigin GetScriptOrigin() const
static Local< Script > New(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
TestResource(uint16_t *data, int *counter=NULL)
v8::Handle< Value > CCatcher(const v8::Arguments &args)
V8EXPORT int InternalFieldCount()
static bool AddMessageListener(MessageCallback that, Handle< Value > data=Handle< Value >())
Handle< Value >(* InvocationCallback)(const Arguments &args)
static ScriptData * PreCompile(const char *input, int length)
Handle< Value >(* NamedPropertyGetter)(Local< String > property, const AccessorInfo &info)
virtual const char * Data()=0
V8EXPORT void * Value() const
void CheckCodeGenerationDisallowed()
static void RemoveCallCompletedCallback(CallCompletedCallback callback)
v8::Handle< Value > CheckThisIndexedPropertySetter(uint32_t index, Local< Value > value, const AccessorInfo &info)
void set_max_old_space_size(int value)
Handle< Value > RecursiveCall(const Arguments &args)
static Local< ObjectTemplate > New()
virtual bool HasError()=0
V8EXPORT bool HasIndexedPropertiesInPixelData()
Handle< Value > HasOwnPropertyIndexedPropertyGetter(uint32_t index, const AccessorInfo &info)
void PrologueCallbackSecond(v8::GCType, v8::GCCallbackFlags)
Handle< Value > ReThrow()
V8EXPORT Local< Value > GetPrototype()
static void GetHeapStatistics(HeapStatistics *heap_statistics)
static bool IsValid(intptr_t value)
void set_resource(const Resource *buffer)
TEST(MakingExternalStringConditions)
V8EXPORT bool ForceDelete(Handle< Value > key)
v8::Handle< v8::Object > bottom
void CallCompletedCallback1()
TestAsciiResource(const char *data, int *counter=NULL)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
static const int kNoGCFlags
virtual ~AsciiVectorResource()
void SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
v8::Handle< v8::Value > DirectApiCallback(const v8::Arguments &args)
void SetInternalFieldCount(int value)
Handle< v8::Integer > HasOwnPropertyNamedPropertyQuery(Local< String > property, const AccessorInfo &info)
static void SetFatalErrorHandler(FatalErrorCallback that)
static int ContextDisposedNotification()
bool CodeGenerationDisallowed(Local< Context > context)
V8EXPORT int32_t Int32Value() const
v8::Handle< Value >(* NamedPropertyGetter)(Local< String > property, const AccessorInfo &info)
void(* AccessorSetter)(Local< String > property, Local< Value > value, const AccessorInfo &info)
V8EXPORT Local< Object > NewInstance() const
IsolateThread(v8::Isolate *isolate, int fib_limit)
bool IsConstructor() const
static FunctionTemplateInfo * cast(Object *obj)
V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t *data, int length)
V8EXPORT void TurnOnAccessCheck()
int prologue_call_count_second
V8EXPORT int GetScriptColumnNumber() const
static void RemoveMessageListeners(MessageCallback that)
static MUST_USE_RESULT Handle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attr, StrictModeFlag strict_mode, SetPropertyMode set_mode=SET_PROPERTY)
V8EXPORT bool Has(Handle< String > key)
const uint16_t * data() const
V8EXPORT bool SetHiddenValue(Handle< String > key, Handle< Value > value)
void set_stack_limit(uint32_t *value)
static Persistent< T > New(Handle< T > that)
static const int kMakeHeapIterableMask
void FailedAccessCheckCallbackGC(Local< v8::Object > target, v8::AccessType type, Local< v8::Value > data)
V8EXPORT bool BooleanValue() const
void set_resource(const Resource *buffer)
v8::Handle< v8::Array > CheckThisNamedPropertyEnumerator(const AccessorInfo &info)
Handle< Value > HasOwnPropertyNamedPropertyGetter(Local< String > property, const AccessorInfo &info)
void(* WeakReferenceCallback)(Persistent< Value > object, void *parameter)
int GetLineNumber() const
Handle< v8::Integer > HasOwnPropertyIndexedPropertyQuery(uint32_t index, const AccessorInfo &info)
static Local< Value > RangeError(Handle< String > message)
#define CHECK_NE(unexpected, value)
Handle< Boolean > V8EXPORT False()
static void Sleep(const int milliseconds)
static const int kAbortIncrementalMarkingMask
Vector< const char > CStrVector(const char *data)
int StrLength(const char *string)
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
void SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter=0, NamedPropertyQuery query=0, NamedPropertyDeleter deleter=0, NamedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
v8::Handle< Value > HandleF(const v8::Arguments &args)
static void Print(const char *format,...)
Local< Object > This() const
#define T(name, string, precedence)
static void AddCallCompletedCallback(CallCompletedCallback callback)
Local< String > GetScriptName() const
v8::Handle< v8::Value > ThrowingDirectGetterCallback(Local< String > name, const v8::AccessorInfo &info)
static Local< Object > Cast(Local< S > that)
V8EXPORT bool IsObject() const
v8::Handle< v8::Boolean > CheckThisIndexedPropertyDeleter(uint32_t index, const AccessorInfo &info)
bool IsCodeGenerationFromStringsAllowed()
static Local< Value > ReferenceError(Handle< String > message)
virtual ~UC16VectorResource()
static int SNPrintF(Vector< char > str, const char *format,...)
Local< Value > StackTrace() const
static V8EXPORT v8::Local< v8::String > Empty()
static Semaphore * CreateSemaphore(int count)
int ToNumber(Register reg)
V8EXPORT bool IsDate() const
void AddInterceptor(Handle< FunctionTemplate > templ, v8::NamedPropertyGetter getter, v8::NamedPropertySetter setter)
v8::Handle< v8::Value > Version(const v8::Arguments &args)
v8::Handle< Value > ThrowValue(const v8::Arguments &args)
static int NumberOfHandles()
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
V8EXPORT int GetIndexedPropertiesExternalArrayDataLength()
V8EXPORT uint32_t Uint32Value() const
static double nan_value()
static Local< AccessorSignature > New(Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >())
void AddAccessor(Handle< FunctionTemplate > templ, Handle< String > name, v8::AccessorGetter getter, v8::AccessorSetter setter)
VisitorImpl(TestResource *r1, TestResource *r2)
V8EXPORT bool IsNumber() const
void CallCompletedCallback2()
void EpilogueCallback(v8::GCType, v8::GCCallbackFlags)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< String > name)
V8EXPORT Local< String > StringValue() const
Local< Function > GetFunction()
void CheckVisitedResources()
static RegisterThreadedTest * nth(int i)
V8EXPORT bool ForceSet(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
void DisposeAndForceGcCallback(v8::Persistent< v8::Value > handle, void *)
V8EXPORT bool Delete(Handle< String > key)
int GetUtf8Length(Handle< String > str)
static Local< Value > SyntaxError(Handle< String > message)
V8EXPORT Local< Object > Clone()
v8::Persistent< v8::Object > bad_handle
void CheckOwnProperties(v8::Handle< v8::Value > val, int elmc, const char *elmv[])
virtual const i::uc16 * data() const
V8EXPORT bool SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None)
Handle< Value > InterceptorGetter(Local< String > name, const AccessorInfo &info)
AsciiVectorResource(i::Vector< const char > vector)
const char * data() const
V8EXPORT int GetIndexedPropertiesPixelDataLength()
Local< ObjectTemplate > PrototypeTemplate()
V8EXPORT bool IsFalse() const
v8::Handle< v8::Boolean > CheckThisNamedPropertyDeleter(Local< String > property, const AccessorInfo &info)
V8EXPORT Flags GetFlags() const
static Local< Value > TypeError(Handle< String > message)
static Local< Signature > New(Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >(), int argc=0, Handle< FunctionTemplate > argv[]=0)
static V8EXPORT Local< Integer > New(int32_t value)
V8EXPORT int GetScriptLineNumber() const
virtual size_t length() const
static void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
Handle< StackTrace > GetStackTrace() const
InitDefaultIsolateThread(TestCase testCase)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< v8::String > name)
static void StartPreemption(int every_n_ms)
void(* MessageCallback)(Handle< Message > message, Handle< Value > data)
static void SetCreateHistogramFunction(CreateHistogramCallback)
Local< T > Close(Handle< T > value)
V8EXPORT bool IsNumberObject() const
V8EXPORT int WriteAscii(char *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
static void RemoveGCPrologueCallback(GCPrologueCallback callback)
static bool ReportApiFailure(const char *location, const char *message)
Handle< Primitive > V8EXPORT Undefined()
static V8EXPORT Local< Number > New(double value)
v8::Handle< v8::Value > WithTryCatch(const v8::Arguments &args)
int echo_indexed_call_count
V8EXPORT double NumberValue() const
bool CodeGenerationAllowed(Local< Context > context)
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
CcTest::TestFunction * callback()
static Local< StackTrace > CurrentStackTrace(int frame_limit, StackTraceOptions options=kOverview)
static Local< TypeSwitch > New(Handle< FunctionTemplate > type)
int epilogue_call_count_second
char * StrDup(const char *str)
V8EXPORT uint32_t Length() const
static ScriptData * New(const char *data, int length)
static V8EXPORT Local< External > New(void *value)
Isolate * GetIsolate() const
V8EXPORT bool IsInt32() const
v8::Local< v8::Context > local()
Handle< Object > SetPrototype(Handle< JSFunction > function, Handle< Object > prototype)
V8EXPORT bool HasRealNamedProperty(Handle< String > key)
static Handle< Boolean > New(bool value)
Handle< v8::Array > UnboxedDoubleIndexedPropertyEnumerator(const AccessorInfo &info)
static void SetUp(PartOfTest part)
static V8EXPORT Local< String > NewExternal(ExternalStringResource *resource)
void DeleteArray(T *array)
bool V8EXPORT SetResourceConstraints(ResourceConstraints *constraints)
V8EXPORT Handle< Value > GetInferredName() const
void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type)
static ConsString * cast(Object *obj)
static void StopPreemption()
Handle< Value > V8EXPORT ThrowException(Handle< Value > exception)
static const int kMaxValue
bool IsConstructCall() const
static const int kHeaderSize
Handle< Value >(* AccessorGetter)(Local< String > property, const AccessorInfo &info)
v8::Handle< Function > args_fun
int match(Handle< Value > value)
Local< v8::Message > Message() const
V8EXPORT int Write(uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
Handle< Value > EmptyInterceptorGetter(Local< String > name, const AccessorInfo &info)
static bool IsLocked(Isolate *isolate=NULL)
void Inherit(Handle< FunctionTemplate > parent)
void EpilogueCallbackSecond(v8::GCType, v8::GCCallbackFlags)
v8::Handle< v8::Integer > CheckThisNamedPropertyQuery(Local< String > property, const AccessorInfo &info)
NativeFunctionExtension(const char *name, const char *source, v8::InvocationCallback fun=&Echo)
Local< String > GetFunctionName() const
Local< String > GetSourceLine() const
static V8EXPORT Local< Object > New()
Handle< v8::Integer > HasOwnPropertyNamedPropertyQuery2(Local< String > property, const AccessorInfo &info)
Handle< Value > SimpleAccessorGetter(Local< String > name, const AccessorInfo &info)
static void SetCounterFunction(CounterLookupCallback)
V8EXPORT Local< Uint32 > ToArrayIndex() const
static v8::internal::Handle< v8::internal::TemplateInfo > OpenHandle(const Template *that)
void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle< Value > data=Handle< Value >(), bool turned_on_by_default=true)
V8EXPORT bool Value() const
V8EXPORT bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static const int kObjectCount
const char * name() const
int GetFrameCount() const
v8::Persistent< v8::Object > objects_[kObjectCount]
static bool IdleNotification(int hint=1000)
V8EXPORT double NumberValue() const
v8::Handle< Value > call_ic_function2
static void IgnoreOutOfMemoryException()