49 static const bool kLogThreading =
false;
51 static bool IsNaN(
double x) {
59 using ::v8::AccessorInfo;
60 using ::v8::Arguments;
62 using ::v8::Extension;
64 using ::v8::FunctionTemplate;
66 using ::v8::HandleScope;
71 using ::v8::ObjectTemplate;
72 using ::v8::Persistent;
74 using ::v8::StackTrace;
82 static void ExpectString(
const char*
code,
const char* expected) {
83 Local<Value> result = CompileRun(code);
84 CHECK(result->IsString());
85 String::AsciiValue ascii(result);
89 static void ExpectInt32(
const char* code,
int expected) {
90 Local<Value> result = CompileRun(code);
91 CHECK(result->IsInt32());
92 CHECK_EQ(expected, result->Int32Value());
95 static void ExpectBoolean(
const char* code,
bool expected) {
96 Local<Value> result = CompileRun(code);
97 CHECK(result->IsBoolean());
98 CHECK_EQ(expected, result->BooleanValue());
102 static void ExpectTrue(
const char* code) {
103 ExpectBoolean(code,
true);
107 static void ExpectFalse(
const char* code) {
108 ExpectBoolean(code,
false);
112 static void ExpectObject(
const char* code, Local<Value> expected) {
113 Local<Value> result = CompileRun(code);
114 CHECK(result->Equals(expected));
118 static void ExpectUndefined(
const char* code) {
119 Local<Value> result = CompileRun(code);
120 CHECK(result->IsUndefined());
124 static int signature_callback_count;
128 signature_callback_count++;
130 for (
int i = 0; i < args.
Length(); i++)
139 for (
int i = 0; i < args.
Length(); i++) {
148 Local<Context> local_env;
151 local_env = env.
local();
155 CHECK(!local_env.IsEmpty());
162 const char* c_source =
"1 + 2 + 3";
163 Local<String> source = String::New(c_source);
164 Local<Script> script = Script::Compile(source);
165 CHECK_EQ(6, script->Run()->Int32Value());
182 signature_callback_count = 0;
186 CHECK_EQ(1, signature_callback_count);
191 "var o = new SubFun();"
193 CHECK_EQ(2, signature_callback_count);
198 "o.m = Fun.prototype.m;"
200 CHECK_EQ(2, signature_callback_count);
207 "var o = new UnrelFun();"
208 "o.m = Fun.prototype.m;"
210 CHECK_EQ(2, signature_callback_count);
231 CHECK(value2->IsTrue());
234 CHECK(value3->IsTrue());
237 cons1->SetClassName(v8_str(
"Cons1"));
249 env->
Global()->Set(v8_str(
"Cons1"), cons1->GetFunction());
254 "Fun2(new Cons1(), new Cons2(), new Cons3()) =="
255 "'[object Cons1],[object Cons2],[object Cons3]'");
259 "Fun2(new Cons1(), new Cons2(), 5) == '[object Cons1],[object Cons2],'");
260 CHECK(value5->IsTrue());
263 "Fun2(new Cons3(), new Cons2(), new Cons1()) == ',[object Cons2],'");
264 CHECK(value6->IsTrue());
267 "Fun2(new Cons1(), new Cons2(), new Cons3(), 'd') == "
268 "'[object Cons1],[object Cons2],[object Cons3],d';");
269 CHECK(value7->IsTrue());
272 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'");
273 CHECK(value8->IsTrue());
281 Local<String> undef_str = undef->
ToString();
282 char* value = i::NewArray<char>(undef_str->Length() + 1);
283 undef_str->WriteAscii(value);
284 CHECK_EQ(0, strcmp(value,
"undefined"));
293 Local<Value> foo_before = obj->Get(v8_str(
"foo"));
294 CHECK(foo_before->IsUndefined());
295 Local<String> bar_str = v8_str(
"bar");
296 obj->Set(v8_str(
"foo"), bar_str);
297 Local<Value> foo_after = obj->Get(v8_str(
"foo"));
298 CHECK(!foo_after->IsUndefined());
299 CHECK(foo_after->IsString());
308 Local<Value> before = obj->Get(1);
309 CHECK(before->IsUndefined());
310 Local<String> bar_str = v8_str(
"bar");
311 obj->Set(1, bar_str);
312 Local<Value> after = obj->Get(1);
313 CHECK(!after->IsUndefined());
314 CHECK(after->IsString());
317 Local<v8::Array> value = CompileRun(
"[\"a\", \"b\"]").As<
v8::Array>();
318 CHECK_EQ(v8_str(
"a"), value->Get(0));
319 CHECK_EQ(v8_str(
"b"), value->Get(1));
326 const char* c_source =
"1 + 2 + 3";
327 Local<String> source = String::New(c_source);
328 Local<Script> script = Script::Compile(source);
329 CHECK_EQ(6, script->Run()->Int32Value());
333 static uint16_t* AsciiToTwoByteString(
const char* source) {
335 uint16_t* converted = i::NewArray<uint16_t>(array_length);
336 for (
int i = 0; i < array_length; i++) converted[i] = source[i];
344 : data_(data), length_(0), counter_(counter) {
345 while (data[length_]) ++length_;
350 if (counter_ !=
NULL) ++*counter_;
370 : data_(data), length_(strlen(data)), counter_(counter) { }
374 if (counter_ !=
NULL) ++*counter_;
392 int dispose_count = 0;
393 const char* c_source =
"1 + 2 * 3";
394 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
399 Local<String> source = String::NewExternal(resource);
400 Local<Script> script = Script::Compile(source);
401 Local<Value> value = script->Run();
402 CHECK(value->IsNumber());
404 CHECK(source->IsExternal());
406 static_cast<TestResource*>(source->GetExternalStringResource()));
407 String::Encoding encoding = String::UNKNOWN_ENCODING;
408 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
409 source->GetExternalStringResourceBase(&encoding));
410 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
414 v8::internal::Isolate::Current()->compilation_cache()->Clear();
415 HEAP->CollectAllAvailableGarbage();
421 int dispose_count = 0;
422 const char* c_source =
"1 + 2 * 3";
428 Local<String> source = String::NewExternal(resource);
429 CHECK(source->IsExternalAscii());
430 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
431 source->GetExternalAsciiStringResource());
432 String::Encoding encoding = String::UNKNOWN_ENCODING;
433 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
434 source->GetExternalStringResourceBase(&encoding));
435 CHECK_EQ(String::ASCII_ENCODING, encoding);
436 Local<Script> script = Script::Compile(source);
437 Local<Value> value = script->Run();
438 CHECK(value->IsNumber());
443 i::Isolate::Current()->compilation_cache()->Clear();
444 HEAP->CollectAllAvailableGarbage();
450 int dispose_count = 0;
451 uint16_t* two_byte_source = AsciiToTwoByteString(
"1 + 2 * 3");
455 Local<String> source = String::New(two_byte_source);
459 CHECK_EQ(source->IsExternal(),
false);
460 CHECK_EQ(source->IsExternalAscii(),
false);
461 String::Encoding encoding = String::UNKNOWN_ENCODING;
462 CHECK_EQ(
NULL, source->GetExternalStringResourceBase(&encoding));
463 CHECK_EQ(String::ASCII_ENCODING, encoding);
464 bool success = source->MakeExternal(
new TestResource(two_byte_source,
467 Local<Script> script = Script::Compile(source);
468 Local<Value> value = script->Run();
469 CHECK(value->IsNumber());
474 i::Isolate::Current()->compilation_cache()->Clear();
481 int dispose_count = 0;
482 const char* c_source =
"1 + 2 * 3";
486 Local<String> source = v8_str(c_source);
490 bool success = source->MakeExternal(
493 Local<Script> script = Script::Compile(source);
494 Local<Value> value = script->Run();
495 CHECK(value->IsNumber());
500 i::Isolate::Current()->compilation_cache()->Clear();
506 TEST(MakingExternalStringConditions) {
514 uint16_t* two_byte_string = AsciiToTwoByteString(
"s1");
515 Local<String> small_string = String::New(two_byte_string);
519 CHECK(!small_string->CanMakeExternal());
524 CHECK(small_string->CanMakeExternal());
526 two_byte_string = AsciiToTwoByteString(
"small string 2");
527 small_string = String::New(two_byte_string);
531 CHECK(!small_string->CanMakeExternal());
532 for (
int i = 0; i < 100; i++) {
533 String::Value value(small_string);
536 CHECK(small_string->CanMakeExternal());
538 const int buf_size = 10 * 1024;
539 char* buf = i::NewArray<char>(buf_size);
540 memset(buf,
'a', buf_size);
541 buf[buf_size - 1] =
'\0';
543 two_byte_string = AsciiToTwoByteString(buf);
544 Local<String> large_string = String::New(two_byte_string);
548 CHECK(large_string->CanMakeExternal());
552 TEST(MakingExternalAsciiStringConditions) {
560 Local<String> small_string = String::New(
"s1");
562 CHECK(!small_string->CanMakeExternal());
567 CHECK(small_string->CanMakeExternal());
569 small_string = String::New(
"small string 2");
571 CHECK(!small_string->CanMakeExternal());
572 for (
int i = 0; i < 100; i++) {
573 String::Value value(small_string);
576 CHECK(small_string->CanMakeExternal());
578 const int buf_size = 10 * 1024;
579 char* buf = i::NewArray<char>(buf_size);
580 memset(buf,
'a', buf_size);
581 buf[buf_size - 1] =
'\0';
582 Local<String> large_string = String::New(buf);
585 CHECK(large_string->CanMakeExternal());
592 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
593 Local<String>
string =
600 CHECK(isymbol->IsSymbol());
610 const char* one_byte_string =
"test string";
611 Local<String>
string = String::NewExternal(
618 CHECK(isymbol->IsSymbol());
626 int dispose_count = 0;
627 bool in_new_space =
false;
630 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
631 Local<String>
string =
636 in_new_space =
HEAP->InNewSpace(*istring);
637 CHECK(in_new_space ||
HEAP->old_data_space()->Contains(*istring));
646 int dispose_count = 0;
647 bool in_new_space =
false;
650 const char* one_byte_string =
"test string";
651 Local<String>
string = String::NewExternal(
655 in_new_space =
HEAP->InNewSpace(*istring);
656 CHECK(in_new_space ||
HEAP->old_data_space()->Contains(*istring));
672 dispose_(dispose) { }
676 if (dispose_)
delete this;
687 TEST(ExternalStringWithDisposeHandling) {
688 const char* c_source =
"1 + 2 * 3";
691 TestAsciiResourceWithDisposeControl::dispose_count = 0;
692 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
697 Local<String> source = String::NewExternal(&res_stack);
698 Local<Script> script = Script::Compile(source);
699 Local<Value> value = script->Run();
700 CHECK(value->IsNumber());
702 HEAP->CollectAllAvailableGarbage();
703 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
705 i::Isolate::Current()->compilation_cache()->Clear();
706 HEAP->CollectAllAvailableGarbage();
707 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
708 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
711 TestAsciiResourceWithDisposeControl::dispose_count = 0;
712 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
718 Local<String> source = String::NewExternal(res_heap);
719 Local<Script> script = Script::Compile(source);
720 Local<Value> value = script->Run();
721 CHECK(value->IsNumber());
723 HEAP->CollectAllAvailableGarbage();
724 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
726 i::Isolate::Current()->compilation_cache()->Clear();
727 HEAP->CollectAllAvailableGarbage();
728 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
729 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
737 const char* one_byte_string_1 =
"function a_times_t";
738 const char* two_byte_string_1 =
"wo_plus_b(a, b) {return ";
739 const char* one_byte_extern_1 =
"a * 2 + b;} a_times_two_plus_b(4, 8) + ";
740 const char* two_byte_extern_1 =
"a_times_two_plus_b(4, 8) + ";
741 const char* one_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
742 const char* two_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
743 const char* two_byte_extern_2 =
"a_times_two_plus_b(1, 2);";
744 Local<String> left = v8_str(one_byte_string_1);
746 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
747 Local<String> right = String::New(two_byte_source);
750 Local<String> source = String::Concat(left, right);
751 right = String::NewExternal(
753 source = String::Concat(source, right);
754 right = String::NewExternal(
755 new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
756 source = String::Concat(source, right);
757 right = v8_str(one_byte_string_2);
758 source = String::Concat(source, right);
760 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
761 right = String::New(two_byte_source);
764 source = String::Concat(source, right);
765 right = String::NewExternal(
766 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
767 source = String::Concat(source, right);
768 Local<Script> script = Script::Compile(source);
769 Local<Value> value = script->Run();
770 CHECK(value->IsNumber());
773 i::Isolate::Current()->compilation_cache()->Clear();
783 global->
Set(v8_str(
"pi"), v8_num(3.1415926));
784 Local<Value> pi = global->
Get(v8_str(
"pi"));
785 CHECK_EQ(3.1415926, pi->NumberValue());
797 args.
This()->Set(v8_str(
"x"), v8_num(1));
798 args.
This()->Set(v8_str(
"y"), v8_num(2));
812 Local<v8::FunctionTemplate> fun_templ =
814 Local<Function> fun = fun_templ->GetFunction();
815 env->
Global()->Set(v8_str(
"obj"), fun);
816 Local<Script> script = v8_compile(
"obj()");
817 CHECK_EQ(102, script->Run()->Int32Value());
823 fun_templ->SetCallHandler(handle_call);
824 Local<Function> fun = fun_templ->GetFunction();
825 env->
Global()->Set(v8_str(
"obj"), fun);
826 Local<Script> script = v8_compile(
"obj()");
827 CHECK_EQ(102, script->Run()->Int32Value());
831 Local<v8::FunctionTemplate> fun_templ =
833 fun_templ->SetClassName(v8_str(
"funky"));
834 fun_templ->InstanceTemplate()->SetAccessor(v8_str(
"m"), Return239);
835 Local<Function> fun = fun_templ->GetFunction();
836 env->
Global()->Set(v8_str(
"obj"), fun);
837 Local<Script> script = v8_compile(
"var s = new obj(); s.x");
838 CHECK_EQ(1, script->Run()->Int32Value());
840 Local<Value> result = v8_compile(
"(new obj()).toString()")->Run();
841 CHECK_EQ(v8_str(
"[object funky]"), result);
843 result = v8_compile(
"(new obj()).m")->Run();
844 CHECK_EQ(239, result->Int32Value());
849 static void* expected_ptr;
857 static void TestExternalPointerWrapping() {
864 obj->
Set(v8_str(
"func"),
866 env->
Global()->Set(v8_str(
"obj"), obj);
870 " for (var i = 0; i < 13; i++) obj.func();\n"
872 "foo(), true")->BooleanValue());
880 TestExternalPointerWrapping();
886 TestExternalPointerWrapping();
890 char* s =
new char[n];
891 for (
int i = 0; i < n; i++) {
892 expected_ptr = s + i;
893 TestExternalPointerWrapping();
899 expected_ptr =
reinterpret_cast<void*
>(1);
900 TestExternalPointerWrapping();
902 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef);
903 TestExternalPointerWrapping();
905 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef + 1);
906 TestExternalPointerWrapping();
908 #if defined(V8_HOST_ARCH_X64)
910 expected_ptr =
reinterpret_cast<void*
>(0x400000000);
911 TestExternalPointerWrapping();
913 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef);
914 TestExternalPointerWrapping();
916 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef + 1);
917 TestExternalPointerWrapping();
929 derived->Inherit(base);
931 Local<v8::Function> base_function = base->GetFunction();
932 Local<v8::Function> derived_function = derived->GetFunction();
933 Local<v8::Function> other_function = other->GetFunction();
935 Local<v8::Object> base_instance = base_function->NewInstance();
936 Local<v8::Object> derived_instance = derived_function->NewInstance();
937 Local<v8::Object> derived_instance2 = derived_function->NewInstance();
938 Local<v8::Object> other_instance = other_function->NewInstance();
939 derived_instance2->Set(v8_str(
"__proto__"), derived_instance);
940 other_instance->Set(v8_str(
"__proto__"), derived_instance2);
944 base_instance->FindInstanceInPrototypeChain(base));
945 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty());
946 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty());
950 derived_instance->FindInstanceInPrototypeChain(base));
952 derived_instance->FindInstanceInPrototypeChain(derived));
953 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty());
961 other_instance->FindInstanceInPrototypeChain(base));
963 other_instance->FindInstanceInPrototypeChain(derived));
965 other_instance->FindInstanceInPrototypeChain(other));
976 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
979 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
995 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
998 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1018 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1021 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1031 uint32_t value = 239;
1034 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1037 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1051 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1054 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1068 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1071 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1080 uint32_t INT32_MAX_AS_UINT = (1
U << 31) - 1;
1081 uint32_t value = INT32_MAX_AS_UINT + 1;
1082 CHECK(value > INT32_MAX_AS_UINT);
1085 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1088 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1096 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1099 CHECK(!not_error->IsNativeError());
1101 CHECK(!not_object->IsNativeError());
1111 CHECK(!unboxed_string->IsStringObject());
1113 CHECK(!boxed_not_string->IsStringObject());
1115 CHECK(!not_object->IsStringObject());
1117 CHECK(!as_boxed.IsEmpty());
1118 Local<v8::String> the_string = as_boxed->StringValue();
1119 CHECK(!the_string.IsEmpty());
1120 ExpectObject(
"\"test\"", the_string);
1125 CHECK(!the_string.IsEmpty());
1126 ExpectObject(
"\"test\"", the_string);
1136 CHECK(!unboxed_number->IsNumberObject());
1138 CHECK(!boxed_not_number->IsNumberObject());
1140 CHECK(!as_boxed.IsEmpty());
1141 double the_number = as_boxed->NumberValue();
1157 CHECK(!unboxed_boolean->IsBooleanObject());
1159 CHECK(!boxed_not_boolean->IsBooleanObject());
1162 CHECK(!as_boxed.IsEmpty());
1163 bool the_boolean = as_boxed->BooleanValue();
1170 CHECK_EQ(
true, as_boxed->BooleanValue());
1172 CHECK_EQ(
false, as_boxed->BooleanValue());
1179 double PI = 3.1415926;
1181 CHECK_EQ(PI, pi_obj->NumberValue());
1188 Local<String> str = v8_str(
"3.1415926");
1189 CHECK_EQ(3.1415926, str->NumberValue());
1200 double PI = 3.1415926;
1202 CHECK_EQ(3.0, date->NumberValue());
1216 CHECK(!u->BooleanValue());
1218 CHECK(!n->BooleanValue());
1220 CHECK(!str1->BooleanValue());
1222 CHECK(str2->BooleanValue());
1227 CHECK(!v8_compile(
"NaN")->Run()->BooleanValue());
1233 return v8_num(13.4);
1250 templ->
Set(
"x", v8_num(200));
1256 CHECK_EQ(200, v8_compile(
"x")->Run()->Int32Value());
1257 CHECK_EQ(876, v8_compile(
"m")->Run()->Int32Value());
1263 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1264 templ1->Set(
"x", v8_num(10));
1265 templ1->Set(
"y", v8_num(13));
1267 Local<v8::Object> instance1 = templ1->NewInstance();
1268 env->
Global()->Set(v8_str(
"p"), instance1);
1269 CHECK(v8_compile(
"(p.x == 10)")->Run()->BooleanValue());
1270 CHECK(v8_compile(
"(p.y == 13)")->Run()->BooleanValue());
1272 fun->PrototypeTemplate()->Set(
"nirk", v8_num(123));
1273 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
1274 templ2->Set(
"a", v8_num(12));
1275 templ2->Set(
"b", templ1);
1276 Local<v8::Object> instance2 = templ2->NewInstance();
1277 env->
Global()->Set(v8_str(
"q"), instance2);
1278 CHECK(v8_compile(
"(q.nirk == 123)")->Run()->BooleanValue());
1279 CHECK(v8_compile(
"(q.a == 12)")->Run()->BooleanValue());
1280 CHECK(v8_compile(
"(q.b.x == 10)")->Run()->BooleanValue());
1281 CHECK(v8_compile(
"(q.b.y == 13)")->Run()->BooleanValue());
1287 return v8_num(17.2);
1291 static v8::Handle<Value> GetKnurd(Local<String> property,
const AccessorInfo&) {
1293 return v8_num(15.2);
1321 CHECK(CompileRun(
"base1.prototype.__proto__ == s.prototype")->BooleanValue());
1322 CHECK(CompileRun(
"base2.prototype.__proto__ == s.prototype")->BooleanValue());
1324 CHECK(v8_compile(
"s.prototype.PI == 3.14")->Run()->BooleanValue());
1327 CHECK(CompileRun(
"s.knurd == undefined")->BooleanValue());
1328 CHECK(CompileRun(
"s.prototype.knurd == undefined")->BooleanValue());
1329 CHECK(CompileRun(
"base1.prototype.knurd == undefined")->BooleanValue());
1331 env->
Global()->Set(v8_str(
"obj"),
1333 CHECK_EQ(17.2, v8_compile(
"obj.flabby()")->Run()->NumberValue());
1334 CHECK(v8_compile(
"'flabby' in obj")->Run()->BooleanValue());
1335 CHECK_EQ(15.2, v8_compile(
"obj.knurd")->Run()->NumberValue());
1336 CHECK(v8_compile(
"'knurd' in obj")->Run()->BooleanValue());
1337 CHECK_EQ(20.1, v8_compile(
"obj.v1")->Run()->NumberValue());
1339 env->
Global()->Set(v8_str(
"obj2"),
1341 CHECK_EQ(17.2, v8_compile(
"obj2.flabby()")->Run()->NumberValue());
1342 CHECK(v8_compile(
"'flabby' in obj2")->Run()->BooleanValue());
1343 CHECK_EQ(15.2, v8_compile(
"obj2.knurd")->Run()->NumberValue());
1344 CHECK(v8_compile(
"'knurd' in obj2")->Run()->BooleanValue());
1345 CHECK_EQ(10.1, v8_compile(
"obj2.v2")->Run()->NumberValue());
1348 CHECK(v8_compile(
"obj.v2")->Run()->IsUndefined());
1349 CHECK(v8_compile(
"obj2.v1")->Run()->IsUndefined());
1357 const AccessorInfo& info) {
1359 CHECK_EQ(v8_str(
"data"), info.Data());
1360 echo_named_call_count++;
1367 const AccessorInfo& info) {
1368 Handle<Object>
self = info.This();
1369 return self->Get(String::Concat(v8_str(
"accessor_"), name));
1373 const AccessorInfo& info) {
1374 Handle<Object>
self = info.This();
1375 self->Set(String::Concat(v8_str(
"accessor_"), name), value);
1379 const AccessorInfo& info) {
1380 return Handle<Value>();
1385 const AccessorInfo& info) {
1386 return Handle<Value>();
1390 const AccessorInfo& info) {
1392 String::AsciiValue ascii(name);
1393 char* name_str = *ascii;
1394 char prefix[] =
"interceptor_";
1396 for (i = 0; name_str[i] && prefix[i]; ++i) {
1397 if (name_str[i] != prefix[i])
return Handle<Value>();
1399 Handle<Object>
self = info.This();
1400 return self->GetHiddenValue(v8_str(name_str + i));
1405 const AccessorInfo& info) {
1407 if (value->IsInt32() && value->Int32Value() < 10000) {
1408 Handle<Object>
self = info.This();
1409 self->SetHiddenValue(name, value);
1412 return Handle<Value>();
1416 Handle<String> name,
1419 templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
1425 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1430 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1431 Handle<FunctionTemplate> child = FunctionTemplate::New();
1432 child->Inherit(parent);
1437 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1438 CompileRun(
"var child = new Child;"
1440 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
1441 ExpectInt32(
"child.age", 10);
1442 ExpectInt32(
"child.accessor_age", 10);
1447 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1448 Handle<FunctionTemplate> child = FunctionTemplate::New();
1449 child->Inherit(parent);
1452 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1453 CompileRun(
"var child = new Child;"
1454 "var parent = child.__proto__;"
1455 "Object.defineProperty(parent, 'age', "
1456 " {get: function(){ return this.accessor_age; }, "
1457 " set: function(v){ this.accessor_age = v; }, "
1458 " enumerable: true, configurable: true});"
1460 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
1461 ExpectInt32(
"child.age", 10);
1462 ExpectInt32(
"child.accessor_age", 10);
1467 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1468 Handle<FunctionTemplate> child = FunctionTemplate::New();
1469 child->Inherit(parent);
1472 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1473 CompileRun(
"var child = new Child;"
1474 "var parent = child.__proto__;"
1475 "parent.name = 'Alice';");
1476 ExpectBoolean(
"child.hasOwnProperty('name')",
false);
1477 ExpectString(
"child.name",
"Alice");
1478 CompileRun(
"child.name = 'Bob';");
1479 ExpectString(
"child.name",
"Bob");
1480 ExpectBoolean(
"child.hasOwnProperty('name')",
true);
1481 ExpectString(
"parent.name",
"Alice");
1486 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1491 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1492 CompileRun(
"var obj = new Obj;"
1493 "function setAge(i){ obj.age = i; };"
1494 "for(var i = 0; i <= 10000; i++) setAge(i);");
1496 ExpectInt32(
"obj.interceptor_age", 9999);
1498 ExpectInt32(
"obj.accessor_age", 10000);
1503 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1508 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1509 CompileRun(
"var obj = new Obj;"
1510 "function setAge(i){ obj.age = i; };"
1511 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1513 ExpectInt32(
"obj.accessor_age", 10000);
1515 ExpectInt32(
"obj.interceptor_age", 9999);
1520 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1521 Handle<FunctionTemplate> child = FunctionTemplate::New();
1522 child->Inherit(parent);
1527 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1528 CompileRun(
"var child = new Child;"
1529 "function setAge(i){ child.age = i; };"
1530 "for(var i = 0; i <= 10000; i++) setAge(i);");
1532 ExpectInt32(
"child.interceptor_age", 9999);
1534 ExpectInt32(
"child.accessor_age", 10000);
1539 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1540 Handle<FunctionTemplate> child = FunctionTemplate::New();
1541 child->Inherit(parent);
1546 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1547 CompileRun(
"var child = new Child;"
1548 "function setAge(i){ child.age = i; };"
1549 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1551 ExpectInt32(
"child.accessor_age", 10000);
1553 ExpectInt32(
"child.interceptor_age", 9999);
1558 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1561 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1562 CompileRun(
"var obj = new Obj;"
1563 "function setter(i) { this.accessor_age = i; };"
1564 "function getter() { return this.accessor_age; };"
1565 "function setAge(i) { obj.age = i; };"
1566 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1567 "for(var i = 0; i <= 10000; i++) setAge(i);");
1569 ExpectInt32(
"obj.interceptor_age", 9999);
1571 ExpectInt32(
"obj.accessor_age", 10000);
1575 ExpectInt32(
"obj.age", 10000);
1576 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
1577 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
1582 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1585 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
1586 CompileRun(
"var obj = new Obj;"
1587 "function setter(i) { this.accessor_age = i; };"
1588 "function getter() { return this.accessor_age; };"
1589 "function setAge(i) { obj.age = i; };"
1590 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1591 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1593 ExpectInt32(
"obj.accessor_age", 10000);
1595 ExpectInt32(
"obj.interceptor_age", 9999);
1599 ExpectInt32(
"obj.age", 10000);
1600 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
1601 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
1606 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1607 Handle<FunctionTemplate> child = FunctionTemplate::New();
1608 child->Inherit(parent);
1611 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1612 CompileRun(
"var child = new Child;"
1613 "function setAge(i){ child.age = i; };"
1614 "for(var i = 0; i <= 10000; i++) setAge(i);");
1616 ExpectInt32(
"child.interceptor_age", 9999);
1618 ExpectInt32(
"child.age", 10000);
1623 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1624 Handle<FunctionTemplate> child = FunctionTemplate::New();
1625 child->Inherit(parent);
1628 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1629 CompileRun(
"var child = new Child;"
1630 "function setAge(i){ child.age = i; };"
1631 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1633 ExpectInt32(
"child.age", 10000);
1635 ExpectInt32(
"child.interceptor_age", 9999);
1639 echo_named_call_count = 0;
1646 env->
Global()->Set(v8_str(
"obj"),
1648 CHECK_EQ(echo_named_call_count, 0);
1649 v8_compile(
"obj.x")->Run();
1650 CHECK_EQ(echo_named_call_count, 1);
1651 const char* code =
"var str = 'oddle'; obj[str] + obj.poddle;";
1653 String::AsciiValue value(str);
1656 CHECK_EQ(v8_compile(
"obj.flob = 10;")->Run()->Int32Value(), 10);
1657 CHECK(v8_compile(
"'myProperty' in obj")->Run()->BooleanValue());
1658 CHECK(v8_compile(
"delete obj.myProperty")->Run()->BooleanValue());
1666 const AccessorInfo& info) {
1668 CHECK_EQ(v8_num(637), info.Data());
1669 echo_indexed_call_count++;
1670 return v8_num(index);
1681 env->
Global()->Set(v8_str(
"obj"),
1683 Local<Script> script = v8_compile(
"obj[900]");
1684 CHECK_EQ(script->Run()->Int32Value(), 900);
1692 const AccessorInfo& info) {
1694 CHECK(info.This()->Equals(bottom));
1700 const AccessorInfo& info) {
1702 CHECK(info.This()->Equals(bottom));
1709 const AccessorInfo& info) {
1711 CHECK(info.This()->Equals(bottom));
1718 const AccessorInfo& info) {
1720 CHECK(info.This()->Equals(bottom));
1726 const AccessorInfo& info) {
1728 CHECK(info.This()->Equals(bottom));
1734 const AccessorInfo& info) {
1736 CHECK(info.This()->Equals(bottom));
1743 const AccessorInfo& info) {
1745 CHECK(info.This()->Equals(bottom));
1751 Local<String> property,
1752 const AccessorInfo& info) {
1754 CHECK(info.This()->Equals(bottom));
1760 const AccessorInfo& info) {
1762 CHECK(info.This()->Equals(bottom));
1768 const AccessorInfo& info) {
1770 CHECK(info.This()->Equals(bottom));
1782 CheckThisIndexedPropertyHandler,
1789 CheckThisNamedPropertyHandler,
1796 Local<v8::Object> top = templ->
GetFunction()->NewInstance();
1797 Local<v8::Object> middle = templ->
GetFunction()->NewInstance();
1799 bottom->
Set(v8_str(
"__proto__"), middle);
1800 middle->Set(v8_str(
"__proto__"), top);
1801 env->
Global()->Set(v8_str(
"obj"), bottom);
1804 Script::Compile(v8_str(
"obj[0]"))->Run();
1805 Script::Compile(v8_str(
"obj.x"))->Run();
1808 Script::Compile(v8_str(
"obj[1] = 42"))->Run();
1809 Script::Compile(v8_str(
"obj.y = 42"))->Run();
1812 Script::Compile(v8_str(
"0 in obj"))->Run();
1813 Script::Compile(v8_str(
"'x' in obj"))->Run();
1816 Script::Compile(v8_str(
"delete obj[0]"))->Run();
1817 Script::Compile(v8_str(
"delete obj.x"))->Run();
1820 Script::Compile(v8_str(
"for (var p in obj) ;"))->Run();
1825 const AccessorInfo& info) {
1827 if (v8_str(
"pre")->Equals(key)) {
1828 return v8_str(
"PrePropertyHandler: pre");
1835 const AccessorInfo&) {
1836 if (v8_str(
"pre")->Equals(key)) {
1849 PrePropertyHandlerQuery);
1851 Script::Compile(v8_str(
1852 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run();
1854 CHECK_EQ(v8_str(
"PrePropertyHandler: pre"), result_pre);
1856 CHECK_EQ(v8_str(
"Object: on"), result_on);
1866 "this.propertyIsEnumerable(undefined)"))->Run();
1872 static const int kTargetRecursionDepth = 200;
1877 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
1880 return call_recursively_script->
Run();
1887 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
1888 if (depth == kTargetRecursionDepth) {
1889 printf(
"[depth = %d]\n", depth);
1894 args.
This()->Get(v8_str(
"callFunctionRecursively"));
1895 return function.
As<Function>()->Call(args.
This(), 0,
NULL);
1902 global->
Set(v8_str(
"callScriptRecursively"),
1904 global->
Set(v8_str(
"callFunctionRecursively"),
1909 call_recursively_script = v8_compile(
"callScriptRecursively()");
1910 call_recursively_script->
Run();
1914 Script::Compile(v8_str(
"callFunctionRecursively()"))->Run();
1919 ThrowingPropertyHandlerGet(Local<String> key,
const AccessorInfo&) {
1927 const AccessorInfo&) {
1937 ThrowingPropertyHandlerSet);
1941 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
1944 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
1952 Foo->PrototypeTemplate()->Set(v8_str(
"plak"), v8_num(321));
1954 env->
Global()->Set(v8_str(
"Foo"), Foo->GetFunction());
1955 Local<Script> script = Script::Compile(v8_str(
"Foo.prototype.plak"));
1956 CHECK_EQ(script->Run()->Int32Value(), 321);
1965 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1966 instance_templ->SetInternalFieldCount(1);
1967 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1968 CHECK_EQ(1, obj->InternalFieldCount());
1969 CHECK(obj->GetInternalField(0)->IsUndefined());
1970 obj->SetInternalField(0, v8_num(17));
1971 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
1978 global_template->SetInternalFieldCount(1);
1994 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
1995 instance_templ->SetInternalFieldCount(1);
1996 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
1997 CHECK_EQ(1, obj->InternalFieldCount());
1998 CHECK(obj->GetPointerFromInternalField(0) ==
NULL);
2000 char* data =
new char[100];
2002 void* aligned = data;
2003 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(aligned) & 0x1));
2004 void* unaligned = data + 1;
2005 CHECK_EQ(1, static_cast<int>(reinterpret_cast<uintptr_t>(unaligned) & 0x1));
2008 obj->SetPointerInInternalField(0, aligned);
2010 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0));
2013 obj->SetPointerInInternalField(0, unaligned);
2015 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0));
2026 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2027 instance_templ->SetInternalFieldCount(1);
2028 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2029 CHECK_EQ(1, obj->InternalFieldCount());
2030 CHECK(obj->GetPointerFromInternalField(0) ==
NULL);
2032 char* data =
new char[100];
2034 void* aligned = data;
2035 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(aligned) & 0x1));
2036 void* unaligned = data + 1;
2037 CHECK_EQ(1, static_cast<int>(reinterpret_cast<uintptr_t>(unaligned) & 0x1));
2039 obj->SetPointerInInternalField(0, aligned);
2043 obj->SetPointerInInternalField(0, unaligned);
2049 CHECK_EQ(aligned, obj->GetPointerFromInternalField(0));
2053 CHECK_EQ(unaligned, obj->GetPointerFromInternalField(0));
2067 int hash = obj->GetIdentityHash();
2068 int hash1 = obj->GetIdentityHash();
2081 int hash4 = obj->GetIdentityHash();
2087 CompileRun(
"Object.prototype['v8::IdentityHash'] = 42;\n");
2090 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2094 "function cnst() { return 42; };\n"
2095 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2098 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2127 CHECK(obj->
Get(empty)->IsUndefined());
2139 CHECK_EQ(2008, obj->
Get(prop_name)->Int32Value());
2166 "set_called = false;"
2167 "Object.defineProperty("
2168 " Object.prototype,"
2170 " {get: function() { return 45; },"
2171 " set: function() { set_called = true; }})");
2178 ExpectFalse(
"set_called");
2183 static bool interceptor_for_hidden_properties_called;
2185 Local<String> name,
const AccessorInfo& info) {
2186 interceptor_for_hidden_properties_called =
true;
2195 interceptor_for_hidden_properties_called =
false;
2201 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
2202 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
2203 Local<v8::Function>
function = fun_templ->GetFunction();
2204 Local<v8::Object> obj =
function->NewInstance();
2206 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
2207 CHECK(!interceptor_for_hidden_properties_called);
2216 env->
Global()->Set(v8_str(
"ext"), ext);
2217 Local<Value> reext_obj = Script::Compile(v8_str(
"this.ext"))->Run();
2219 int* ptr =
static_cast<int*
>(reext->
Value());
2247 Local<String> str = v8_str(
"str");
2263 int number_of_weak_calls_;
2267 static void WeakPointerCallback(Persistent<Value> handle,
void*
id) {
2279 Persistent<Object> g1s1;
2280 Persistent<Object> g1s2;
2281 Persistent<Object> g1c1;
2282 Persistent<Object> g2s1;
2283 Persistent<Object> g2s2;
2284 Persistent<Object> g2c1;
2290 g1s1 = Persistent<Object>::New(Object::New());
2291 g1s2 = Persistent<Object>::New(Object::New());
2292 g1c1 = Persistent<Object>::New(Object::New());
2293 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2294 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2295 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2297 g2s1 = Persistent<Object>::New(Object::New());
2298 g2s2 = Persistent<Object>::New(Object::New());
2299 g2c1 = Persistent<Object>::New(Object::New());
2300 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2301 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2302 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2305 Persistent<Object> root = Persistent<Object>::New(g1s1);
2308 CHECK(g1s2->Set(0, g2s2));
2309 CHECK(g2s1->Set(0, g1s1));
2312 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2313 Persistent<Value> g1_children[] = { g1c1 };
2314 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2315 Persistent<Value> g2_children[] = { g2c1 };
2316 V8::AddObjectGroup(g1_objects, 2);
2317 V8::AddImplicitReferences(g1s1, g1_children, 1);
2318 V8::AddObjectGroup(g2_objects, 2);
2319 V8::AddImplicitReferences(g2s2, g2_children, 1);
2328 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2336 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2337 Persistent<Value> g1_children[] = { g1c1 };
2338 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2339 Persistent<Value> g2_children[] = { g2c1 };
2340 V8::AddObjectGroup(g1_objects, 2);
2341 V8::AddImplicitReferences(g1s1, g1_children, 1);
2342 V8::AddObjectGroup(g2_objects, 2);
2343 V8::AddImplicitReferences(g2s2, g2_children, 1);
2352 g1c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2353 g2c1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2366 Persistent<Object> g1s1;
2367 Persistent<Object> g1s2;
2368 Persistent<Object> g2s1;
2369 Persistent<Object> g2s2;
2370 Persistent<Object> g3s1;
2371 Persistent<Object> g3s2;
2375 g1s1 = Persistent<Object>::New(Object::New());
2376 g1s2 = Persistent<Object>::New(Object::New());
2377 g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2378 g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2380 g2s1 = Persistent<Object>::New(Object::New());
2381 g2s2 = Persistent<Object>::New(Object::New());
2382 g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2383 g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2385 g3s1 = Persistent<Object>::New(Object::New());
2386 g3s2 = Persistent<Object>::New(Object::New());
2387 g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2388 g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2391 Persistent<Object> root = Persistent<Object>::New(g1s1);
2397 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2398 Persistent<Value> g1_children[] = { g2s1 };
2399 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2400 Persistent<Value> g2_children[] = { g3s1 };
2401 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2402 Persistent<Value> g3_children[] = { g1s1 };
2403 V8::AddObjectGroup(g1_objects, 2);
2404 V8::AddImplicitReferences(g1s1, g1_children, 1);
2405 V8::AddObjectGroup(g2_objects, 2);
2406 V8::AddImplicitReferences(g2s1, g2_children, 1);
2407 V8::AddObjectGroup(g3_objects, 2);
2408 V8::AddImplicitReferences(g3s1, g3_children, 1);
2417 root.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2421 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2422 Persistent<Value> g1_children[] = { g2s1 };
2423 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2424 Persistent<Value> g2_children[] = { g3s1 };
2425 Persistent<Value> g3_objects[] = { g3s1, g3s2 };
2426 Persistent<Value> g3_children[] = { g1s1 };
2427 V8::AddObjectGroup(g1_objects, 2);
2428 V8::AddImplicitReferences(g1s1, g1_children, 1);
2429 V8::AddObjectGroup(g2_objects, 2);
2430 V8::AddImplicitReferences(g2s1, g2_children, 1);
2431 V8::AddObjectGroup(g3_objects, 2);
2432 V8::AddImplicitReferences(g3s1, g3_children, 1);
2445 Local<Script> script = Script::Compile(v8_str(
"throw 'panama!';"));
2447 Local<Value> result = script->Run();
2448 CHECK(result.IsEmpty());
2450 String::AsciiValue exception_value(try_catch.
Exception());
2451 CHECK_EQ(*exception_value,
"panama!");
2462 message_received =
true;
2467 message_received =
false;
2469 CHECK(!message_received);
2476 script->
SetData(v8_str(
"7.56"));
2478 CHECK(message_received);
2488 message_received =
true;
2493 message_received =
false;
2495 CHECK(!message_received);
2498 CompileRun(
"throw 1337;");
2499 CHECK(message_received);
2511 CHECK(v8_str(
"hidden value")->Equals(hidden_property));
2512 message_received =
true;
2517 message_received =
false;
2519 CHECK(!message_received);
2524 v8_str(
"hidden value"));
2525 context->
Global()->Set(v8_str(
"error"), error);
2526 CompileRun(
"throw error;");
2527 CHECK(message_received);
2536 context->
Global()->Set(v8_str(
"foo"), v8_num(14));
2537 context->
Global()->Set(v8_str(
"12"), v8_num(92));
2539 context->
Global()->Set(v8_num(13), v8_num(56));
2540 Local<Value>
foo = Script::Compile(v8_str(
"this.foo"))->Run();
2542 Local<Value> twelve = Script::Compile(v8_str(
"this[12]"))->Run();
2543 CHECK_EQ(92, twelve->Int32Value());
2544 Local<Value> sixteen = Script::Compile(v8_str(
"this[16]"))->Run();
2545 CHECK_EQ(32, sixteen->Int32Value());
2546 Local<Value> thirteen = Script::Compile(v8_str(
"this[13]"))->Run();
2547 CHECK_EQ(56, thirteen->Int32Value());
2549 CHECK_EQ(92, context->
Global()->Get(v8_str(
"12"))->Int32Value());
2552 CHECK_EQ(32, context->
Global()->Get(v8_str(
"16"))->Int32Value());
2555 CHECK_EQ(56, context->
Global()->Get(v8_str(
"13"))->Int32Value());
2564 Local<String> prop = v8_str(
"none");
2565 context->
Global()->Set(prop, v8_num(7));
2568 prop = v8_str(
"read_only");
2572 Script::Compile(v8_str(
"read_only = 9"))->Run();
2574 context->
Global()->Set(prop, v8_num(10));
2577 prop = v8_str(
"dont_delete");
2580 Script::Compile(v8_str(
"delete dont_delete"))->Run();
2584 prop = v8_str(
"dont_enum");
2588 prop = v8_str(
"absent");
2590 Local<Value> fake_prop = v8_num(1);
2594 Local<Value> exception =
2595 CompileRun(
"({ toString: function() { throw 'exception';} })");
2597 CHECK(try_catch.HasCaught());
2598 String::AsciiValue exception_value(try_catch.Exception());
2599 CHECK_EQ(
"exception", *exception_value);
2609 CHECK(array->Get(0)->IsUndefined());
2610 CHECK(!array->Has(0));
2611 CHECK(array->Get(100)->IsUndefined());
2612 CHECK(!array->Has(100));
2613 array->Set(2, v8_num(7));
2615 CHECK(!array->Has(0));
2616 CHECK(!array->Has(1));
2617 CHECK(array->Has(2));
2618 CHECK_EQ(7, array->Get(2)->Int32Value());
2619 Local<Value> obj = Script::Compile(v8_str(
"[1, 2, 3]"))->Run();
2620 Local<v8::Array> arr = obj.As<
v8::Array>();
2622 CHECK_EQ(1, arr->Get(0)->Int32Value());
2623 CHECK_EQ(2, arr->Get(1)->Int32Value());
2624 CHECK_EQ(3, arr->Get(2)->Int32Value());
2636 for (
int i = 0; i < args.
Length(); i++)
2637 result->Set(i, args[i]);
2638 return scope.
Close(result);
2644 Local<ObjectTemplate> global = ObjectTemplate::New();
2648 const char* fun =
"f()";
2649 Local<v8::Array> a0 = CompileRun(fun).As<
v8::Array>();
2652 const char* fun2 =
"f(11)";
2653 Local<v8::Array> a1 = CompileRun(fun2).As<
v8::Array>();
2655 CHECK_EQ(11, a1->Get(0)->Int32Value());
2657 const char* fun3 =
"f(12, 13)";
2658 Local<v8::Array> a2 = CompileRun(fun3).As<
v8::Array>();
2660 CHECK_EQ(12, a2->Get(0)->Int32Value());
2661 CHECK_EQ(13, a2->Get(1)->Int32Value());
2663 const char* fun4 =
"f(14, 15, 16)";
2664 Local<v8::Array> a3 = CompileRun(fun4).As<
v8::Array>();
2666 CHECK_EQ(14, a3->Get(0)->Int32Value());
2667 CHECK_EQ(15, a3->Get(1)->Int32Value());
2668 CHECK_EQ(16, a3->Get(2)->Int32Value());
2670 const char* fun5 =
"f(17, 18, 19, 20)";
2671 Local<v8::Array> a4 = CompileRun(fun5).As<
v8::Array>();
2673 CHECK_EQ(17, a4->Get(0)->Int32Value());
2674 CHECK_EQ(18, a4->Get(1)->Int32Value());
2675 CHECK_EQ(19, a4->Get(2)->Int32Value());
2676 CHECK_EQ(20, a4->Get(3)->Int32Value());
2686 " for (var i = 0; i < arguments.length; i++) {"
2687 " result.push(arguments[i]);"
2691 Local<Function> Foo =
2692 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
2695 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
2699 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
2705 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2));
2713 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3));
2723 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
2732 static const char* js_code_causing_out_of_memory =
2733 "var a = new Array(); while(true) a.push(a);";
2742 static const int K = 1024;
2752 Local<Script> script =
2753 Script::Compile(String::New(js_code_causing_out_of_memory));
2754 Local<Value> result = script->Run();
2757 CHECK(result.IsEmpty());
2767 Local<Script> script =
2768 Script::Compile(String::New(js_code_causing_out_of_memory));
2769 Local<Value> result = script->Run();
2772 CHECK(result.IsEmpty());
2783 static const int K = 1024;
2790 Local<ObjectTemplate> templ = ObjectTemplate::New();
2791 templ->Set(v8_str(
"ProvokeOutOfMemory"),
2795 Local<Value> result = CompileRun(
2796 "var thrown = false;"
2798 " ProvokeOutOfMemory();"
2803 CHECK(result.IsEmpty());
2812 static const int K = 1024;
2825 Local<Value> result = CompileRun(
2826 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
2827 "for (var i = 0; i < 22; i++) { str = str + str; }");
2830 CHECK(result.IsEmpty());
2841 " for (var i = 0; i < arguments.length; i++) {"
2842 " result.push(arguments[i]);"
2846 Local<Function> Foo =
2847 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
2850 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0));
2854 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1));
2860 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2));
2868 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3));
2878 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4));
2889 String::AsciiValue str_value(try_catch->
Exception());
2899 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
2900 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
2901 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
2902 CHECK_EQ(0, obj->ToInt32()->Value());
2903 CHECK(0u == obj->ToUint32()->Value());
2905 CompileRun(
"var obj = -1234567890123;");
2906 obj = env->
Global()->Get(v8_str(
"obj"));
2907 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
2908 CHECK_EQ(-1912276171, obj->ToInt32()->Value());
2909 CHECK(2382691125u == obj->ToUint32()->Value());
2911 CompileRun(
"var obj = 42;");
2912 obj = env->
Global()->Get(v8_str(
"obj"));
2913 CHECK_EQ(42.0, obj->ToNumber()->Value());
2914 CHECK_EQ(42, obj->ToInt32()->Value());
2915 CHECK(42u == obj->ToUint32()->Value());
2917 CompileRun(
"var obj = -37;");
2918 obj = env->
Global()->Get(v8_str(
"obj"));
2919 CHECK_EQ(-37.0, obj->ToNumber()->Value());
2920 CHECK_EQ(-37, obj->ToInt32()->Value());
2921 CHECK(4294967259u == obj->ToUint32()->Value());
2923 CompileRun(
"var obj = 0x81234567;");
2924 obj = env->
Global()->Get(v8_str(
"obj"));
2925 CHECK_EQ(2166572391.0, obj->ToNumber()->Value());
2926 CHECK_EQ(-2128394905, obj->ToInt32()->Value());
2927 CHECK(2166572391u == obj->ToUint32()->Value());
2929 CompileRun(
"var obj = 42.3;");
2930 obj = env->
Global()->Get(v8_str(
"obj"));
2931 CHECK_EQ(42.3, obj->ToNumber()->Value());
2932 CHECK_EQ(42, obj->ToInt32()->Value());
2933 CHECK(42u == obj->ToUint32()->Value());
2935 CompileRun(
"var obj = -5726623061.75;");
2936 obj = env->
Global()->Get(v8_str(
"obj"));
2937 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
2938 CHECK_EQ(-1431655765, obj->ToInt32()->Value());
2939 CHECK(2863311531u == obj->ToUint32()->Value());
2947 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
2948 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
2949 CHECK(!obj->IsInt32());
2950 CHECK(!obj->IsUint32());
2952 CompileRun(
"var obj = -1234567890123;");
2953 obj = env->
Global()->Get(v8_str(
"obj"));
2954 CHECK(!obj->IsInt32());
2955 CHECK(!obj->IsUint32());
2957 CompileRun(
"var obj = 42;");
2958 obj = env->
Global()->Get(v8_str(
"obj"));
2959 CHECK(obj->IsInt32());
2960 CHECK(obj->IsUint32());
2962 CompileRun(
"var obj = -37;");
2963 obj = env->
Global()->Get(v8_str(
"obj"));
2964 CHECK(obj->IsInt32());
2965 CHECK(!obj->IsUint32());
2967 CompileRun(
"var obj = 0x81234567;");
2968 obj = env->
Global()->Get(v8_str(
"obj"));
2969 CHECK(!obj->IsInt32());
2970 CHECK(obj->IsUint32());
2972 CompileRun(
"var obj = 42.3;");
2973 obj = env->
Global()->Get(v8_str(
"obj"));
2974 CHECK(!obj->IsInt32());
2975 CHECK(!obj->IsUint32());
2977 CompileRun(
"var obj = -5726623061.75;");
2978 obj = env->
Global()->Get(v8_str(
"obj"));
2979 CHECK(!obj->IsInt32());
2980 CHECK(!obj->IsUint32());
2982 CompileRun(
"var obj = 0.0;");
2983 obj = env->
Global()->Get(v8_str(
"obj"));
2984 CHECK(obj->IsInt32());
2985 CHECK(obj->IsUint32());
2987 CompileRun(
"var obj = -0.0;");
2988 obj = env->
Global()->Get(v8_str(
"obj"));
2989 CHECK(!obj->IsInt32());
2990 CHECK(!obj->IsUint32());
2998 "function TestClass() { };"
2999 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
3000 "var obj = new TestClass();");
3001 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
3005 Local<Value> to_string_result = obj->ToString();
3006 CHECK(to_string_result.IsEmpty());
3007 CheckUncle(&try_catch);
3009 Local<Value> to_number_result = obj->ToNumber();
3010 CHECK(to_number_result.IsEmpty());
3011 CheckUncle(&try_catch);
3013 Local<Value> to_integer_result = obj->ToInteger();
3014 CHECK(to_integer_result.IsEmpty());
3015 CheckUncle(&try_catch);
3017 Local<Value> to_uint32_result = obj->ToUint32();
3018 CHECK(to_uint32_result.IsEmpty());
3019 CheckUncle(&try_catch);
3021 Local<Value> to_int32_result = obj->ToInt32();
3022 CHECK(to_int32_result.IsEmpty());
3023 CheckUncle(&try_catch);
3025 Local<Value> to_object_result =
v8::Undefined()->ToObject();
3026 CHECK(to_object_result.IsEmpty());
3030 int32_t int32_value = obj->Int32Value();
3032 CheckUncle(&try_catch);
3034 uint32_t uint32_value = obj->Uint32Value();
3036 CheckUncle(&try_catch);
3038 double number_value = obj->NumberValue();
3040 CheckUncle(&try_catch);
3042 int64_t integer_value = obj->IntegerValue();
3043 CHECK_EQ(0.0, static_cast<double>(integer_value));
3044 CheckUncle(&try_catch);
3066 Local<ObjectTemplate> templ = ObjectTemplate::New();
3067 templ->Set(v8_str(
"ThrowFromC"),
3071 "var thrown = false;"
3077 Local<Value> thrown = context->
Global()->Get(v8_str(
"thrown"));
3078 CHECK(thrown->BooleanValue());
3084 Local<ObjectTemplate> templ = ObjectTemplate::New();
3085 templ->Set(v8_str(
"ThrowFromC"),
3089 CompileRun(
"ThrowFromC();");
3103 Local<ObjectTemplate> templ = ObjectTemplate::New();
3104 templ->Set(v8_str(
"CCatcher"),
3107 Local<Value> result = CompileRun(
"try {"
3109 " CCatcher('throw 7;');"
3114 CHECK(result->IsTrue());
3118 static void check_reference_error_message(
3121 const char* reference_error =
"Uncaught ReferenceError: asdf is not defined";
3122 CHECK(message->
Get()->Equals(v8_str(reference_error)));
3136 TEST(APIThrowMessageOverwrittenToString) {
3139 Local<ObjectTemplate> templ = ObjectTemplate::New();
3142 CompileRun(
"asdf;");
3143 CompileRun(
"var limit = {};"
3144 "limit.valueOf = fail;"
3145 "Error.stackTraceLimit = limit;");
3147 CompileRun(
"Array.prototype.pop = fail;");
3148 CompileRun(
"Object.prototype.hasOwnProperty = fail;");
3149 CompileRun(
"Object.prototype.toString = function f() { return 'Yikes'; }");
3150 CompileRun(
"Number.prototype.toString = function f() { return 'Yikes'; }");
3151 CompileRun(
"String.prototype.toString = function f() { return 'Yikes'; }");
3152 CompileRun(
"ReferenceError.prototype.toString ="
3153 " function() { return 'Whoops' }");
3154 CompileRun(
"asdf;");
3155 CompileRun(
"ReferenceError.prototype.constructor.name = void 0;");
3156 CompileRun(
"asdf;");
3157 CompileRun(
"ReferenceError.prototype.constructor = void 0;");
3158 CompileRun(
"asdf;");
3159 CompileRun(
"ReferenceError.prototype.__proto__ = new Object();");
3160 CompileRun(
"asdf;");
3161 CompileRun(
"ReferenceError.prototype = new Object();");
3162 CompileRun(
"asdf;");
3165 CompileRun(
"ReferenceError.prototype.constructor = new Object();"
3166 "ReferenceError.prototype.constructor.name = 1;"
3167 "Number.prototype.toString = function() { return 'Whoops'; };"
3168 "ReferenceError.prototype.toString = Object.prototype.toString;");
3169 CompileRun(
"asdf;");
3174 static void check_custom_error_message(
3177 const char* uncaught_error =
"Uncaught MyError toString";
3178 CHECK(message->
Get()->Equals(v8_str(uncaught_error)));
3187 "function MyError(name, message) { "
3188 " this.name = name; "
3189 " this.message = message; "
3191 "MyError.prototype = Object.create(Error.prototype); "
3192 "MyError.prototype.toString = function() { "
3193 " return 'MyError toString'; "
3195 "throw new MyError('my name', 'my message'); ");
3203 message_received =
true;
3208 message_received =
false;
3211 Local<ObjectTemplate> templ = ObjectTemplate::New();
3212 templ->Set(v8_str(
"ThrowFromC"),
3215 CompileRun(
"ThrowFromC();");
3216 CHECK(message_received);
3221 TEST(APIThrowMessageAndVerboseTryCatch) {
3222 message_received =
false;
3225 Local<ObjectTemplate> templ = ObjectTemplate::New();
3226 templ->Set(v8_str(
"ThrowFromC"),
3231 Local<Value> result = CompileRun(
"ThrowFromC();");
3233 CHECK(result.IsEmpty());
3234 CHECK(message_received);
3239 TEST(APIStackOverflowAndVerboseTryCatch) {
3240 message_received =
false;
3246 Local<Value> result = CompileRun(
"function foo() { foo(); } foo();");
3248 CHECK(result.IsEmpty());
3249 CHECK(message_received);
3256 Local<ObjectTemplate> templ = ObjectTemplate::New();
3257 templ->Set(v8_str(
"ThrowFromC"),
3262 Local<Script> script
3263 = Script::Compile(v8_str(
"ThrowFromC(); throw 'panama';"));
3264 Local<Value> result = script->Run();
3265 CHECK(result.IsEmpty());
3267 String::AsciiValue exception_value(try_catch.
Exception());
3268 CHECK_EQ(
"konto", *exception_value);
3276 int count = args[0]->Int32Value();
3277 int cInterval = args[2]->Int32Value();
3281 Local<v8::Object> global = Context::GetCurrent()->Global();
3282 Local<Value> fun = global->Get(v8_str(
"JSThrowCountDown"));
3287 if (count % cInterval == 0) {
3289 Local<Value> result = fun.
As<Function>()->Call(global, 4, argv);
3290 int expected = args[3]->Int32Value();
3293 CHECK(result.IsEmpty());
3294 CHECK(!i::Isolate::Current()->has_scheduled_exception());
3300 return fun.As<Function>()->Call(global, 4, argv);
3309 bool equality = args[0]->BooleanValue();
3310 int count = args[1]->Int32Value();
3311 int expected = args[2]->Int32Value();
3325 CompileRun(
"(function() {"
3327 " eval('asldkf (*&^&*^');"
3358 Local<ObjectTemplate> templ = ObjectTemplate::New();
3360 templ->Set(v8_str(
"CThrowCountDown"),
3364 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
3365 " if (count == 0) throw 'FromJS';"
3366 " if (count % jsInterval == 0) {"
3368 " var value = CThrowCountDown(count - 1,"
3372 " check(false, count, expected);"
3375 " check(true, count, expected);"
3378 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);"
3381 Local<Function> fun =
3382 Local<Function>::Cast(context->
Global()->Get(v8_str(
"JSThrowCountDown")));
3389 fun->Call(fun, argc, a0);
3393 fun->Call(fun, argc, a1);
3397 fun->Call(fun, argc, a2);
3401 fun->Call(fun, argc, a3);
3405 fun->Call(fun, argc, a4);
3409 fun->Call(fun, argc, a5);
3422 Local<ObjectTemplate> templ = ObjectTemplate::New();
3426 "function Run(obj) {"
3432 " return 'no exception';"
3434 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
3451 Script::Compile(v8_str(
"throw 10"))->Run();
3456 Script::Compile(v8_str(
"throw 0"))->Run();
3467 Script::Compile(v8_str(
"var o = {}; with (o) { throw 42; }"))->Run();
3477 CompileRun(
"function f(k) { try { this[k]; } finally { return 0; } };");
3478 CompileRun(
"f({toString: function() { throw 42; }});");
3493 v8_str(
"native_with_try_catch"),
3499 " throw new Error('a');\n"
3501 " native_with_try_catch();\n"
3511 CHECK(v8_str(
"a")->Equals(v8_str(
"a")));
3512 CHECK(!v8_str(
"a")->Equals(v8_str(
"b")));
3514 CHECK_EQ(v8_str(
"a"), v8_str(
"a"));
3515 CHECK_NE(v8_str(
"a"), v8_str(
"b"));
3521 CHECK(v8_str(
"a")->StrictEquals(v8_str(
"a")));
3522 CHECK(!v8_str(
"a")->StrictEquals(v8_str(
"b")));
3523 CHECK(!v8_str(
"5")->StrictEquals(v8_num(5)));
3524 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
3525 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
3526 CHECK(v8_num(0)->StrictEquals(v8_num(-0)));
3528 CHECK(!not_a_number->StrictEquals(not_a_number));
3534 CHECK(alias->StrictEquals(obj));
3542 Local<Script> script = Script::Compile(v8_str(
"x"));
3543 for (
int i = 0; i < 10; i++)
3549 const AccessorInfo& info) {
3551 CHECK_EQ(info.Data(), v8_str(
"donut"));
3559 Local<ObjectTemplate> templ = ObjectTemplate::New();
3560 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3562 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3563 Local<Script> script = Script::Compile(v8_str(
"obj.x"));
3564 for (
int i = 0; i < 10; i++) {
3565 Local<Value> result = script->Run();
3572 Local<ObjectTemplate> templ = ObjectTemplate::New();
3573 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3575 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3578 Local<Script> script_desc
3579 = Script::Compile(v8_str(
"var prop = Object.getOwnPropertyDescriptor( "
3581 "prop.configurable;"));
3582 Local<Value> result = script_desc->Run();
3583 CHECK_EQ(result->BooleanValue(),
true);
3586 Local<Script> script_define
3587 = Script::Compile(v8_str(
"var desc = { get: function(){return 42; },"
3588 " configurable: true };"
3589 "Object.defineProperty(obj, 'x', desc);"
3591 result = script_define->Run();
3595 result = script_desc->Run();
3596 CHECK_EQ(result->BooleanValue(),
true);
3600 = Script::Compile(v8_str(
"var desc = { get: function(){return 43; },"
3601 " configurable: false };"
3602 "Object.defineProperty(obj, 'x', desc);"
3604 result = script_define->Run();
3606 result = script_desc->Run();
3607 CHECK_EQ(result->BooleanValue(),
false);
3611 result = script_define->Run();
3612 CHECK(try_catch.HasCaught());
3613 String::AsciiValue exception_value(try_catch.Exception());
3614 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3619 Local<ObjectTemplate> templ = ObjectTemplate::New();
3620 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
3622 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3624 Local<Script> script_desc = Script::Compile(v8_str(
"var prop ="
3625 "Object.getOwnPropertyDescriptor( "
3627 "prop.configurable;"));
3628 Local<Value> result = script_desc->Run();
3629 CHECK_EQ(result->BooleanValue(),
true);
3631 Local<Script> script_define =
3632 Script::Compile(v8_str(
"var desc = {get: function(){return 42; },"
3633 " configurable: true };"
3634 "Object.defineProperty(obj, 'x', desc);"
3636 result = script_define->Run();
3640 result = script_desc->Run();
3641 CHECK_EQ(result->BooleanValue(),
true);
3645 Script::Compile(v8_str(
"var desc = {get: function(){return 43; },"
3646 " configurable: false };"
3647 "Object.defineProperty(obj, 'x', desc);"
3649 result = script_define->Run();
3651 result = script_desc->Run();
3653 CHECK_EQ(result->BooleanValue(),
false);
3656 result = script_define->Run();
3657 CHECK(try_catch.HasCaught());
3658 String::AsciiValue exception_value(try_catch.Exception());
3659 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3671 Local<ObjectTemplate> templ = ObjectTemplate::New();
3674 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3675 CompileRun(
"var obj2 = {};");
3677 CHECK(CompileRun(
"obj1.x")->IsUndefined());
3678 CHECK(CompileRun(
"obj2.x")->IsUndefined());
3680 CHECK(GetGlobalProperty(&context,
"obj1")->
3683 ExpectString(
"obj1.x",
"x");
3684 CHECK(CompileRun(
"obj2.x")->IsUndefined());
3686 CHECK(GetGlobalProperty(&context,
"obj2")->
3689 ExpectString(
"obj1.x",
"x");
3690 ExpectString(
"obj2.x",
"x");
3692 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3693 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3695 CompileRun(
"Object.defineProperty(obj1, 'x',"
3696 "{ get: function() { return 'y'; }, configurable: true })");
3698 ExpectString(
"obj1.x",
"y");
3699 ExpectString(
"obj2.x",
"x");
3701 CompileRun(
"Object.defineProperty(obj2, 'x',"
3702 "{ get: function() { return 'y'; }, configurable: true })");
3704 ExpectString(
"obj1.x",
"y");
3705 ExpectString(
"obj2.x",
"y");
3707 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3708 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3710 CHECK(GetGlobalProperty(&context,
"obj1")->
3712 CHECK(GetGlobalProperty(&context,
"obj2")->
3715 ExpectString(
"obj1.x",
"x");
3716 ExpectString(
"obj2.x",
"x");
3718 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3719 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3722 CompileRun(
"Object.defineProperty(obj1, 'x',"
3723 "{ get: function() { return 'z'; }, configurable: false })");
3724 CompileRun(
"Object.defineProperty(obj2, 'x',"
3725 "{ get: function() { return 'z'; }, configurable: false })");
3727 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3728 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3730 ExpectString(
"obj1.x",
"z");
3731 ExpectString(
"obj2.x",
"z");
3733 CHECK(!GetGlobalProperty(&context,
"obj1")->
3735 CHECK(!GetGlobalProperty(&context,
"obj2")->
3738 ExpectString(
"obj1.x",
"z");
3739 ExpectString(
"obj2.x",
"z");
3745 Local<ObjectTemplate> templ = ObjectTemplate::New();
3748 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3749 CompileRun(
"var obj2 = {};");
3760 ExpectString(
"obj1.x",
"x");
3761 ExpectString(
"obj2.x",
"x");
3763 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
3764 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
3766 CHECK(!GetGlobalProperty(&context,
"obj1")->
3768 CHECK(!GetGlobalProperty(&context,
"obj2")->
3773 CompileRun(
"Object.defineProperty(obj1, 'x',"
3774 "{get: function() { return 'func'; }})");
3776 String::AsciiValue exception_value(try_catch.
Exception());
3777 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3781 CompileRun(
"Object.defineProperty(obj2, 'x',"
3782 "{get: function() { return 'func'; }})");
3784 String::AsciiValue exception_value(try_catch.
Exception());
3785 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
3791 const AccessorInfo& info) {
3793 CHECK_EQ(info.Data(), v8_str(
"donut"));
3801 Local<ObjectTemplate> templ = ObjectTemplate::New();
3804 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
3805 CompileRun(
"var obj2 = {};");
3816 ExpectString(
"obj1[239]",
"239");
3817 ExpectString(
"obj2[239]",
"239");
3818 ExpectString(
"obj1['239']",
"239");
3819 ExpectString(
"obj2['239']",
"239");
3826 static void SetXValue(Local<String> name,
3828 const AccessorInfo& info) {
3830 CHECK_EQ(info.Data(), v8_str(
"donut"));
3839 Local<ObjectTemplate> templ = ObjectTemplate::New();
3840 templ->SetAccessor(v8_str(
"x"), GetXValue, SetXValue, v8_str(
"donut"));
3842 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3843 Local<Script> script = Script::Compile(v8_str(
"obj.x = 4"));
3844 for (
int i = 0; i < 10; i++) {
3856 Local<ObjectTemplate> templ = ObjectTemplate::New();
3857 templ->SetAccessor(v8_str(
"x"),
NULL, SetXValue, v8_str(
"donut"));
3859 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3860 Local<Script> script = Script::Compile(v8_str(
"obj.x = 4; obj.x"));
3861 for (
int i = 0; i < 10; i++) {
3873 Local<ObjectTemplate> templ = ObjectTemplate::New();
3874 templ->SetAccessor(v8_str(
"x"),
NULL,
NULL, v8_str(
"donut"));
3876 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3877 Local<Script> script = Script::Compile(v8_str(
"obj.x = 4; obj.x"));
3878 for (
int i = 0; i < 10; i++) {
3885 const AccessorInfo& info) {
3887 CHECK(info.Data()->IsUndefined());
3894 Local<ObjectTemplate> templ = ObjectTemplate::New();
3895 templ->SetNamedPropertyHandler(XPropertyGetter);
3897 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
3898 Local<Script> script = Script::Compile(v8_str(
"obj.x"));
3899 for (
int i = 0; i < 10; i++) {
3900 Local<Value> result = script->Run();
3908 Local<ObjectTemplate> templ = ObjectTemplate::New();
3909 templ->SetNamedPropertyHandler(XPropertyGetter);
3912 context->
Global()->Set(v8_str(
"interceptor_obj"), templ->NewInstance());
3913 Local<Script> script = Script::Compile(v8_str(
"interceptor_obj.x"));
3914 for (
int i = 0; i < 10; i++) {
3915 Local<Value> result = script->Run();
3923 Local<Value> result =
3924 CompileRun(
"function get_x(o) { return o.x; };"
3925 "var obj = { x : 42, y : 0 };"
3927 "for (var i = 0; i < 10; i++) get_x(obj);"
3928 "interceptor_obj.x = 42;"
3929 "interceptor_obj.y = 10;"
3930 "delete interceptor_obj.y;"
3931 "get_x(interceptor_obj)");
3942 Local<ObjectTemplate> templ = ObjectTemplate::New();
3943 templ->SetNamedPropertyHandler(XPropertyGetter);
3946 context1->Global()->Set(v8_str(
"interceptor_obj"),
object);
3949 CompileRun(
"interceptor_obj.y = 0;"
3950 "delete interceptor_obj.y;");
3957 context2->
Global()->Set(v8_str(
"interceptor_obj"),
object);
3958 Local<Value> result =
3959 CompileRun(
"function get_x(o) { return o.x; }"
3960 "interceptor_obj.x = 42;"
3961 "for (var i=0; i != 10; i++) {"
3962 " get_x(interceptor_obj);"
3964 "get_x(interceptor_obj)");
3972 CompileRun(
"var obj = { x : 0 }; delete obj.x;");
3980 const AccessorInfo& info) {
3994 = function_template->InstanceTemplate();
3995 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
3997 context->
Global()->Set(v8_str(
"F"), function_template->GetFunction());
3999 CompileRun(
"var o = new F(); o.x = 23;");
4001 Local<Value> result = CompileRun(
"o = new F(); o.x");
4002 CHECK_EQ(result->Int32Value(), 23);
4007 const AccessorInfo& info) {
4018 const AccessorInfo& info) {
4029 Local<ObjectTemplate> templ = ObjectTemplate::New();
4030 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
4031 IndexedPropertySetter);
4033 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4034 Local<Script> getter_script = Script::Compile(v8_str(
4035 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"));
4036 Local<Script> setter_script = Script::Compile(v8_str(
4037 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
4040 Local<Script> interceptor_setter_script = Script::Compile(v8_str(
4041 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});"
4044 Local<Script> interceptor_getter_script = Script::Compile(v8_str(
4046 Local<Value> result = getter_script->Run();
4048 result = setter_script->Run();
4050 result = interceptor_setter_script->Run();
4052 result = interceptor_getter_script->Run();
4059 const AccessorInfo& info) {
4071 const AccessorInfo& info) {
4081 const AccessorInfo& info) {
4083 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
4084 "keys = new Array(); keys[125000] = 1;"
4085 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
4086 "keys.length = 25; keys;"));
4087 Local<Value> result = indexed_property_names_script->Run();
4096 Local<ObjectTemplate> templ = ObjectTemplate::New();
4097 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
4098 UnboxedDoubleIndexedPropertySetter,
4103 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4105 Local<Script> create_unboxed_double_script = Script::Compile(v8_str(
4106 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } "
4108 "for (x in obj) {key_count++;};"
4110 Local<Value> result = create_unboxed_double_script->Run();
4111 CHECK(result->ToObject()->HasRealIndexedProperty(2000));
4112 Local<Script> key_count_check = Script::Compile(v8_str(
4114 result = key_count_check->Run();
4120 const AccessorInfo& info) {
4122 Local<Script> indexed_property_names_script = Script::Compile(v8_str(
4124 " return arguments;"
4126 "keys = f(0, 1, 2, 3);"
4128 Local<Value> result = indexed_property_names_script->Run();
4135 const AccessorInfo& info) {
4148 Local<ObjectTemplate> templ = ObjectTemplate::New();
4149 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
4155 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4156 Local<Script> create_args_script =
4157 Script::Compile(v8_str(
4158 "var key_count = 0;"
4159 "for (x in obj) {key_count++;} key_count;"));
4160 Local<Value> result = create_args_script->Run();
4167 const AccessorInfo& info) {
4174 Local<ObjectTemplate> templ = ObjectTemplate::New();
4175 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4178 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4181 const char* fast_case_code =
4182 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
4183 ExpectString(fast_case_code,
"0");
4186 const char* slow_case_code =
4187 "obj.x = 1; delete obj.x;"
4188 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
4189 ExpectString(slow_case_code,
"1");
4195 Local<ObjectTemplate> templ = ObjectTemplate::New();
4196 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4199 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
4204 " for (var i = 0; i < 100; i++) {"
4206 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
4212 ExpectString(code,
"PASSED");
4218 Local<ObjectTemplate> templ = ObjectTemplate::New();
4219 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4222 Local<v8::Object> obj = templ->NewInstance();
4224 context->
Global()->Set(v8_str(
"obj"), obj);
4228 " for (var i = 0; i < 100; i++) {"
4230 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
4236 ExpectString(code,
"PASSED");
4241 i::FLAG_allow_natives_syntax =
true;
4243 Local<ObjectTemplate> templ = ObjectTemplate::New();
4244 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4247 Local<v8::Object> obj = templ->NewInstance();
4248 context->
Global()->Set(v8_str(
"obj"), obj);
4252 " for (var i = 0; i < 100; i++) {"
4253 " var expected = i;"
4255 " %EnableAccessChecks(obj);"
4256 " expected = undefined;"
4259 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4260 " if (i == 5) %DisableAccessChecks(obj);"
4266 ExpectString(code,
"PASSED");
4272 Local<ObjectTemplate> templ = ObjectTemplate::New();
4273 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4276 Local<v8::Object> obj = templ->NewInstance();
4277 context->
Global()->Set(v8_str(
"obj"), obj);
4281 " for (var i = 0; i < 100; i++) {"
4283 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4289 ExpectString(code,
"PASSED");
4295 Local<ObjectTemplate> templ = ObjectTemplate::New();
4296 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4299 Local<v8::Object> obj = templ->NewInstance();
4300 context->
Global()->Set(v8_str(
"obj"), obj);
4304 " for (var i = 0; i < 100; i++) {"
4305 " var expected = i;"
4309 " expected = undefined;"
4312 " /* probe minimal Smi number on 32-bit platforms */"
4313 " key = -(1 << 30);"
4314 " expected = undefined;"
4317 " /* probe minimal Smi number on 64-bit platforms */"
4319 " expected = undefined;"
4321 " var v = obj[key];"
4322 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4328 ExpectString(code,
"PASSED");
4334 Local<ObjectTemplate> templ = ObjectTemplate::New();
4335 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4338 Local<v8::Object> obj = templ->NewInstance();
4339 context->
Global()->Set(v8_str(
"obj"), obj);
4343 " for (var i = 0; i < 100; i++) {"
4344 " var expected = i;"
4348 " expected = undefined;"
4350 " var v = obj[key];"
4351 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4357 ExpectString(code,
"PASSED");
4363 Local<ObjectTemplate> templ = ObjectTemplate::New();
4364 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4367 Local<v8::Object> obj = templ->NewInstance();
4368 context->
Global()->Set(v8_str(
"obj"), obj);
4371 "var original = obj;"
4373 " for (var i = 0; i < 100; i++) {"
4374 " var expected = i;"
4376 " obj = {50: 'foobar'};"
4377 " expected = 'foobar';"
4380 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4381 " if (i == 50) obj = original;"
4387 ExpectString(code,
"PASSED");
4393 Local<ObjectTemplate> templ = ObjectTemplate::New();
4394 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4397 Local<v8::Object> obj = templ->NewInstance();
4398 context->
Global()->Set(v8_str(
"obj"), obj);
4401 "var original = obj;"
4403 " for (var i = 0; i < 100; i++) {"
4404 " var expected = i;"
4407 " expected = undefined;"
4410 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4411 " if (i == 5) obj = original;"
4417 ExpectString(code,
"PASSED");
4423 Local<ObjectTemplate> templ = ObjectTemplate::New();
4424 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4427 Local<v8::Object> obj = templ->NewInstance();
4428 context->
Global()->Set(v8_str(
"obj"), obj);
4431 "var o = {__proto__: obj};"
4433 " for (var i = 0; i < 100; i++) {"
4435 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4441 ExpectString(code,
"PASSED");
4450 Local<String> password = v8_str(
"Password");
4456 global0->
Set(v8_str(
"custom"), v8_num(1234));
4457 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
4461 context1->SetSecurityToken(password);
4463 global1->
Set(v8_str(
"custom"), v8_num(1234));
4465 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
4466 CHECK_EQ(1234, global1->
Get(v8_str(
"custom"))->Int32Value());
4470 context2->SetSecurityToken(password);
4473 CHECK_EQ(0, global1->
Get(v8_str(
"custom"))->Int32Value());
4474 CHECK_EQ(0, global2->
Get(v8_str(
"custom"))->Int32Value());
4493 proto0->
Set(v8_str(
"custom"), v8_num(1234));
4504 CHECK(!proto1->Has(v8_str(
"custom")));
4517 Local<String> source = v8_str(
"Object.prototype.obj = 1234;"
4518 "Array.prototype.arr = 4567;"
4522 Local<Script> script0 = Script::Compile(source);
4523 CHECK_EQ(8901.0, script0->Run()->NumberValue());
4526 Local<Script> script1 = Script::Compile(source);
4527 CHECK_EQ(8901.0, script1->Run()->NumberValue());
4535 Local<v8::FunctionTemplate> desc =
4537 desc->InstanceTemplate()->MarkAsUndetectable();
4539 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4540 env->
Global()->Set(v8_str(
"undetectable"), obj);
4542 ExpectString(
"undetectable.toString()",
"[object Object]");
4543 ExpectString(
"typeof undetectable",
"undefined");
4544 ExpectString(
"typeof(undetectable)",
"undefined");
4545 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
4546 ExpectBoolean(
"typeof undetectable == 'object'",
false);
4547 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
4548 ExpectBoolean(
"!undetectable",
true);
4550 ExpectObject(
"true&&undetectable", obj);
4551 ExpectBoolean(
"false&&undetectable",
false);
4552 ExpectBoolean(
"true||undetectable",
true);
4553 ExpectObject(
"false||undetectable", obj);
4555 ExpectObject(
"undetectable&&true", obj);
4556 ExpectObject(
"undetectable&&false", obj);
4557 ExpectBoolean(
"undetectable||true",
true);
4558 ExpectBoolean(
"undetectable||false",
false);
4560 ExpectBoolean(
"undetectable==null",
true);
4561 ExpectBoolean(
"null==undetectable",
true);
4562 ExpectBoolean(
"undetectable==undefined",
true);
4563 ExpectBoolean(
"undefined==undetectable",
true);
4564 ExpectBoolean(
"undetectable==undetectable",
true);
4567 ExpectBoolean(
"undetectable===null",
false);
4568 ExpectBoolean(
"null===undetectable",
false);
4569 ExpectBoolean(
"undetectable===undefined",
false);
4570 ExpectBoolean(
"undefined===undetectable",
false);
4571 ExpectBoolean(
"undetectable===undetectable",
true);
4579 Local<v8::FunctionTemplate> desc =
4581 desc->InstanceTemplate()->MarkAsUndetectable();
4583 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4584 env->
Global()->Set(v8_str(
"undetectable"), obj);
4586 ExpectBoolean(
"undefined == void 0",
true);
4587 ExpectBoolean(
"undetectable == void 0",
true);
4588 ExpectBoolean(
"null == void 0",
true);
4589 ExpectBoolean(
"undefined === void 0",
true);
4590 ExpectBoolean(
"undetectable === void 0",
false);
4591 ExpectBoolean(
"null === void 0",
false);
4593 ExpectBoolean(
"void 0 == undefined",
true);
4594 ExpectBoolean(
"void 0 == undetectable",
true);
4595 ExpectBoolean(
"void 0 == null",
true);
4596 ExpectBoolean(
"void 0 === undefined",
true);
4597 ExpectBoolean(
"void 0 === undetectable",
false);
4598 ExpectBoolean(
"void 0 === null",
false);
4600 ExpectString(
"(function() {"
4602 " return x === void 0;"
4604 " return e.toString();"
4607 "ReferenceError: x is not defined");
4608 ExpectString(
"(function() {"
4610 " return void 0 === x;"
4612 " return e.toString();"
4615 "ReferenceError: x is not defined");
4623 Local<v8::FunctionTemplate> desc =
4625 desc->InstanceTemplate()->MarkAsUndetectable();
4627 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4628 env->
Global()->Set(v8_str(
"undetectable"), obj);
4630 Local<String> source = v8_str(
"undetectable.x = 42;"
4633 Local<Script> script = Script::Compile(source);
4637 ExpectBoolean(
"Object.isExtensible(undetectable)",
true);
4639 source = v8_str(
"Object.preventExtensions(undetectable);");
4640 script = Script::Compile(source);
4642 ExpectBoolean(
"Object.isExtensible(undetectable)",
false);
4644 source = v8_str(
"undetectable.y = 2000;");
4645 script = Script::Compile(source);
4647 ExpectBoolean(
"undetectable.y == undefined",
true);
4656 Local<String> obj = String::NewUndetectable(
"foo");
4657 env->
Global()->Set(v8_str(
"undetectable"), obj);
4659 ExpectString(
"undetectable",
"foo");
4660 ExpectString(
"typeof undetectable",
"undefined");
4661 ExpectString(
"typeof(undetectable)",
"undefined");
4662 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
4663 ExpectBoolean(
"typeof undetectable == 'string'",
false);
4664 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
4665 ExpectBoolean(
"!undetectable",
true);
4667 ExpectObject(
"true&&undetectable", obj);
4668 ExpectBoolean(
"false&&undetectable",
false);
4669 ExpectBoolean(
"true||undetectable",
true);
4670 ExpectObject(
"false||undetectable", obj);
4672 ExpectObject(
"undetectable&&true", obj);
4673 ExpectObject(
"undetectable&&false", obj);
4674 ExpectBoolean(
"undetectable||true",
true);
4675 ExpectBoolean(
"undetectable||false",
false);
4677 ExpectBoolean(
"undetectable==null",
true);
4678 ExpectBoolean(
"null==undetectable",
true);
4679 ExpectBoolean(
"undetectable==undefined",
true);
4680 ExpectBoolean(
"undefined==undetectable",
true);
4681 ExpectBoolean(
"undetectable==undetectable",
true);
4684 ExpectBoolean(
"undetectable===null",
false);
4685 ExpectBoolean(
"null===undetectable",
false);
4686 ExpectBoolean(
"undetectable===undefined",
false);
4687 ExpectBoolean(
"undefined===undetectable",
false);
4688 ExpectBoolean(
"undetectable===undetectable",
true);
4693 i::FLAG_allow_natives_syntax =
true;
4697 Local<String> obj = String::NewUndetectable(
"foo");
4698 env->
Global()->Set(v8_str(
"undetectable"), obj);
4699 env->
Global()->Set(v8_str(
"detectable"), v8_str(
"bar"));
4702 "function testBranch() {"
4703 " if (!%_IsUndetectableObject(undetectable)) throw 1;"
4704 " if (%_IsUndetectableObject(detectable)) throw 2;"
4706 "function testBool() {"
4707 " var b1 = !%_IsUndetectableObject(undetectable);"
4708 " var b2 = %_IsUndetectableObject(detectable);"
4713 "%OptimizeFunctionOnNextCall(testBranch);"
4714 "%OptimizeFunctionOnNextCall(testBool);"
4715 "for (var i = 0; i < 10; i++) {"
4724 template <
typename T>
static void USE(
T) { }
4728 static inline void PersistentHandles() {
4729 USE(PersistentHandles);
4730 Local<String> str = v8_str(
"foo");
4733 Local<Script> scr = Script::Compile(v8_str(
""));
4736 Local<ObjectTemplate> templ = ObjectTemplate::New();
4751 Local<ObjectTemplate> global_template = ObjectTemplate::New();
4752 global_template->Set(v8_str(
"JSNI_Log"),
4755 Context::Scope context_scope(context);
4756 Script::Compile(v8_str(
"JSNI_Log('LOG')"))->Run();
4761 static const char* kSimpleExtensionSource =
4770 const char* extension_names[] = {
"simpletest" };
4773 Context::Scope lock(context);
4782 const char* extension_names[] = {
"nulltest" };
4785 Context::Scope lock(context);
4791 static const char* kEmbeddedExtensionSource =
4792 "function Ret54321(){return 54321;}~~@@$"
4793 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
4794 static const int kEmbeddedExtensionSourceValidLen = 34;
4800 kEmbeddedExtensionSource));
4801 const char* extension_names[] = {
"srclentest_fail" };
4809 for (
int source_len = kEmbeddedExtensionSourceValidLen - 1;
4810 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
4815 kEmbeddedExtensionSource, 0, 0,
4817 const char* extension_names[1] = { extension_name.
start() };
4820 if (source_len == kEmbeddedExtensionSourceValidLen) {
4821 Context::Scope lock(context);
4832 static const char* kEvalExtensionSource1 =
4833 "function UseEval1() {"
4835 " return eval('x');"
4839 static const char* kEvalExtensionSource2 =
4843 " return eval('x');"
4845 " this.UseEval2 = e;"
4853 const char* extension_names[] = {
"evaltest1",
"evaltest2" };
4856 Context::Scope lock(context);
4859 result = Script::Compile(v8_str(
"UseEval2()"))->Run();
4864 static const char* kWithExtensionSource1 =
4865 "function UseWith1() {"
4867 " with({x:87}) { return x; }"
4872 static const char* kWithExtensionSource2 =
4876 " with ({x:87}) { return x; }"
4878 " this.UseWith2 = e;"
4886 const char* extension_names[] = {
"withtest1",
"withtest2" };
4889 Context::Scope lock(context);
4892 result = Script::Compile(v8_str(
"UseWith2()"))->Run();
4899 Extension* extension =
new Extension(
"autotest", kSimpleExtensionSource);
4900 extension->set_auto_enable(
true);
4903 Context::Scope lock(context);
4909 static const char* kSyntaxErrorInExtensionSource =
4918 kSyntaxErrorInExtensionSource));
4919 const char* extension_names[] = {
"syntaxerror" };
4926 static const char* kExceptionInExtensionSource =
4935 kExceptionInExtensionSource));
4936 const char* extension_names[] = {
"exception" };
4943 static const char* kNativeCallInExtensionSource =
4944 "function call_runtime_last_index_of(x) {"
4945 " return %StringLastIndexOf(x, 'bob', 10);"
4949 static const char* kNativeCallTest =
4950 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
4956 kNativeCallInExtensionSource));
4957 const char* extension_names[] = {
"nativecall" };
4960 Context::Scope lock(context);
4971 : Extension(name, source),
4980 if (args.
Length() >= 1)
return (args[0]);
4990 const char* name =
"nativedecl";
4992 "native function foo();"));
4993 const char* extension_names[] = { name };
4996 Context::Scope lock(context);
5004 const char* name =
"nativedeclerr";
5007 "native\nfunction foo();"));
5008 const char* extension_names[] = { name };
5017 const char* name =
"nativedeclerresc";
5022 "nativ\\u0065 function foo();"));
5023 const char* extension_names[] = { name };
5030 static void CheckDependencies(
const char* name,
const char* expected) {
5034 CHECK_EQ(String::New(expected), context->
Global()->Get(v8_str(
"loaded")));
5046 static const char* kEDeps[] = {
"D" };
5048 static const char* kDDeps[] = {
"B",
"C" };
5050 static const char* kBCDeps[] = {
"A" };
5054 CheckDependencies(
"A",
"undefinedA");
5055 CheckDependencies(
"B",
"undefinedAB");
5056 CheckDependencies(
"C",
"undefinedAC");
5057 CheckDependencies(
"D",
"undefinedABCD");
5058 CheckDependencies(
"E",
"undefinedABCDE");
5060 static const char* exts[2] = {
"C",
"E" };
5063 CHECK_EQ(v8_str(
"undefinedACBDE"), context->
Global()->Get(v8_str(
"loaded")));
5067 static const char* kExtensionTestScript =
5068 "native function A();"
5069 "native function B();"
5070 "native function C();"
5072 " if (i == 0) return A();"
5073 " if (i == 1) return B();"
5074 " if (i == 2) return C();"
5081 args.
This()->Set(v8_str(
"data"), args.
Data());
5096 static int lookup_count = 0;
5100 if (name->
Equals(v8_str(
"A"))) {
5102 }
else if (name->
Equals(v8_str(
"B"))) {
5104 }
else if (name->
Equals(v8_str(
"C"))) {
5115 static const char* exts[1] = {
"functiontest" };
5128 static const char* exts[1] = {
"functiontest" };
5131 for (
int i = 0; i < 10; i++) {
5135 Script::Compile(v8_str(
"(new A()).data"))->Run());
5137 Script::Compile(v8_str(
"(new B()).data"))->Run());
5139 Script::Compile(v8_str(
"(new C()).data"))->Run());
5144 static const char* last_location;
5145 static const char* last_message;
5147 if (last_location ==
NULL) {
5148 last_location = location;
5159 static const char* aDeps[] = {
"B" };
5161 static const char* bDeps[] = {
"A" };
5163 last_location =
NULL;
5171 static const char* js_code_causing_huge_string_flattening =
5173 "for (var i = 0; i < 30; i++) {"
5189 Local<Script> script =
5190 Script::Compile(String::New(js_code_causing_huge_string_flattening));
5191 last_location =
NULL;
5211 Script::Compile(v8_str(
"throw Error()"))->Run();
5235 return Local<Script>(*script_);
5252 const AccessorInfo& info) {
5261 prev->Set(v8_str(
"next"), obj);
5277 const char* extension_list[] = {
"v8/gc" };
5280 Context::Scope context_scope(context);
5283 context->Global()->Set(v8_str(
"whammy"), interceptor);
5286 "for (var i = 0; i < 10000; i++) {"
5287 " var obj = whammy.length;"
5288 " if (last) last.next = obj;"
5303 *(
reinterpret_cast<bool*
>(data)) =
true;
5309 Context::Scope context_scope(context);
5318 bool object_a_disposed =
false;
5319 object_a.
MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
5323 HEAP->PerformScavenge();
5324 CHECK(object_a_disposed);
5328 static void InvokeScavenge() {
5329 HEAP->PerformScavenge();
5333 static void InvokeMarkSweep() {
5341 *(
reinterpret_cast<bool*
>(data)) =
true;
5349 *(
reinterpret_cast<bool*
>(data)) =
true;
5356 Context::Scope context_scope(context);
5358 static const int kNumberOfGCTypes = 2;
5360 {&ForceScavenge, &ForceMarkSweep};
5362 typedef void (*GCInvoker)();
5363 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
5365 for (
int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
5366 for (
int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
5372 bool disposed =
false;
5373 object.MakeWeak(&disposed, gc_forcing_callback[inner_gc]);
5374 object.MarkIndependent();
5375 invoke_gc[outer_gc]();
5384 *(
reinterpret_cast<bool*
>(data)) =
true;
5390 Context::Scope context_scope(context);
5398 object->Set(y_str, y_str);
5400 bool revived =
false;
5401 object.MakeWeak(&revived, &RevivingCallback);
5402 object.MarkIndependent();
5403 HEAP->PerformScavenge();
5410 CHECK(object->Get(y_str)->Equals(y_str));
5437 args_fun = context->
Global()->Get(v8_str(
"f")).
As<Function>();
5438 v8_compile(
"f(1, 2, 3)")->Run();
5443 const AccessorInfo&) {
5449 const AccessorInfo&) {
5455 const AccessorInfo&) {
5456 if (!name->Equals(v8_str(
"foo"))) {
5485 CHECK(v8_compile(
"delete k.foo")->Run()->IsFalse());
5486 CHECK(v8_compile(
"delete k.bar")->Run()->IsTrue());
5488 CHECK_EQ(v8_compile(
"k.foo")->Run(), v8_str(
"foo"));
5489 CHECK(v8_compile(
"k.bar")->Run()->IsUndefined());
5491 CHECK(v8_compile(
"delete k[2]")->Run()->IsFalse());
5492 CHECK(v8_compile(
"delete k[4]")->Run()->IsTrue());
5494 CHECK_EQ(v8_compile(
"k[2]")->Run(), v8_num(2));
5495 CHECK(v8_compile(
"k[4]")->Run()->IsUndefined());
5501 if (name->Equals(v8_str(
"foo")) ||
5502 name->Equals(v8_str(
"bar")) ||
5503 name->Equals(v8_str(
"baz"))) {
5548 "k[4294967295] = 0;"
5550 "k[4294967296] = 0;"
5554 "k[30000000000] = 0;"
5557 "for (var prop in k) {"
5558 " result.push(prop);"
5597 static v8::Handle<Value> PGetter(Local<String> name,
const AccessorInfo& info) {
5601 CHECK_EQ(info.Holder(), global->
Get(v8_str(
"o1")));
5602 if (name->Equals(v8_str(
"p1"))) {
5604 }
else if (name->Equals(v8_str(
"p2"))) {
5606 }
else if (name->Equals(v8_str(
"p3"))) {
5608 }
else if (name->Equals(v8_str(
"p4"))) {
5620 "o1.__proto__ = { };"
5621 "var o2 = { __proto__: o1 };"
5622 "var o3 = { __proto__: o2 };"
5623 "var o4 = { __proto__: o3 };"
5624 "for (var i = 0; i < 10; i++) o4.p4;"
5625 "for (var i = 0; i < 10; i++) o3.p3;"
5626 "for (var i = 0; i < 10; i++) o2.p2;"
5627 "for (var i = 0; i < 10; i++) o1.p1;");
5632 const AccessorInfo& info) {
5636 CHECK_EQ(info.Holder(), global->
Get(v8_str(
"o1")));
5637 if (name->Equals(v8_str(
"p1"))) {
5639 }
else if (name->Equals(v8_str(
"p2"))) {
5641 }
else if (name->Equals(v8_str(
"p3"))) {
5643 }
else if (name->Equals(v8_str(
"p4"))) {
5667 p_getter_count2 = 0;
5679 for (
int i = 0; i < 100; i++) {
5683 context->
Global()->Set(v8_str(
"o2"), obj);
5685 Script::Compile(v8_str(
"o.__proto__ === o2.__proto__"))->Run();
5687 context->
Global()->Set(v8_str(
"o"), obj);
5694 if (*a == 0 && *b == 0)
return 0;
5695 if (*a != *b)
return 0 + *a - *b;
5704 if (n-- == 0)
return 0;
5705 if (*a == 0 && *b == 0)
return 0;
5706 if (*a != *b)
return 0 + *a - *b;
5714 int len = str->Utf8Length();
5718 len = str->Utf8Length();
5731 const int kStride = 4;
5734 "for (var i = 0; i < 0xd800; i += 4) {"
5735 " left = left + String.fromCharCode(i);"
5739 "for (var i = 0; i < 0xd800; i += 4) {"
5740 " right = String.fromCharCode(i) + right;"
5743 Handle<String> left_tree = global->
Get(v8_str(
"left")).As<String>();
5744 Handle<String> right_tree = global->
Get(v8_str(
"right")).As<String>();
5747 CHECK_EQ(0xd800 / kStride, left_tree->Length());
5748 CHECK_EQ(0xd800 / kStride, right_tree->Length());
5751 char utf8buf[0xd800 * 3];
5756 memset(utf8buf, 0x1, 1000);
5757 len = str2->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen);
5760 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5762 memset(utf8buf, 0x1, 1000);
5763 len = str2->WriteUtf8(utf8buf, 8, &charlen);
5766 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203\1", 9));
5768 memset(utf8buf, 0x1, 1000);
5769 len = str2->WriteUtf8(utf8buf, 7, &charlen);
5772 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5774 memset(utf8buf, 0x1, 1000);
5775 len = str2->WriteUtf8(utf8buf, 6, &charlen);
5778 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5780 memset(utf8buf, 0x1, 1000);
5781 len = str2->WriteUtf8(utf8buf, 5, &charlen);
5784 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
5786 memset(utf8buf, 0x1, 1000);
5787 len = str2->WriteUtf8(utf8buf, 4, &charlen);
5790 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
5792 memset(utf8buf, 0x1, 1000);
5793 len = str2->WriteUtf8(utf8buf, 3, &charlen);
5796 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
5798 memset(utf8buf, 0x1, 1000);
5799 len = str2->WriteUtf8(utf8buf, 2, &charlen);
5802 CHECK_EQ(0, strncmp(utf8buf,
"ab\1", 3));
5804 memset(utf8buf, 0x1,
sizeof(utf8buf));
5807 (0x80 + (0x800 - 0x80) * 2 + (0xd800 - 0x800) * 3) / kStride;
5809 len = left_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
5811 CHECK_EQ(0xd800 / kStride, charlen);
5812 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[utf8_expected - 3]));
5813 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[utf8_expected - 2]));
5815 static_cast<unsigned char>(utf8buf[utf8_expected - 1]));
5816 CHECK_EQ(1, utf8buf[utf8_expected]);
5818 memset(utf8buf, 0x1,
sizeof(utf8buf));
5821 len = right_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
5823 CHECK_EQ(0xd800 / kStride, charlen);
5824 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[0]));
5825 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[1]));
5826 CHECK_EQ(0xc0 - kStride, static_cast<unsigned char>(utf8buf[2]));
5827 CHECK_EQ(1, utf8buf[utf8_expected]);
5829 memset(buf, 0x1,
sizeof(buf));
5830 memset(wbuf, 0x1,
sizeof(wbuf));
5831 len = str->WriteAscii(buf);
5833 len = str->Write(wbuf);
5836 uint16_t answer1[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5837 CHECK_EQ(0, StrCmp16(answer1, wbuf));
5839 memset(buf, 0x1,
sizeof(buf));
5840 memset(wbuf, 0x1,
sizeof(wbuf));
5841 len = str->WriteAscii(buf, 0, 4);
5843 len = str->Write(wbuf, 0, 4);
5845 CHECK_EQ(0, strncmp(
"abcd\1", buf, 5));
5846 uint16_t answer2[] = {
'a',
'b',
'c',
'd', 0x101};
5847 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5));
5849 memset(buf, 0x1,
sizeof(buf));
5850 memset(wbuf, 0x1,
sizeof(wbuf));
5851 len = str->WriteAscii(buf, 0, 5);
5853 len = str->Write(wbuf, 0, 5);
5855 CHECK_EQ(0, strncmp(
"abcde\1", buf, 6));
5856 uint16_t answer3[] = {
'a',
'b',
'c',
'd',
'e', 0x101};
5857 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6));
5859 memset(buf, 0x1,
sizeof(buf));
5860 memset(wbuf, 0x1,
sizeof(wbuf));
5861 len = str->WriteAscii(buf, 0, 6);
5863 len = str->Write(wbuf, 0, 6);
5866 uint16_t answer4[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5867 CHECK_EQ(0, StrCmp16(answer4, wbuf));
5869 memset(buf, 0x1,
sizeof(buf));
5870 memset(wbuf, 0x1,
sizeof(wbuf));
5871 len = str->WriteAscii(buf, 4, -1);
5873 len = str->Write(wbuf, 4, -1);
5877 CHECK_EQ(0, StrCmp16(answer5, wbuf));
5879 memset(buf, 0x1,
sizeof(buf));
5880 memset(wbuf, 0x1,
sizeof(wbuf));
5881 len = str->WriteAscii(buf, 4, 6);
5883 len = str->Write(wbuf, 4, 6);
5886 CHECK_EQ(0, StrCmp16(answer5, wbuf));
5888 memset(buf, 0x1,
sizeof(buf));
5889 memset(wbuf, 0x1,
sizeof(wbuf));
5890 len = str->WriteAscii(buf, 4, 1);
5892 len = str->Write(wbuf, 4, 1);
5894 CHECK_EQ(0, strncmp(
"e\1", buf, 2));
5896 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2));
5898 memset(buf, 0x1,
sizeof(buf));
5899 memset(wbuf, 0x1,
sizeof(wbuf));
5900 len = str->WriteAscii(buf, 3, 1);
5902 len = str->Write(wbuf, 3, 1);
5904 CHECK_EQ(0, strncmp(
"d\1", buf, 2));
5906 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2));
5908 memset(wbuf, 0x1,
sizeof(wbuf));
5910 len = str->Write(wbuf, 0, 6, String::NO_NULL_TERMINATION);
5913 uint16_t answer8a[] = {
'a',
'b',
'c',
'd',
'e'};
5914 uint16_t answer8b[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
5915 CHECK_EQ(0, StrNCmp16(answer8a, wbuf, 5));
5916 CHECK_NE(0, StrCmp16(answer8b, wbuf));
5918 CHECK_EQ(0, StrCmp16(answer8b, wbuf));
5920 memset(buf, 0x1,
sizeof(buf));
5922 len = str->WriteAscii(buf, 0, 6, String::NO_NULL_TERMINATION);
5925 CHECK_EQ(0, strncmp(
"abcde", buf, 5));
5930 memset(utf8buf, 0x1,
sizeof(utf8buf));
5932 len = str2->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen,
5933 String::NO_NULL_TERMINATION);
5937 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203", 8));
5938 CHECK_NE(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5940 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
5942 memset(utf8buf, 0x1,
sizeof(utf8buf));
5944 len = str->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen,
5945 String::NO_NULL_TERMINATION);
5950 CHECK_EQ(0, strcmp(utf8buf,
"abcde"));
5952 memset(buf, 0x1,
sizeof(buf));
5953 len = str3->WriteAscii(buf);
5955 CHECK_EQ(0, strcmp(
"abc def", buf));
5957 memset(buf, 0x1,
sizeof(buf));
5958 len = str3->WriteAscii(buf, 0, -1, String::PRESERVE_ASCII_NULL);
5962 CHECK_EQ(0, strcmp(
"def", buf + 4));
5966 static void Utf16Helper(
5969 const char* lengths_name,
5971 Local<v8::Array> a =
5972 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
5973 Local<v8::Array> alens =
5974 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
5975 for (
int i = 0; i < len; i++) {
5976 Local<v8::String>
string =
5977 Local<v8::String>::Cast(a->Get(i));
5978 Local<v8::Number> expected_len =
5979 Local<v8::Number>::Cast(alens->Get(i));
5980 CHECK_EQ(expected_len->Value() !=
string->Length(),
5981 string->MayContainNonAscii());
5983 CHECK_EQ(static_cast<int>(expected_len->Value()), length);
5988 static uint16_t StringGet(Handle<String> str,
int index) {
5990 v8::Utils::OpenHandle(String::Cast(*str));
5991 return istring->Get(index);
5995 static void WriteUtf8Helper(
5998 const char* lengths_name,
6000 Local<v8::Array> b =
6001 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
6002 Local<v8::Array> alens =
6003 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
6006 for (
int i = 0; i < len; i++) {
6007 Local<v8::String>
string =
6008 Local<v8::String>::Cast(b->Get(i));
6009 Local<v8::Number> expected_len =
6010 Local<v8::Number>::Cast(alens->Get(i));
6011 int utf8_length =
static_cast<int>(expected_len->Value());
6012 for (
int j = utf8_length + 1; j >= 0; j--) {
6013 memset(reinterpret_cast<void*>(&buffer), 42,
sizeof(buffer));
6014 memset(reinterpret_cast<void*>(&buffer2), 42,
sizeof(buffer2));
6017 string->WriteUtf8(buffer, j, &nchars, String::NO_OPTIONS);
6019 string->WriteUtf8(buffer2, j, &nchars, String::NO_NULL_TERMINATION);
6020 CHECK_GE(utf8_length + 1, utf8_written);
6021 CHECK_GE(utf8_length, utf8_written2);
6022 for (
int k = 0; k < utf8_written2; k++) {
6025 CHECK(nchars * 3 >= utf8_written - 1);
6026 CHECK(nchars <= utf8_written);
6027 if (j == utf8_length + 1) {
6028 CHECK_EQ(utf8_written2, utf8_length);
6029 CHECK_EQ(utf8_written2 + 1, utf8_written);
6031 CHECK_EQ(buffer[utf8_written], 42);
6032 if (j > utf8_length) {
6033 if (utf8_written != 0)
CHECK_EQ(buffer[utf8_written - 1], 0);
6034 if (utf8_written > 1)
CHECK_NE(buffer[utf8_written - 2], 42);
6035 Handle<String> roundtrip = v8_str(buffer);
6036 CHECK(roundtrip->Equals(
string));
6038 if (utf8_written != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
6040 if (utf8_written2 != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
6042 uint16_t trail = StringGet(
string, nchars - 1);
6043 uint16_t lead = StringGet(
string, nchars - 2);
6044 if (((lead & 0xfc00) == 0xd800) &&
6045 ((trail & 0xfc00) == 0xdc00)) {
6046 unsigned char u1 = buffer2[utf8_written2 - 4];
6047 unsigned char u2 = buffer2[utf8_written2 - 3];
6048 unsigned char u3 = buffer2[utf8_written2 - 2];
6049 unsigned char u4 = buffer2[utf8_written2 - 1];
6054 uint32_t c = 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
6056 CHECK_EQ((u3 & 0x3f), ((c >> 6) & 0x3f));
6057 CHECK_EQ((u2 & 0x3f), ((c >> 12) & 0x3f));
6070 "var pad = '01234567890123456789';"
6072 "var plens = [20, 3, 3];"
6073 "p.push('01234567890123456789');"
6074 "var lead = 0xd800;"
6075 "var trail = 0xdc00;"
6076 "p.push(String.fromCharCode(0xd800));"
6077 "p.push(String.fromCharCode(0xdc00));"
6082 "for (var i = 0; i < 3; i++) {"
6083 " p[1] = String.fromCharCode(lead++);"
6084 " for (var j = 0; j < 3; j++) {"
6085 " p[2] = String.fromCharCode(trail++);"
6086 " a.push(p[i] + p[j]);"
6087 " b.push(p[i] + p[j]);"
6088 " c.push(p[i] + p[j]);"
6089 " alens.push(plens[i] + plens[j]);"
6097 "for (var m = 0; m < 9; m++) {"
6098 " for (var n = 0; n < 9; n++) {"
6099 " a2.push(a[m] + a[n]);"
6100 " b2.push(b[m] + b[n]);"
6101 " var newc = 'x' + c[m] + c[n] + 'y';"
6102 " c2.push(newc.substring(1, newc.length - 1));"
6103 " var utf = alens[m] + alens[n];"
6106 " if ((m % 3) == 1 && n >= 6) utf -= 2;"
6107 " a2lens.push(utf);"
6110 Utf16Helper(context,
"a",
"alens", 9);
6111 Utf16Helper(context,
"a2",
"a2lens", 81);
6112 WriteUtf8Helper(context,
"b",
"alens", 9);
6113 WriteUtf8Helper(context,
"b2",
"a2lens", 81);
6114 WriteUtf8Helper(context,
"c2",
"a2lens", 81);
6118 static bool SameSymbol(Handle<String>
s1, Handle<String>
s2) {
6121 return *is1 == *is2;
6125 static void SameSymbolHelper(
const char* a,
const char* b) {
6128 CHECK(SameSymbol(symbol1, symbol2));
6138 CHECK(SameSymbol(symbol1, symbol2));
6140 SameSymbolHelper(
"\360\220\220\205",
6141 "\355\240\201\355\260\205");
6142 SameSymbolHelper(
"\355\240\201\355\260\206",
6143 "\360\220\220\206");
6144 SameSymbolHelper(
"x\360\220\220\205",
6145 "x\355\240\201\355\260\205");
6146 SameSymbolHelper(
"x\355\240\201\355\260\206",
6147 "x\360\220\220\206");
6149 "var sym0 = 'benedictus';"
6150 "var sym0b = 'S\303\270ren';"
6151 "var sym1 = '\355\240\201\355\260\207';"
6152 "var sym2 = '\360\220\220\210';"
6153 "var sym3 = 'x\355\240\201\355\260\207';"
6154 "var sym4 = 'x\360\220\220\210';"
6155 "if (sym1.length != 2) throw sym1;"
6156 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
6157 "if (sym2.length != 2) throw sym2;"
6158 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);"
6159 "if (sym3.length != 3) throw sym3;"
6160 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);"
6161 "if (sym4.length != 3) throw sym4;"
6162 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);");
6170 Local<Value>
s0 = global->
Get(v8_str(
"sym0"));
6171 Local<Value> s0b = global->
Get(v8_str(
"sym0b"));
6172 Local<Value> s1 = global->
Get(v8_str(
"sym1"));
6173 Local<Value> s2 = global->
Get(v8_str(
"sym2"));
6174 Local<Value>
s3 = global->
Get(v8_str(
"sym3"));
6175 Local<Value>
s4 = global->
Get(v8_str(
"sym4"));
6176 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0))));
6177 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b))));
6178 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1))));
6179 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2))));
6180 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3))));
6181 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4))));
6193 str = v8_str(
"42asdf");
6196 str = v8_str(
"-42");
6199 str = v8_str(
"4294967295");
6226 CHECK(reference_error->IsObject());
6229 CHECK(syntax_error->IsObject());
6232 CHECK(type_error->IsObject());
6235 CHECK(error->IsObject());
6240 static v8::Handle<Value> YGetter(Local<String> name,
const AccessorInfo& info) {
6246 static void YSetter(Local<String> name,
6248 const AccessorInfo& info) {
6249 if (info.This()->Has(name)) {
6250 info.This()->Delete(name);
6252 info.This()->Set(name, value);
6262 context->
Global()->Set(v8_str(
"holder"), holder);
6264 "holder.y = 11; holder.y = 12; holder.y");
6281 for (
int i = 0; i < 10; i++) {
6295 static bool g_security_callback_result =
false;
6296 static bool NamedSecurityTestCallback(Local<v8::Object> global,
6299 Local<Value> data) {
6305 return g_security_callback_result;
6309 static bool IndexedSecurityTestCallback(Local<v8::Object> global,
6312 Local<Value> data) {
6318 return g_security_callback_result;
6322 static int trouble_nesting = 0;
6328 Local<v8::Object> arg_this = Context::GetCurrent()->Global();
6329 Local<Value> trouble_callee = (trouble_nesting == 3) ?
6330 arg_this->Get(v8_str(
"trouble_callee")) :
6331 arg_this->Get(v8_str(
"trouble_caller"));
6332 CHECK(trouble_callee->IsFunction());
6333 return Function::Cast(*trouble_callee)->Call(arg_this, 0,
NULL);
6337 static int report_count = 0;
6354 global->
Set(v8_str(
"trouble"), fun->GetFunction());
6356 Script::Compile(v8_str(
"function trouble_callee() {"
6360 "function trouble_caller() {"
6363 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
6364 CHECK(trouble->IsFunction());
6365 Local<Value> trouble_callee = global->
Get(v8_str(
"trouble_callee"));
6366 CHECK(trouble_callee->IsFunction());
6367 Local<Value> trouble_caller = global->
Get(v8_str(
"trouble_caller"));
6368 CHECK(trouble_caller->IsFunction());
6369 Function::Cast(*trouble_caller)->Call(global, 0,
NULL);
6374 static const char* script_resource_name =
"ExceptionInNativeScript.js";
6380 CHECK_EQ(script_resource_name, *name);
6383 CHECK_EQ(
" new o.foo();", *source_line);
6393 global->
Set(v8_str(
"trouble"), fun->GetFunction());
6395 Script::Compile(v8_str(
"function trouble() {\n"
6399 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
6400 CHECK(trouble->IsFunction());
6401 Function::Cast(*trouble)->Call(global, 0,
NULL);
6406 TEST(CompilationErrorUsingTryCatchHandler) {
6410 Script::Compile(v8_str(
"This doesn't &*&@#$&*^ compile."));
6416 TEST(TryCatchFinallyUsingTryCatchHandler) {
6420 Script::Compile(v8_str(
"try { throw ''; } catch (e) {}"))->Run();
6422 Script::Compile(v8_str(
"try { throw ''; } finally {}"))->Run();
6425 Script::Compile(v8_str(
"(function() {"
6426 "try { throw ''; } finally { return; }"
6429 Script::Compile(v8_str(
"(function()"
6430 " { try { throw ''; } finally { throw 0; }"
6441 IndexedSecurityTestCallback);
6444 Context::New(
NULL, global_template);
6450 global0->
Set(v8_str(
"0"), v8_num(999));
6460 Context::New(
NULL, global_template);
6464 global1->
Set(v8_str(
"othercontext"), global0);
6467 v8_compile(
"othercontext.foo = 222; othercontext[0] = 888;");
6477 { g_security_callback_result =
true;
6481 global2->
Set(v8_str(
"othercontext"), global0);
6483 v8_compile(
"othercontext.foo = 333; othercontext[0] = 888;");
6504 Local<Value>
foo = v8_str(
"foo");
6505 Local<Value>
bar = v8_str(
"bar");
6511 Script::Compile(v8_str(
"spy=function(){return spy;}"))->Run();
6512 Local<Value> spy = env1->
Global()->Get(v8_str(
"spy"));
6513 CHECK(spy->IsFunction());
6516 Script::Compile(v8_str(
"spy2=function(){return new this.Array();}"))->Run();
6517 Local<Value> spy2 = env1->
Global()->Get(v8_str(
"spy2"));
6518 CHECK(spy2->IsFunction());
6522 env2->SetSecurityToken(foo);
6524 Context::Scope scope_env2(env2);
6525 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0,
NULL);
6526 CHECK(result->IsFunction());
6530 env2->SetSecurityToken(bar);
6531 Context::Scope scope_env2(env2);
6535 Function::Cast(*spy2)->Call(env2->Global(), 0,
NULL);
6552 { Context::Scope scope(other);
6553 other_object = other->Global()->Get(v8_str(
"Object"));
6554 other->Global()->Set(v8_num(42), v8_num(87));
6557 current->
Global()->Set(v8_str(
"other"), other->Global());
6558 CHECK(v8_compile(
"other")->Run()->Equals(other->Global()));
6565 for (
int i = 0; i < 5; i++) {
6566 CHECK(!access_other0->Run()->Equals(other_object));
6567 CHECK(access_other0->Run()->IsUndefined());
6568 CHECK(!access_other1->Run()->Equals(v8_num(87)));
6569 CHECK(access_other1->Run()->IsUndefined());
6575 v8_compile(
"function F() { };"
6576 "F.prototype = other;"
6577 "var f = new F();")->Run();
6580 for (
int j = 0; j < 5; j++) {
6581 CHECK(!access_f0->Run()->Equals(other_object));
6582 CHECK(access_f0->Run()->IsUndefined());
6583 CHECK(!access_f1->Run()->Equals(v8_num(87)));
6584 CHECK(access_f1->Run()->IsUndefined());
6590 { Context::Scope scope(other);
6591 other->Global()->Set(v8_str(
"__proto__"), current->
Global());
6596 current->
Global()->Set(v8_str(
"foo"), v8_num(100));
6597 current->
Global()->Set(v8_num(99), v8_num(101));
6600 Local<Script> access_f2 = v8_compile(
"f.foo");
6601 Local<Script> access_f3 = v8_compile(
"f[99]");
6602 for (
int k = 0; k < 5; k++) {
6603 CHECK(!access_f2->Run()->Equals(v8_num(100)));
6604 CHECK(access_f2->Run()->IsUndefined());
6605 CHECK(!access_f3->Run()->Equals(v8_num(101)));
6606 CHECK(access_f3->Run()->IsUndefined());
6617 Local<Value>
foo = v8_str(
"foo");
6618 Local<Value>
bar = v8_str(
"bar");
6622 env2->SetSecurityToken(foo);
6624 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6625 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6628 env2->SetSecurityToken(bar);
6630 Context::Scope scope_env2(env2);
6631 Local<Value> result =
6632 Script::Compile(v8_str(
"delete env1.prop"))->Run();
6633 CHECK(result->IsFalse());
6637 Local<Value> v = env1->
Global()->Get(v8_str(
"prop"));
6638 CHECK(v->IsNumber());
6650 Local<Value>
foo = v8_str(
"foo");
6651 Local<Value>
bar = v8_str(
"bar");
6655 env2->SetSecurityToken(foo);
6657 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6658 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6661 Local<String> test = v8_str(
"propertyIsEnumerable.call(env1, 'prop')");
6663 Context::Scope scope_env2(env2);
6664 Local<Value> result = Script::Compile(test)->Run();
6665 CHECK(result->IsTrue());
6669 env2->SetSecurityToken(bar);
6671 Context::Scope scope_env2(env2);
6672 Local<Value> result = Script::Compile(test)->Run();
6673 CHECK(result->IsFalse());
6685 Local<Value>
foo = v8_str(
"foo");
6686 Local<Value>
bar = v8_str(
"bar");
6690 env2->SetSecurityToken(foo);
6692 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
6693 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
6699 env2->SetSecurityToken(bar);
6701 Context::Scope scope_env2(env2);
6702 Local<Value> result =
6703 CompileRun(
"(function(){var obj = {'__proto__':env1};"
6704 "for (var p in obj)"
6705 " if (p == 'prop') return false;"
6706 "return true;})()");
6707 CHECK(result->IsTrue());
6718 Local<v8::Object> global1 = env1->
Global();
6720 Local<Value>
foo = v8_str(
"foo");
6724 env2->SetSecurityToken(foo);
6730 Local<v8::Object> global2 = env2->Global();
6732 CompileRun(
"function getProp() {return prop;}");
6734 env1->
Global()->Set(v8_str(
"getProp"),
6735 global2->Get(v8_str(
"getProp")));
6739 env2->DetachGlobal();
6741 CHECK(!env2->Global()->Equals(global2));
6745 env3->SetSecurityToken(v8_str(
"bar"));
6748 Local<v8::Object> global3 = env3->Global();
6750 CHECK(global3->Get(v8_str(
"prop"))->IsUndefined());
6751 CHECK(global3->Get(v8_str(
"getProp"))->IsUndefined());
6758 Local<Value> get_prop = global1->Get(v8_str(
"getProp"));
6759 CHECK(get_prop->IsFunction());
6761 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0,
NULL);
6762 CHECK(!try_catch.HasCaught());
6768 Local<Value> r = global3->Get(v8_str(
"prop2"));
6769 CHECK(r->IsUndefined());
6784 Local<Value>
foo = v8_str(
"foo");
6788 env2->SetSecurityToken(foo);
6797 env1->
Global()->Set(v8_str(
"other"), env2->Global());
6800 Local<Value> result = CompileRun(
"other.p");
6801 CHECK(result->IsInt32());
6802 CHECK_EQ(42, result->Int32Value());
6805 Local<v8::Object> global2 = env2->Global();
6806 env2->DetachGlobal();
6810 result = CompileRun(
"other.p");
6811 CHECK(result->IsUndefined());
6819 env3->SetSecurityToken(foo);
6828 result = CompileRun(
"other.p");
6829 CHECK(result->IsInt32());
6830 CHECK_EQ(24, result->Int32Value());
6833 env3->SetSecurityToken(v8_str(
"bar"));
6838 result = CompileRun(
"other.p");
6839 CHECK(result->IsUndefined());
6842 env3->DetachGlobal();
6843 env2->ReattachGlobal(global2);
6847 result = CompileRun(
"other.p");
6848 CHECK(result->IsInt32());
6849 CHECK_EQ(42, result->Int32Value());
6857 static bool NamedAccessBlocker(Local<v8::Object> global,
6860 Local<Value> data) {
6861 return Context::GetCurrent()->Global()->Equals(global) ||
6862 allowed_access_type[type];
6866 static bool IndexedAccessBlocker(Local<v8::Object> global,
6869 Local<Value> data) {
6870 return Context::GetCurrent()->Global()->Equals(global) ||
6871 allowed_access_type[type];
6875 static int g_echo_value = -1;
6877 const AccessorInfo& info) {
6878 return v8_num(g_echo_value);
6882 static void EchoSetter(Local<String> name,
6884 const AccessorInfo&) {
6885 if (value->IsNumber())
6886 g_echo_value = value->Int32Value();
6891 const AccessorInfo& info) {
6897 static void UnreachableSetter(Local<String>, Local<Value>,
6898 const AccessorInfo&) {
6908 IndexedAccessBlocker);
6912 v8_str(
"accessible_prop"),
6913 EchoGetter, EchoSetter,
6918 global_template->
SetAccessor(v8_str(
"blocked_prop"),
6919 UnreachableGetter, UnreachableSetter,
6931 "function getter() { return 'getter'; };\n"
6932 "function setter() { return 'setter'; }\n"
6933 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
6935 Local<Value> getter = global0->
Get(v8_str(
"getter"));
6936 Local<Value> setter = global0->
Get(v8_str(
"setter"));
6939 global0->
Set(239, v8_str(
"239"));
6943 "function el_getter() { return 'el_getter'; };\n"
6944 "function el_setter() { return 'el_setter'; };\n"
6945 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
6947 Local<Value> el_getter = global0->
Get(v8_str(
"el_getter"));
6948 Local<Value> el_setter = global0->
Get(v8_str(
"el_setter"));
6956 global1->
Set(v8_str(
"other"), global0);
6959 CompileRun(
"other.blocked_prop = 1");
6961 ExpectUndefined(
"other.blocked_prop");
6963 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
6964 ExpectFalse(
"propertyIsEnumerable.call(other, 'blocked_prop')");
6968 ExpectUndefined(
"other.blocked_prop");
6971 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
6973 ExpectTrue(
"propertyIsEnumerable.call(other, 'blocked_prop')");
6977 CompileRun(
"other[239] = 1");
6979 ExpectUndefined(
"other[239]");
6980 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239')");
6981 ExpectFalse(
"propertyIsEnumerable.call(other, '239')");
6985 ExpectUndefined(
"other[239]");
6987 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239').value");
6989 ExpectTrue(
"propertyIsEnumerable.call(other, '239')");
6993 CompileRun(
"other.js_accessor_p = 2");
6995 ExpectUndefined(
"other.js_accessor_p");
6997 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
7001 ExpectUndefined(
"other.js_accessor_p");
7003 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
7005 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
7007 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
7014 ExpectString(
"other.js_accessor_p",
"getter");
7016 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
7018 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
7020 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
7029 ExpectUndefined(
"other.js_accessor_p");
7031 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
7033 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
7035 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
7045 ExpectString(
"other.js_accessor_p",
"getter");
7047 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
7049 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
7051 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
7058 CompileRun(
"other[42] = 2");
7060 ExpectUndefined(
"other[42]");
7061 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42')");
7065 ExpectUndefined(
"other[42]");
7066 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
7067 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
7068 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
7075 ExpectString(
"other[42]",
"el_getter");
7076 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
7077 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
7078 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
7087 ExpectUndefined(
"other[42]");
7088 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
7089 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
7090 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
7100 ExpectString(
"other[42]",
"el_getter");
7101 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
7102 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
7103 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
7112 value = CompileRun(
"other.accessible_prop = 3");
7117 value = CompileRun(
"other.accessible_prop");
7122 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
7123 CHECK(value->IsNumber());
7126 value = CompileRun(
"propertyIsEnumerable.call(other, 'accessible_prop')");
7127 CHECK(value->IsTrue());
7132 CompileRun(
"(function(){var obj = {'__proto__':other};"
7133 "for (var p in obj)"
7134 " if (p == 'accessible_prop' || p == 'blocked_prop') {"
7137 "return true;})()");
7138 CHECK(value->IsTrue());
7152 IndexedAccessBlocker);
7156 v8_str(
"accessible_prop"),
7157 EchoGetter, EchoSetter,
7163 global_template->
SetAccessor(v8_str(
"blocked_prop"),
7164 UnreachableGetter, UnreachableSetter,
7177 global1->
Set(v8_str(
"other"), global0);
7180 ExpectTrue(
"Object.keys(other).indexOf('blocked_prop') == -1");
7182 ExpectUndefined(
"other.blocked_prop");
7185 CompileRun(
"Object.defineProperty(\n"
7186 " other, 'blocked_prop', {configurable: false})");
7187 ExpectUndefined(
"other.blocked_prop");
7189 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
7192 ExpectTrue(
"Object.isExtensible(other)");
7193 CompileRun(
"Object.preventExtensions(other)");
7194 ExpectTrue(
"Object.isExtensible(other)");
7197 CompileRun(
"Object.freeze(other)");
7198 ExpectTrue(
"Object.isExtensible(other)");
7200 CompileRun(
"Object.seal(other)");
7201 ExpectTrue(
"Object.isExtensible(other)");
7206 CompileRun(
"other.accessible_prop = 42");
7211 CompileRun(
"Object.defineProperty(other, 'accessible_prop', {value: -1})");
7212 value = CompileRun(
"other.accessible_prop == 42");
7217 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
7220 Local<Value> data) {
7225 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
7228 Local<Value> data) {
7239 GetOwnPropertyNamesIndexedBlocker);
7253 global1->
Set(v8_str(
"other"), global0);
7263 value = CompileRun(
"Object.getOwnPropertyNames(other).length == 0");
7266 value = CompileRun(
"Object.getOwnPropertyNames(object).length == 0");
7267 CHECK(value->IsTrue());
7278 result->
Set(0, v8_str(
"x"));
7289 NamedPropertyEnumerator);
7296 CompileRun(
"Object.getOwnPropertyNames(object).join(',')");
7302 const AccessorInfo& info) {
7325 global_template->
SetAccessor(v8_str(
"unreachable"),
7326 UnreachableGetter, 0,
7333 Local<v8::Object> global = context0->Global();
7335 global->Set(v8_str(
"accessible"), v8_num(11));
7343 global1->
Set(v8_str(
"other"), global);
7350 value = v8_compile(
"other.unreachable")->Run();
7351 CHECK(value->IsUndefined());
7360 static int named_access_count = 0;
7361 static int indexed_access_count = 0;
7363 static bool NamedAccessCounter(Local<v8::Object> global,
7366 Local<Value> data) {
7367 named_access_count++;
7372 static bool IndexedAccessCounter(Local<v8::Object> global,
7375 Local<Value> data) {
7376 indexed_access_count++;
7383 named_access_count = 0;
7384 indexed_access_count = 0;
7396 IndexedAccessCounter);
7397 Local<v8::Object>
object = object_template->
NewInstance();
7407 global1->
Set(v8_str(
"obj"),
object);
7412 CompileRun(
"function testProp(obj) {"
7413 " for (var i = 0; i < 10; i++) obj.prop = 1;"
7414 " for (var j = 0; j < 10; j++) obj.prop;"
7417 value = CompileRun(
"testProp(obj)");
7423 CompileRun(
"var p = 'prop';"
7424 "function testKeyed(obj) {"
7425 " for (var i = 0; i < 10; i++) obj[p] = 1;"
7426 " for (var j = 0; j < 10; j++) obj[p];"
7431 value = CompileRun(
"testKeyed(obj)");
7436 CompileRun(
"testKeyed({ a: 0 })");
7437 CompileRun(
"testKeyed({ b: 0 })");
7438 value = CompileRun(
"testKeyed(obj)");
7444 CompileRun(
"function testIndexed(obj) {"
7445 " for (var i = 0; i < 10; i++) obj[0] = 1;"
7446 " for (var j = 0; j < 10; j++) obj[0];"
7449 value = CompileRun(
"testIndexed(obj)");
7452 CHECK_EQ(21, indexed_access_count);
7454 CompileRun(
"testIndexed(new Array(1))");
7456 value = CompileRun(
"testIndexed(obj)");
7459 CHECK_EQ(42, indexed_access_count);
7463 CompileRun(
"obj.f = function() {}");
7464 CompileRun(
"function testCallNormal(obj) {"
7465 " for (var i = 0; i < 10; i++) obj.f();"
7467 CompileRun(
"testCallNormal(obj)");
7471 value = CompileRun(
"delete obj.prop");
7474 CompileRun(
"var o = { x: 0 }; delete o.x; testProp(o);");
7476 value = CompileRun(
"testProp(obj);");
7482 CompileRun(
"o.f = function() {}; testCallNormal(o)");
7485 value = CompileRun(
"testCallNormal(obj)");
7495 static bool NamedAccessFlatten(Local<v8::Object> global,
7498 Local<Value> data) {
7502 CHECK(name->IsString());
7504 memset(buf, 0x1,
sizeof(buf));
7505 len = name.As<String>()->WriteAscii(buf);
7510 memset(buf, 0x1,
sizeof(buf));
7511 len = name.As<String>()->Write(buf2);
7518 static bool IndexedAccessFlatten(Local<v8::Object> global,
7521 Local<Value> data) {
7532 named_access_count = 0;
7533 indexed_access_count = 0;
7545 IndexedAccessFlatten);
7546 Local<v8::Object>
object = object_template->
NewInstance();
7556 global1->
Set(v8_str(
"obj"),
object);
7560 value = v8_compile(
"var p = 'as' + 'df';")->Run();
7561 value = v8_compile(
"obj[p];")->Run();
7571 Local<String>,
const AccessorInfo&) {
7577 Local<String>, Local<Value> value,
const AccessorInfo&) {
7584 const AccessorInfo& info) {
7590 uint32_t, Local<Value> value,
const AccessorInfo&) {
7596 named_access_count = 0;
7597 indexed_access_count = 0;
7610 IndexedAccessCounter);
7612 AccessControlNamedSetter);
7614 AccessControlIndexedSetter);
7615 Local<v8::Object>
object = object_template->
NewInstance();
7625 global1->
Set(v8_str(
"obj"),
object);
7631 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x = 1;")->Run();
7632 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x;"
7638 value = v8_compile(
"var p = 'x';")->Run();
7639 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p] = 1;")->Run();
7640 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p];"
7648 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0] = 1;")->Run();
7649 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0];"
7653 CHECK_EQ(21, indexed_access_count);
7678 Local<ObjectTemplate> instance = t->InstanceTemplate();
7680 instance->Set(v8_str(
"x"), v8_num(42));
7681 instance->Set(v8_str(
"f"),
7684 Local<Value> o = t->GetFunction()->NewInstance();
7686 context->
Global()->Set(v8_str(
"i"), o);
7687 Local<Value> value = Script::Compile(v8_str(
"i.x"))->Run();
7690 value = Script::Compile(v8_str(
"i.f()"))->Run();
7696 GlobalObjectInstancePropertiesGet(Local<String> key,
const AccessorInfo&) {
7705 Local<Value> global_object;
7708 t->InstanceTemplate()->SetNamedPropertyHandler(
7709 GlobalObjectInstancePropertiesGet);
7711 instance_template->Set(v8_str(
"x"), v8_num(42));
7712 instance_template->Set(v8_str(
"f"),
7717 const char* script =
7718 "function wrapper(call) {"
7719 " var x = 0, y = 1;"
7720 " for (var i = 0; i < 1000; i++) {"
7726 "for (var i = 0; i < 17; i++) wrapper(false);"
7728 "try { wrapper(true); } catch (e) { thrown = 1; };"
7735 global_object = env->
Global();
7737 Local<Value> value = Script::Compile(v8_str(
"x"))->Run();
7739 value = Script::Compile(v8_str(
"f()"))->Run();
7741 value = Script::Compile(v8_str(script))->Run();
7748 Local<Value> value = Script::Compile(v8_str(
"x"))->Run();
7750 value = Script::Compile(v8_str(
"f()"))->Run();
7752 value = Script::Compile(v8_str(script))->Run();
7761 Local<Value> global_object;
7772 const char* script =
7773 "function bar(x, y) { try { } finally { } }"
7774 "function baz(x) { try { } finally { } }"
7775 "function bom(x) { try { } finally { } }"
7776 "function foo(x) { bar([x], bom(2)); }"
7777 "for (var i = 0; i < 10000; i++) foo(1);"
7785 global_object = env->
Global();
7786 foo = Script::Compile(v8_str(script))->Run();
7792 env->
Global()->Set(v8_str(
"foo"), foo);
7793 Script::Compile(v8_str(
"foo()"))->Run();
7804 static int shadow_y;
7805 static int shadow_y_setter_call_count;
7806 static int shadow_y_getter_call_count;
7809 static void ShadowYSetter(Local<String>, Local<Value>,
const AccessorInfo&) {
7810 shadow_y_setter_call_count++;
7816 const AccessorInfo& info) {
7818 shadow_y_getter_call_count++;
7819 return v8_num(shadow_y);
7824 const AccessorInfo& info) {
7830 const AccessorInfo&) {
7836 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
7843 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
7844 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
7845 Local<ObjectTemplate> proto = t->PrototypeTemplate();
7846 Local<ObjectTemplate> instance = t->InstanceTemplate();
7850 proto->Set(v8_str(
"f"),
7854 proto->Set(v8_str(
"x"), v8_num(12));
7856 instance->SetAccessor(v8_str(
"y"), ShadowYGetter, ShadowYSetter);
7858 Local<Value> o = t->GetFunction()->NewInstance();
7859 context->
Global()->Set(v8_str(
"__proto__"), o);
7861 Local<Value> value =
7862 Script::Compile(v8_str(
"this.propertyIsEnumerable(0)"))->Run();
7863 CHECK(value->IsBoolean());
7864 CHECK(!value->BooleanValue());
7866 value = Script::Compile(v8_str(
"x"))->Run();
7869 value = Script::Compile(v8_str(
"f()"))->Run();
7872 Script::Compile(v8_str(
"y = 43"))->Run();
7873 CHECK_EQ(1, shadow_y_setter_call_count);
7874 value = Script::Compile(v8_str(
"y"))->Run();
7875 CHECK_EQ(1, shadow_y_getter_call_count);
7885 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
7887 t1->SetHiddenPrototype(
true);
7888 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
7890 t2->SetHiddenPrototype(
true);
7891 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
7893 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
7895 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
7896 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
7897 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
7898 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
7901 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7902 o0->Set(v8_str(
"__proto__"), o1);
7903 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7904 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7905 o0->Set(v8_str(
"__proto__"), o2);
7906 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7907 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7908 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7909 o0->Set(v8_str(
"__proto__"), o3);
7910 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7911 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7912 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7913 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
7918 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
7919 CHECK(proto->IsObject());
7929 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
7931 t1->SetHiddenPrototype(
true);
7932 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
7934 t2->SetHiddenPrototype(
true);
7935 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
7937 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
7939 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
7940 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
7941 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
7942 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
7945 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7946 CHECK(o0->SetPrototype(o1));
7947 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7948 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7949 CHECK(o1->SetPrototype(o2));
7950 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7951 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7952 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7953 CHECK(o2->SetPrototype(o3));
7954 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
7955 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
7956 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
7957 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
7962 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
7963 CHECK(proto->IsObject());
7967 Local<Value> proto0 = o0->GetPrototype();
7968 CHECK(proto0->IsObject());
7971 Local<Value> proto1 = o1->GetPrototype();
7972 CHECK(proto1->IsObject());
7975 Local<Value> proto2 = o2->GetPrototype();
7976 CHECK(proto2->IsObject());
7985 i::FLAG_allow_natives_syntax =
true;
7990 t1->SetHiddenPrototype(
true);
7991 t1->InstanceTemplate()->Set(v8_str(
"foo"), v8_num(1));
7993 t2->SetHiddenPrototype(
true);
7994 t2->InstanceTemplate()->Set(v8_str(
"fuz1"), v8_num(2));
7996 t2->InstanceTemplate()->Set(v8_str(
"fuz2"), v8_num(2));
7998 t3->SetHiddenPrototype(
true);
7999 t3->InstanceTemplate()->Set(v8_str(
"boo"), v8_num(3));
8001 t4->InstanceTemplate()->Set(v8_str(
"baz"), v8_num(4));
8005 for (
int i = 1; i <= 1000; i++) {
8007 t2->InstanceTemplate()->Set(v8_str(name_buf.
start()), v8_num(2));
8010 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
8011 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
8012 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
8013 Local<v8::Object> o4 = t4->GetFunction()->NewInstance();
8016 CHECK(o4->SetPrototype(o3));
8017 CHECK(o3->SetPrototype(o2));
8018 CHECK(o2->SetPrototype(o1));
8022 context->
Global()->Set(v8_str(
"obj"), o4);
8023 CompileRun(
"var names = %GetLocalPropertyNames(obj);");
8025 ExpectInt32(
"names.length", 1006);
8026 ExpectTrue(
"names.indexOf(\"baz\") >= 0");
8027 ExpectTrue(
"names.indexOf(\"boo\") >= 0");
8028 ExpectTrue(
"names.indexOf(\"foo\") >= 0");
8029 ExpectTrue(
"names.indexOf(\"fuz1\") >= 0");
8030 ExpectTrue(
"names.indexOf(\"fuz2\") >= 0");
8031 ExpectFalse(
"names[1005] == undefined");
8041 t1->ReadOnlyPrototype();
8042 context->
Global()->Set(v8_str(
"func1"), t1->GetFunction());
8046 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
8047 " return (descriptor['writable'] == false);"
8048 "})()")->BooleanValue());
8049 CHECK_EQ(42, CompileRun(
"func1.prototype.x")->Int32Value());
8051 CompileRun(
"func1.prototype = {}; func1.prototype.x")->Int32Value());
8055 context->
Global()->Set(v8_str(
"func2"), t2->GetFunction());
8059 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
8060 " return (descriptor['writable'] == true);"
8061 "})()")->BooleanValue());
8062 CHECK_EQ(42, CompileRun(
"func2.prototype.x")->Int32Value());
8072 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
8073 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
8075 CHECK(o0->SetPrototype(o1));
8079 CHECK(!o1->SetPrototype(o0));
8080 CHECK(!try_catch.HasCaught());
8081 ASSERT(!i::Isolate::Current()->has_pending_exception());
8083 CHECK_EQ(42, CompileRun(
"function f() { return 42; }; f()")->Int32Value());
8091 "function Foo() { };"
8092 "function Throw() { throw 5; };"
8094 "x.__defineSetter__('set', Throw);"
8095 "x.__defineGetter__('get', Throw);");
8096 Local<v8::Object> x =
8097 Local<v8::Object>::Cast(context->
Global()->Get(v8_str(
"x")));
8100 x->Get(v8_str(
"get"));
8102 x->Get(v8_str(
"get"));
8104 x->Get(v8_str(
"get"));
8106 x->Get(v8_str(
"get"));
8114 templ->SetClassName(v8_str(
"Fun"));
8115 Local<Function> cons = templ->GetFunction();
8116 context->
Global()->Set(v8_str(
"Fun"), cons);
8117 Local<v8::Object> inst = cons->NewInstance();
8119 CHECK(obj->IsJSObject());
8120 Local<Value> value = CompileRun(
"(new Fun()).constructor === Fun");
8121 CHECK(value->BooleanValue());
8125 static Handle<Value> ConstructorCallback(
const Arguments& args) {
8129 if (args.IsConstructCall()) {
8130 Local<Object> Holder = args.Holder();
8131 This = Object::New();
8132 Local<Value> proto = Holder->GetPrototype();
8133 if (proto->IsObject()) {
8134 This->SetPrototype(proto);
8140 This->Set(v8_str(
"a"), args[0]);
8145 static Handle<Value> FakeConstructorCallback(
const Arguments& args) {
8156 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
8157 Local<Object> instance = instance_template->NewInstance();
8158 context->
Global()->Set(v8_str(
"obj"), instance);
8164 value = CompileRun(
"(function() { var o = new obj(28); return o.a; })()");
8166 CHECK(value->IsInt32());
8169 Local<Value> args1[] = { v8_num(28) };
8170 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1);
8171 CHECK(value_obj1->IsObject());
8173 value = object1->Get(v8_str(
"a"));
8174 CHECK(value->IsInt32());
8180 "(function() { var o = new obj('tipli'); return o.a; })()");
8182 CHECK(value->IsString());
8183 String::AsciiValue string_value1(value->ToString());
8186 Local<Value> args2[] = { v8_str(
"tipli") };
8187 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2);
8188 CHECK(value_obj2->IsObject());
8190 value = object2->Get(v8_str(
"a"));
8192 CHECK(value->IsString());
8193 String::AsciiValue string_value2(value->ToString());
8197 value = CompileRun(
"(function() { var o = new obj(true); return o.a; })()");
8199 CHECK(value->IsBoolean());
8200 CHECK_EQ(
true, value->BooleanValue());
8202 Handle<Value> args3[] = {
v8::True() };
8203 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3);
8204 CHECK(value_obj3->IsObject());
8206 value = object3->Get(v8_str(
"a"));
8208 CHECK(value->IsBoolean());
8209 CHECK_EQ(
true, value->BooleanValue());
8213 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4);
8214 CHECK(value_obj4->IsObject());
8216 value = object4->Get(v8_str(
"a"));
8218 CHECK(value->IsUndefined());
8221 Handle<Value> args5[] = {
v8::Null() };
8222 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5);
8223 CHECK(value_obj5->IsObject());
8225 value = object5->Get(v8_str(
"a"));
8227 CHECK(value->IsNull());
8232 Local<Object> instance = instance_template->NewInstance();
8233 context->
Global()->Set(v8_str(
"obj2"), instance);
8238 value = CompileRun(
"new obj2(28)");
8240 String::AsciiValue exception_value1(try_catch.
Exception());
8241 CHECK_EQ(
"TypeError: object is not a function", *exception_value1);
8244 Local<Value> args[] = { v8_num(29) };
8245 value = instance->CallAsConstructor(1, args);
8247 String::AsciiValue exception_value2(try_catch.
Exception());
8248 CHECK_EQ(
"TypeError: #<Object> is not a function", *exception_value2);
8254 instance_template->SetCallAsFunctionHandler(
ThrowValue);
8255 Local<Object> instance = instance_template->NewInstance();
8256 context->
Global()->Set(v8_str(
"obj3"), instance);
8261 value = CompileRun(
"new obj3(22)");
8263 String::AsciiValue exception_value1(try_catch.
Exception());
8267 Local<Value> args[] = { v8_num(23) };
8268 value = instance->CallAsConstructor(1, args);
8270 String::AsciiValue exception_value2(try_catch.
Exception());
8276 { Local<FunctionTemplate> function_template =
8277 FunctionTemplate::New(FakeConstructorCallback);
8278 Local<Function>
function = function_template->GetFunction();
8279 Local<Object> instance1 =
function;
8280 context->
Global()->Set(v8_str(
"obj4"), instance1);
8285 CHECK(instance1->IsObject());
8286 CHECK(instance1->IsFunction());
8288 value = CompileRun(
"new obj4(28)");
8290 CHECK(value->IsObject());
8292 Local<Value> args1[] = { v8_num(28) };
8293 value = instance1->CallAsConstructor(1, args1);
8295 CHECK(value->IsObject());
8298 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
8299 Local<Object> instance2 = instance_template->NewInstance();
8300 context->
Global()->Set(v8_str(
"obj5"), instance2);
8303 CHECK(instance2->IsObject());
8304 CHECK(!instance2->IsFunction());
8306 value = CompileRun(
"new obj5(28)");
8308 CHECK(!value->IsObject());
8310 Local<Value> args2[] = { v8_num(28) };
8311 value = instance2->CallAsConstructor(1, args2);
8313 CHECK(!value->IsObject());
8322 templ->SetClassName(v8_str(
"Fun"));
8323 Local<Function> cons = templ->GetFunction();
8324 context->
Global()->Set(v8_str(
"Fun"), cons);
8325 Local<Value> value = CompileRun(
8328 " (new Fun()).blah()"
8330 " var str = String(e);"
8331 " if (str.indexOf('TypeError') == -1) return 1;"
8332 " if (str.indexOf('[object Fun]') != -1) return 2;"
8333 " if (str.indexOf('#<Fun>') == -1) return 3;"
8348 Local<Script> script =
8349 Script::Compile(v8_str(
"function f(x) { "
8351 " with (x) { return eval('foo'); }"
8354 "result1 = f(new Object());"
8355 "result2 = f(this);"
8356 "var x = new Object();"
8357 "x.eval = function(x) { return 1; };"
8358 "result3 = f(x);"));
8360 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result1"))->Int32Value());
8361 CHECK_EQ(0, current->
Global()->Get(v8_str(
"result2"))->Int32Value());
8362 CHECK_EQ(1, current->
Global()->Get(v8_str(
"result3"))->Int32Value());
8366 Script::Compile(v8_str(
"function f(x) { "
8368 " with (x) { return eval('bar'); }"
8370 "result4 = f(this)"));
8372 CHECK(!try_catch.HasCaught());
8373 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result4"))->Int32Value());
8384 Local<String> token = v8_str(
"<security token>");
8389 current->
Global()->Set(v8_str(
"other"), other->
Global());
8392 Local<Script> script =
8393 Script::Compile(v8_str(
"other.eval('var foo = 1234')"));
8395 Local<Value>
foo = other->
Global()->Get(v8_str(
"foo"));
8402 Script::Compile(v8_str(
"other.eval('na = 1234')"));
8404 CHECK_EQ(1234, other->
Global()->Get(v8_str(
"na"))->Int32Value());
8411 Script::Compile(v8_str(
"var bar = 42; other.eval('bar');"));
8412 Local<Value> result = script->Run();
8413 CHECK(try_catch.HasCaught());
8419 Script::Compile(v8_str(
"(function() { "
8421 " return other.eval('baz');"
8423 result = script->Run();
8424 CHECK(try_catch.HasCaught());
8429 other->
Global()->Set(v8_str(
"bis"), v8_num(1234));
8430 script = Script::Compile(v8_str(
"other.eval('bis')"));
8431 CHECK_EQ(1234, script->Run()->Int32Value());
8432 CHECK(!try_catch.HasCaught());
8437 script = Script::Compile(v8_str(
"other.eval('this == t')"));
8438 result = script->Run();
8439 CHECK(result->IsTrue());
8440 CHECK(!try_catch.HasCaught());
8445 Script::Compile(v8_str(
"with({x:2}){other.eval('x')}"));
8446 result = script->Run();
8447 CHECK(try_catch.HasCaught());
8453 Script::Compile(v8_str(
"other.y = 1; eval.call(other, 'y')"));
8454 result = script->Run();
8455 CHECK(try_catch.HasCaught());
8471 CompileRun(
"var x = 42;"
8474 " return function(s) { return e(s); }"
8482 context1->Global()->Set(v8_str(
"fun"), fun);
8485 context0->DetachGlobal();
8487 x_value = CompileRun(
"fun('x')");
8502 Local<String> token = v8_str(
"<security token>");
8507 current->
Global()->Set(v8_str(
"other"), other->
Global());
8510 Local<Script> script =
8511 Script::Compile(v8_str(
"other.eval('new Date(42)')"));
8512 Local<Value> value = script->Run();
8513 CHECK_EQ(42.0, value->NumberValue());
8520 if (args[0]->IsInt32()) {
8521 return v8_num(-args[0]->Int32Value());
8538 instance_template->SetCallAsFunctionHandler(call_as_function);
8539 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8540 context->
Global()->Set(v8_str(
"obj"), instance);
8545 value = CompileRun(
"obj(42)");
8549 value = CompileRun(
"(function(o){return o(49)})(obj)");
8554 value = CompileRun(
"[obj]['0'](45)");
8558 value = CompileRun(
"obj.call = Function.prototype.call;"
8559 "obj.call(null, 87)");
8565 const char* apply_99 =
"Function.prototype.call.apply(obj, [this, 99])";
8566 value = CompileRun(apply_99);
8570 const char* call_17 =
"Function.prototype.call.call(obj, this, 17)";
8571 value = CompileRun(call_17);
8577 value = CompileRun(
"new obj(43)");
8579 CHECK_EQ(-43, value->Int32Value());
8584 value = instance->CallAsFunction(instance, 1, args);
8592 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8593 context->
Global()->Set(v8_str(
"obj2"), instance);
8599 value = CompileRun(
"obj2(28)");
8600 CHECK(value.IsEmpty());
8602 String::AsciiValue exception_value1(try_catch.
Exception());
8603 CHECK_EQ(
"TypeError: Property 'obj2' of object #<Object> is not a function",
8608 value = CompileRun(
"obj2(28)");
8610 value = instance->CallAsFunction(instance, 1, args);
8611 CHECK(value.IsEmpty());
8613 String::AsciiValue exception_value2(try_catch.
Exception());
8614 CHECK_EQ(
"TypeError: [object Object] is not a function", *exception_value2);
8620 instance_template->SetCallAsFunctionHandler(
ThrowValue);
8621 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8622 context->
Global()->Set(v8_str(
"obj3"), instance);
8628 value = CompileRun(
"obj3(22)");
8630 String::AsciiValue exception_value1(try_catch.
Exception());
8635 value = instance->CallAsFunction(instance, 1, args);
8637 String::AsciiValue exception_value2(try_catch.
Exception());
8650 instance_template->SetCallAsFunctionHandler(call_as_function);
8651 Local<Object> instance = instance_template->NewInstance();
8654 CHECK(instance->IsCallable());
8659 Local<Object> instance = instance_template->NewInstance();
8662 CHECK(!instance->IsCallable());
8666 { Local<FunctionTemplate> function_template =
8667 FunctionTemplate::New(call_as_function);
8668 Local<Function>
function = function_template->GetFunction();
8669 Local<Object> instance =
function;
8672 CHECK(instance->IsCallable());
8676 { Local<FunctionTemplate> function_template = FunctionTemplate::New();
8677 Local<Function>
function = function_template->GetFunction();
8678 Local<Object> instance =
function;
8681 CHECK(instance->IsCallable());
8687 static int CountHandles() {
8692 static int Recurse(
int depth,
int iterations) {
8694 if (depth == 0)
return CountHandles();
8695 for (
int i = 0; i < iterations; i++) {
8698 return Recurse(depth - 1, iterations);
8703 static const int kIterations = 500;
8704 static const int kNesting = 200;
8709 for (
int i = 0; i < kIterations; i++) {
8714 CHECK_EQ(kIterations, CountHandles());
8717 for (
int j = 0; j < kIterations; j++) {
8719 CHECK_EQ(j + 1 + kIterations, CountHandles());
8722 CHECK_EQ(kIterations, CountHandles());
8725 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
8731 const AccessorInfo& info) {
8741 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
8742 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
8743 Local<Function>
function = fun_templ->GetFunction();
8744 context->
Global()->Set(v8_str(
"constructor"),
function);
8746 "var o = new constructor();"
8747 "o.hasOwnProperty('ostehaps');");
8751 "o.hasOwnProperty('ostehaps');");
8752 CHECK_EQ(
true, value->BooleanValue());
8754 "var p = new constructor();"
8755 "p.hasOwnProperty('ostehaps');");
8756 CHECK_EQ(
false, value->BooleanValue());
8762 const AccessorInfo& info) {
8773 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
8774 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
8775 Local<Function>
function = fun_templ->GetFunction();
8776 context->
Global()->Set(v8_str(
"constructor"),
function);
8779 "function makestr(size) {"
8781 " case 1: return 'f';"
8782 " case 2: return 'fo';"
8783 " case 3: return 'foo';"
8785 " return makestr(size >> 1) + makestr((size + 1) >> 1);"
8787 "var x = makestr(12345);"
8788 "x = makestr(31415);"
8789 "x = makestr(23456);");
8791 "var o = new constructor();"
8792 "o.__proto__ = new String(x);"
8793 "o.hasOwnProperty('ostehaps');");
8799 const AccessorInfo& info);
8816 const AccessorInfo& info) {
8819 CHECK_EQ(isolate, info.GetIsolate());
8820 CHECK_EQ(v8_str(
"data"), info.Data());
8828 CheckInterceptorLoadIC(InterceptorLoadICGetter,
8830 "for (var i = 0; i < 1000; i++) {"
8842 const AccessorInfo& info) {
8844 return v8_str(
"x")->Equals(name)
8850 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8853 "for (var i = 0; i < 1000; i++) {"
8861 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8863 "o.__proto__ = { 'y': 239 };"
8864 "for (var i = 0; i < 1000; i++) {"
8865 " result = o.y + o.x;"
8872 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8874 "o.__proto__.y = 239;"
8875 "for (var i = 0; i < 1000; i++) {"
8876 " result = o.y + o.x;"
8883 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8885 "for (var i = 0; i < 1000; i++) {"
8886 " result = (o.y == undefined) ? 239 : 42;"
8893 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8894 "fst = new Object(); fst.__proto__ = o;"
8895 "snd = new Object(); snd.__proto__ = fst;"
8897 "for (var i = 0; i < 1000; i++) {"
8902 "for (var i = 0; i < 1000; i++) {"
8913 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8914 "proto = new Object();"
8915 "o.__proto__ = proto;"
8917 "for (var i = 0; i < 1000; i++) {"
8922 "for (var i = 0; i < 1000; i++) {"
8933 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8934 "proto1 = new Object();"
8935 "proto2 = new Object();"
8936 "o.__proto__ = proto1;"
8937 "proto1.__proto__ = proto2;"
8939 "for (var i = 0; i < 1000; i++) {"
8945 "for (var i = 0; i < 1000; i++) {"
8953 static int interceptor_load_not_handled_calls = 0;
8955 const AccessorInfo& info) {
8956 ++interceptor_load_not_handled_calls;
8964 interceptor_load_not_handled_calls = 0;
8965 CheckInterceptorLoadIC(InterceptorLoadNotHandled,
8966 "receiver = new Object();"
8967 "receiver.__proto__ = o;"
8968 "proto = new Object();"
8969 "/* Make proto a slow-case object. */"
8970 "for (var i = 0; i < 1000; i++) {"
8971 " proto[\"xxxxxxxx\" + i] = [];"
8974 "o.__proto__ = proto;"
8976 "for (var i = 0; i < 1000; i++) {"
8977 " result += receiver.x;"
8981 CHECK_EQ(1000, interceptor_load_not_handled_calls);
8989 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
8990 "o.__proto__ = this;"
8991 "this.__proto__.y = 239;"
8992 "for (var i = 0; i < 10; i++) {"
8993 " if (o.y != 239) throw 'oops: ' + o.y;"
8998 "for (var i = 0; i < 10; i++) {"
9006 static void SetOnThis(Local<String> name,
9008 const AccessorInfo& info) {
9009 info.This()->ForceSet(name, value);
9025 "for (var i = 0; i < 7; i++) {"
9033 "r = { __proto__: o };"
9035 "for (var i = 0; i < 7; i++) {"
9038 CHECK_EQ(239, value->Int32Value());
9058 "for (var i = 0; i < 7; i++) {"
9059 " result = o.x + o.y;"
9066 "r = { __proto__: o };"
9068 "for (var i = 0; i < 7; i++) {"
9069 " result = r.x + r.y;"
9071 CHECK_EQ(239 + 42, value->Int32Value());
9085 "fst = new Object(); fst.__proto__ = o;"
9086 "snd = new Object(); snd.__proto__ = fst;"
9088 "for (var i = 0; i < 7; i++) {"
9093 "for (var i = 0; i < 7; i++) {"
9096 "result + result1");
9116 "for (var i = 0; i < 7; i++) {"
9121 "for (var i = 0; i < 7; i++) {"
9136 templ_p->
SetAccessor(v8_str(
"y"), Return239, SetOnThis);
9143 "inbetween = new Object();"
9144 "o.__proto__ = inbetween;"
9145 "inbetween.__proto__ = p;"
9146 "for (var i = 0; i < 10; i++) {"
9152 "for (var i = 0; i < 10; i++) {"
9168 templ_p->
SetAccessor(v8_str(
"y"), Return239, SetOnThis);
9175 "o.__proto__ = this;"
9176 "this.__proto__ = p;"
9177 "for (var i = 0; i < 10; i++) {"
9178 " if (o.y != 239) throw 'oops: ' + o.y;"
9183 "for (var i = 0; i < 10; i++) {"
9192 const AccessorInfo& info) {
9194 CHECK(v8_str(
"x")->Equals(name));
9200 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
9201 "o.x == undefined ? 1 : 0",
9207 Local<String> key, Local<Value> value,
const AccessorInfo&) {
9208 CHECK(v8_str(
"x")->Equals(key));
9219 InterceptorStoreICSetter,
9220 0, 0, 0, v8_str(
"data"));
9224 "for (var i = 0; i < 1000; i++) {"
9237 "for (var i = 0; i < 1000; i++) {"
9252 const AccessorInfo& info) {
9254 CHECK(v8_str(
"x")->Equals(name));
9267 v8_compile(
"function f(x) { return x + 1; }; f")->Run();
9270 "for (var i = 0; i < 1000; i++) {"
9271 " result = o.x(41);"
9286 "o.x = function f(x) { return x + 1; };"
9288 "for (var i = 0; i < 7; i++) {"
9289 " result = o.x(41);"
9297 const AccessorInfo& info) {
9299 CHECK(v8_str(
"x")->Equals(name));
9300 return call_ic_function4;
9314 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9316 "o.__proto__.x = function(x) { return x + 1; };"
9318 "for (var i = 0; i < 1000; i++) {"
9319 " result = o.x(42);"
9334 "proto1 = new Object();"
9335 "proto2 = new Object();"
9336 "o.__proto__ = proto1;"
9337 "proto1.__proto__ = proto2;"
9338 "proto2.y = function(x) { return x + 1; };"
9340 "for (var i = 0; i < 7; i++) {"
9343 "proto1.y = function(x) { return x - 1; };"
9345 "for (var i = 0; i < 7; i++) {"
9346 " result += o.y(42);"
9361 "function inc(x) { return x + 1; };"
9365 "for (var i = 0; i < 1000; i++) {"
9366 " result = o.x(42);"
9374 const AccessorInfo& info) {
9376 if (v8_str(
"x")->Equals(name))
9377 return call_ic_function5;
9379 return Local<Value>();
9393 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9395 "function inc(x) { return x + 1; };"
9399 "for (var i = 0; i < 1000; i++) {"
9400 " result = o.x(42);"
9408 const AccessorInfo& info) {
9410 if (v8_str(
"x")->Equals(name))
9411 return call_ic_function6;
9413 return Local<Value>();
9420 i::FLAG_allow_natives_syntax =
true;
9427 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
9429 "function inc(x) { return x + 1; };"
9434 " for (var i = 0; i < 1000; i++) {"
9435 " result = o.x(42);"
9442 "%OptimizeFunctionOnNextCall(test);"
9457 "function inc(x) { return x + 1; };"
9459 "proto1 = new Object();"
9460 "proto2 = new Object();"
9461 "o.__proto__ = proto1;"
9462 "proto1.__proto__ = proto2;"
9465 "for (var i = 0; i < 7; i++) {"
9468 "proto1.y = function(x) { return x - 1; };"
9470 "for (var i = 0; i < 7; i++) {"
9471 " result += o.y(42);"
9487 "function inc(x) { return x + 1; };"
9489 "o.__proto__ = this;"
9490 "this.__proto__.y = inc;"
9492 "for (var i = 0; i < 7; i++) {"
9493 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
9495 "this.y = function(x) { return x - 1; };"
9497 "for (var i = 0; i < 7; i++) {"
9498 " result += o.y(42);"
9515 " o.__proto__ = this;"
9516 " for (var i = 0; i < 10; i++) {"
9517 " var v = o.parseFloat('239');"
9518 " if (v != 239) throw v;"
9522 " for (var i = 0; i < 10; i++) {"
9523 " result += o.parseFloat('239');"
9533 const AccessorInfo& info) {
9537 if ((*call_count) % 20 == 0) {
9549 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
9559 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
9562 CHECK(args.
Holder()->HasRealNamedProperty(v8_str(
"foo")));
9567 static void GenerateSomeGarbage() {
9570 "for (var i = 0; i < 1000; i++) {"
9571 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
9573 "garbage = undefined;");
9578 static int count = 0;
9579 if (count++ % 3 == 0) {
9582 GenerateSomeGarbage();
9592 nativeobject_templ->
Set(
"callback",
9595 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
9599 " for (var i = 1; i <= 30; i++) {"
9600 " nativeobject.callback();"
9616 nativeobject_templ->
Set(
"callback",
9619 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
9624 " for (var i = 1; i <= 5; i++) {"
9625 " try { nativeobject.callback(); } catch (e) { result += e; }"
9635 if (++p_getter_count % 3 == 0) {
9637 GenerateSomeGarbage();
9652 " for (var i = 0; i < 30; i++) o1.p1;"
9673 "for (var i = 0; i < 5; i++) {"
9674 " try { o1.p1; } catch (e) { result += e; }"
9682 int interceptor_call_count = 0;
9687 v8_str(
"method_data"),
9690 proto_templ->
Set(v8_str(
"method"), method_templ);
9697 GenerateSomeGarbage();
9701 "for (var i = 0; i < 100; i++) {"
9702 " result = o.method(41);"
9704 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9705 CHECK_EQ(100, interceptor_call_count);
9709 int interceptor_call_count = 0;
9714 v8_str(
"method_data"),
9717 proto_templ->
Set(v8_str(
"method"), method_templ);
9724 GenerateSomeGarbage();
9728 "var receiver = {};"
9729 "receiver.__proto__ = o;"
9731 "for (var i = 0; i < 100; i++) {"
9732 " result = receiver.method(41);"
9734 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9735 CHECK_EQ(100, interceptor_call_count);
9739 int interceptor_call_count = 0;
9744 v8_str(
"method_data"),
9747 proto_templ->
Set(v8_str(
"method"), method_templ);
9754 GenerateSomeGarbage();
9758 "var receiver = {};"
9759 "receiver.__proto__ = o;"
9761 "var saved_result = 0;"
9762 "for (var i = 0; i < 100; i++) {"
9763 " result = receiver.method(41);"
9765 " saved_result = result;"
9766 " receiver = {method: function(x) { return x - 1 }};"
9769 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9770 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9771 CHECK_GE(interceptor_call_count, 50);
9775 int interceptor_call_count = 0;
9780 v8_str(
"method_data"),
9783 proto_templ->
Set(v8_str(
"method"), method_templ);
9790 GenerateSomeGarbage();
9794 "var receiver = {};"
9795 "receiver.__proto__ = o;"
9797 "var saved_result = 0;"
9798 "for (var i = 0; i < 100; i++) {"
9799 " result = receiver.method(41);"
9801 " saved_result = result;"
9802 " o.method = function(x) { return x - 1 };"
9805 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9806 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9807 CHECK_GE(interceptor_call_count, 50);
9811 int interceptor_call_count = 0;
9816 v8_str(
"method_data"),
9819 proto_templ->
Set(v8_str(
"method"), method_templ);
9826 GenerateSomeGarbage();
9831 "var receiver = {};"
9832 "receiver.__proto__ = o;"
9834 "var saved_result = 0;"
9835 "for (var i = 0; i < 100; i++) {"
9836 " result = receiver.method(41);"
9838 " saved_result = result;"
9843 CHECK_EQ(v8_str(
"TypeError: Object 333 has no method 'method'"),
9845 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9846 CHECK_GE(interceptor_call_count, 50);
9850 int interceptor_call_count = 0;
9855 v8_str(
"method_data"),
9858 proto_templ->
Set(v8_str(
"method"), method_templ);
9865 GenerateSomeGarbage();
9870 "var receiver = {};"
9871 "receiver.__proto__ = o;"
9873 "var saved_result = 0;"
9874 "for (var i = 0; i < 100; i++) {"
9875 " result = receiver.method(41);"
9877 " saved_result = result;"
9878 " receiver = {method: receiver.method};"
9882 CHECK_EQ(v8_str(
"TypeError: Illegal invocation"),
9884 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
9885 CHECK_GE(interceptor_call_count, 50);
9893 v8_str(
"method_data"),
9896 proto_templ->
Set(v8_str(
"method"), method_templ);
9901 GenerateSomeGarbage();
9905 "for (var i = 0; i < 100; i++) {"
9906 " result = o.method(41);"
9909 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
9917 v8_str(
"method_data"),
9920 proto_templ->
Set(v8_str(
"method"), method_templ);
9922 CHECK(!templ.IsEmpty());
9925 GenerateSomeGarbage();
9929 "var receiver = {};"
9930 "receiver.__proto__ = o;"
9932 "for (var i = 0; i < 100; i++) {"
9933 " result = receiver.method(41);"
9936 CHECK_EQ(42, context->Global()->Get(v8_str(
"result"))->Int32Value());
9944 v8_str(
"method_data"),
9947 proto_templ->
Set(v8_str(
"method"), method_templ);
9949 CHECK(!templ.IsEmpty());
9952 GenerateSomeGarbage();
9956 "var receiver = {};"
9957 "receiver.__proto__ = o;"
9959 "var saved_result = 0;"
9960 "for (var i = 0; i < 100; i++) {"
9961 " result = receiver.method(41);"
9963 " saved_result = result;"
9964 " receiver = {method: function(x) { return x - 1 }};"
9967 CHECK_EQ(40, context->Global()->Get(v8_str(
"result"))->Int32Value());
9968 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
9976 v8_str(
"method_data"),
9979 proto_templ->
Set(v8_str(
"method"), method_templ);
9981 CHECK(!templ.IsEmpty());
9984 GenerateSomeGarbage();
9989 "var receiver = {};"
9990 "receiver.__proto__ = o;"
9992 "var saved_result = 0;"
9993 "for (var i = 0; i < 100; i++) {"
9994 " result = receiver.method(41);"
9996 " saved_result = result;"
10001 CHECK_EQ(v8_str(
"TypeError: Object 333 has no method 'method'"),
10003 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
10010 Local<String> name,
const AccessorInfo& info) {
10012 if (v8_str(
"x")->Equals(name)) {
10028 "proto = new Object();"
10029 "proto.y = function(x) { return x + 1; };"
10030 "proto.z = function(x) { return x - 1; };"
10031 "o.__proto__ = proto;"
10033 "var method = 'y';"
10034 "for (var i = 0; i < 10; i++) {"
10035 " if (i == 5) { method = 'z'; };"
10036 " result += o[method](41);"
10038 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10051 keyed_call_ic_function =
10052 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
10054 "o = new Object();"
10055 "proto2 = new Object();"
10056 "o.y = function(x) { return x + 1; };"
10057 "proto2.y = function(x) { return x + 2; };"
10058 "o.__proto__ = proto1;"
10059 "proto1.__proto__ = proto2;"
10061 "var method = 'x';"
10062 "for (var i = 0; i < 10; i++) {"
10063 " if (i == 5) { method = 'y'; };"
10064 " result += o[method](41);"
10066 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10079 "function inc(x) { return x + 1; };"
10081 "function dec(x) { return x - 1; };"
10083 "o.__proto__ = this;"
10084 "this.__proto__.x = inc;"
10085 "this.__proto__.y = dec;"
10087 "var method = 'x';"
10088 "for (var i = 0; i < 10; i++) {"
10089 " if (i == 5) { method = 'y'; };"
10090 " result += o[method](41);"
10092 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10105 "function len(x) { return x.length; };"
10106 "o.__proto__ = this;"
10107 "var m = 'parseFloat';"
10109 "for (var i = 0; i < 10; i++) {"
10112 " saved_result = result;"
10114 " result = o[m]('239');"
10116 CHECK_EQ(3, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10117 CHECK_EQ(239, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
10129 "var o = new Object();"
10130 "o.__proto__ = proto;"
10131 "o.method = function(x) { return x + 1; };"
10132 "var m = 'method';"
10134 "for (var i = 0; i < 10; i++) {"
10135 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
10136 " result += o[m](41);"
10138 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10151 "var proto = new Object();"
10152 "o.__proto__ = proto;"
10153 "proto.method = function(x) { return x + 1; };"
10154 "var m = 'method';"
10156 "for (var i = 0; i < 10; i++) {"
10157 " if (i == 5) { proto.method = function(x) { return x - 1; }; };"
10158 " result += o[m](41);"
10160 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
10164 static int interceptor_call_count = 0;
10167 const AccessorInfo& info) {
10169 if (v8_str(
"x")->Equals(name) && interceptor_call_count++ < 20) {
10184 call_ic_function2 = v8_compile(
"function h(x) { return x; }; h")->Run();
10187 " for (var i = 0; i < 1000; i++) {"
10188 " try { x; } catch(e) { return true; }"
10194 interceptor_call_count = 0;
10195 value = CompileRun(
10197 " for (var i = 0; i < 1000; i++) {"
10198 " try { x(42); } catch(e) { return true; }"
10207 static int interceptor_ic_exception_get_count = 0;
10210 Local<String> name,
10211 const AccessorInfo& info) {
10213 if (v8_str(
"x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) {
10216 if (interceptor_ic_exception_get_count == 20) {
10226 interceptor_ic_exception_get_count = 0;
10231 call_ic_function3 = v8_compile(
"function h(x) { return x; }; h")->Run();
10234 " for (var i = 0; i < 100; i++) {"
10235 " try { x; } catch(e) { return true; }"
10241 interceptor_ic_exception_get_count = 0;
10242 value = CompileRun(
10244 " for (var i = 0; i < 100; i++) {"
10245 " try { x(42); } catch(e) { return true; }"
10254 static int interceptor_ic_exception_set_count = 0;
10257 Local<String> key, Local<Value> value,
const AccessorInfo&) {
10259 if (++interceptor_ic_exception_set_count > 20) {
10269 interceptor_ic_exception_set_count = 0;
10276 " for (var i = 0; i < 100; i++) {"
10277 " try { x = 42; } catch(e) { return true; }"
10292 templ->
Set(
"x", v8_num(42));
10294 context->
Global()->Set(v8_str(
"obj"), obj);
10307 templ->
Set(
"42", v8_num(42));
10309 context->
Global()->Set(v8_str(
"obj"), obj);
10319 templ->
InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10321 env->
Global()->Set(v8_str(
"obj"),
10323 ExpectTrue(
"obj.x === 42");
10324 ExpectTrue(
"!obj.propertyIsEnumerable('x')");
10328 static Handle<Value> ThrowingGetter(Local<String> name,
10329 const AccessorInfo& info) {
10340 Local<FunctionTemplate> templ = FunctionTemplate::New();
10341 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
10342 instance_templ->SetAccessor(v8_str(
"f"), ThrowingGetter);
10344 Local<Object> instance = templ->GetFunction()->NewInstance();
10346 Local<Object> another = Object::New();
10347 another->SetPrototype(instance);
10349 Local<Object> with_js_getter = CompileRun(
10351 "o.__defineGetter__('f', function() { throw undefined; });\n"
10353 CHECK(!with_js_getter.IsEmpty());
10355 TryCatch try_catch;
10358 CHECK(try_catch.HasCaught());
10360 CHECK(result.IsEmpty());
10362 result = another->GetRealNamedProperty(v8_str(
"f"));
10363 CHECK(try_catch.HasCaught());
10365 CHECK(result.IsEmpty());
10367 result = another->GetRealNamedPropertyInPrototypeChain(v8_str(
"f"));
10368 CHECK(try_catch.HasCaught());
10370 CHECK(result.IsEmpty());
10372 result = another->Get(v8_str(
"f"));
10373 CHECK(try_catch.HasCaught());
10375 CHECK(result.IsEmpty());
10377 result = with_js_getter->GetRealNamedProperty(v8_str(
"f"));
10378 CHECK(try_catch.HasCaught());
10380 CHECK(result.IsEmpty());
10382 result = with_js_getter->Get(v8_str(
"f"));
10383 CHECK(try_catch.HasCaught());
10385 CHECK(result.IsEmpty());
10389 static Handle<Value> ThrowingCallbackWithTryCatch(
const Arguments& args) {
10390 TryCatch try_catch;
10394 CompileRun(
"throw 'from JS';");
10395 CHECK(try_catch.HasCaught());
10396 CHECK(!i::Isolate::Current()->has_pending_exception());
10397 CHECK(!i::Isolate::Current()->has_scheduled_exception());
10402 static int call_depth;
10405 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
10406 TryCatch try_catch;
10410 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) {
10411 if (--call_depth) CompileRun(
"throw 'ThrowInJS';");
10415 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) {
10420 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
10421 Handle<String> errorMessageString = message->Get();
10422 CHECK(!errorMessageString.IsEmpty());
10423 message->GetStackTrace();
10424 message->GetScriptResourceName();
10431 Local<Function> func =
10432 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction();
10433 context->
Global()->Set(v8_str(
"func"), func);
10437 for (
unsigned i = 0; i <
sizeof(callbacks)/
sizeof(callbacks[0]); i++) {
10439 if (callback !=
NULL) {
10440 V8::AddMessageListener(callback);
10446 "var thrown = false;\n"
10447 "try { func(); } catch(e) { thrown = true; }\n"
10449 if (callback !=
NULL) {
10450 V8::RemoveMessageListeners(callback);
10457 const AccessorInfo& info) {
10464 const AccessorInfo& info) {
10471 i::FLAG_es5_readonly =
true;
10477 Local<ObjectTemplate> parent_instance_templ =
10478 parent_templ->InstanceTemplate();
10479 parent_instance_templ->SetAccessor(v8_str(
"f"), ParentGetter);
10483 Local<ObjectTemplate> child_instance_templ =
10484 child_templ->InstanceTemplate();
10485 child_templ->Inherit(parent_templ);
10488 child_instance_templ->SetAccessor(v8_str(
"f"), ChildGetter);
10490 child_instance_templ->SetAccessor(v8_str(
"g"), ParentGetter);
10491 child_instance_templ->SetAccessor(v8_str(
"g"), ChildGetter);
10495 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate();
10496 child_proto_templ->SetAccessor(v8_str(
"h"), ParentGetter, 0,
10502 child_instance_templ->SetAccessor(v8_str(
"i"), ChildGetter, 0,
10508 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance();
10511 context->
Global()->Set(v8_str(
"o"), instance);
10512 Local<Value> value = v8_compile(
"o.f")->Run();
10514 CHECK_EQ(42, value->Int32Value());
10515 value = v8_compile(
"o.g")->Run();
10516 CHECK_EQ(42, value->Int32Value());
10519 value = v8_compile(
"o.h = 3; o.h")->Run();
10523 value = v8_compile(
"o.i = 3; o.i")->Run();
10524 CHECK_EQ(42, value->Int32Value());
10539 templ->SetCallHandler(IsConstructHandler);
10543 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
10544 Local<Value> value = v8_compile(
"f()")->Run();
10545 CHECK(!value->BooleanValue());
10546 value = v8_compile(
"new f()")->Run();
10547 CHECK(value->BooleanValue());
10554 templ->SetClassName(v8_str(
"MyClass"));
10558 Local<String> customized_tostring = v8_str(
"customized toString");
10561 v8_compile(
"Object.prototype.toString = function() {"
10562 " return 'customized toString';"
10566 Local<v8::Object> instance = templ->GetFunction()->NewInstance();
10567 Local<String> value = instance->ToString();
10568 CHECK(value->IsString() && value->Equals(customized_tostring));
10571 value = instance->ObjectProtoToString();
10572 CHECK(value->IsString() && value->Equals(v8_str(
"[object MyClass]")));
10575 value = context->
Global()->ObjectProtoToString();
10576 CHECK(value->IsString() && value->Equals(v8_str(
"[object global]")));
10579 Local<Value>
object = v8_compile(
"new Object()")->Run();
10580 value =
object.As<
v8::Object>()->ObjectProtoToString();
10581 CHECK(value->IsString() && value->Equals(v8_str(
"[object Object]")));
10588 v8_compile(
"function Parent() {};"
10589 "function Child() {};"
10590 "Child.prototype = new Parent();"
10591 "var outer = { inner: function() { } };"
10592 "var p = new Parent();"
10593 "var c = new Child();"
10594 "var x = new outer.inner();")->Run();
10596 Local<v8::Value> p = context->
Global()->Get(v8_str(
"p"));
10597 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals(
10598 v8_str(
"Parent")));
10600 Local<v8::Value> c = context->
Global()->Get(v8_str(
"c"));
10601 CHECK(c->IsObject() && c->ToObject()->GetConstructorName()->Equals(
10604 Local<v8::Value> x = context->
Global()->Get(v8_str(
"x"));
10605 CHECK(x->IsObject() && x->ToObject()->GetConstructorName()->Equals(
10606 v8_str(
"outer.inner")));
10610 bool ApiTestFuzzer::fuzzing_ =
false;
10613 int ApiTestFuzzer::active_tests_;
10614 int ApiTestFuzzer::tests_being_run_;
10615 int ApiTestFuzzer::current_;
10621 if (!fuzzing_)
return;
10623 test->ContextSwitch();
10629 bool ApiTestFuzzer::NextThread() {
10630 int test_position = GetNextTestNumber();
10632 if (test_position == current_) {
10634 printf(
"Stay with %s\n", test_name);
10637 if (kLogThreading) {
10638 printf(
"Switch from %s to %s\n",
10642 current_ = test_position;
10660 if (active_tests_ == 0) {
10661 all_tests_done_->
Signal();
10669 static unsigned linear_congruential_generator;
10673 linear_congruential_generator = i::FLAG_testing_prng_seed;
10676 int start = count * part / (
LAST_PART + 1);
10677 int end = (count * (part + 1) / (
LAST_PART + 1)) - 1;
10678 active_tests_ = tests_being_run_ = end - start + 1;
10679 for (
int i = 0; i < tests_being_run_; i++) {
10682 for (
int i = 0; i < active_tests_; i++) {
10688 static void CallTestNumber(
int test_number) {
10698 all_tests_done_->
Wait();
10702 int ApiTestFuzzer::GetNextTestNumber() {
10705 next_test = (linear_congruential_generator >> 16) % tests_being_run_;
10706 linear_congruential_generator *= 1664525u;
10707 linear_congruential_generator += 1013904223u;
10713 void ApiTestFuzzer::ContextSwitch() {
10715 if (NextThread()) {
10729 if (fuzzer !=
NULL) fuzzer->
Join();
10761 printf(
"Start test %d\n", test_number_);
10762 CallTestNumber(test_number_);
10764 printf(
"End test %d\n", test_number_);
10772 const char* code =
"throw 7;";
10784 exception = Local<Value>::New(try_catch.
Exception());
10795 const char* code =
"throw 7;";
10801 return v8_str(
"foo");
10814 Local<Function> fun = fun_templ->GetFunction();
10815 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
10816 Local<Script> script = v8_compile(
"(function () {"
10824 CHECK_EQ(91, script->Run()->Int32Value());
10834 Local<v8::FunctionTemplate> fun_templ =
10836 Local<Function> fun = fun_templ->GetFunction();
10837 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
10838 Local<Script> script = v8_compile(
"(function () {"
10846 CHECK_EQ(91, script->Run()->Int32Value());
10871 Local<v8::FunctionTemplate> fun_templ =
10873 Local<Function> fun = fun_templ->GetFunction();
10874 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
10875 Local<Script> script = v8_compile(
"(function () {"
10876 " unlock_for_a_moment();"
10879 CHECK_EQ(42, script->Run()->Int32Value());
10885 Local<v8::FunctionTemplate> fun_templ =
10887 Local<Function> fun = fun_templ->GetFunction();
10888 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
10889 Local<Script> script = v8_compile(
"(function () {"
10890 " unlock_for_a_moment();"
10893 CHECK_EQ(42, script->Run()->Int32Value());
10898 static int GetGlobalObjectsCount() {
10899 i::Isolate::Current()->heap()->EnsureHeapIsIterable();
10901 i::HeapIterator it;
10903 if (object->IsJSGlobalObject()) count++;
10908 static void CheckSurvivingGlobalObjectsCount(
int expected) {
10916 int count = GetGlobalObjectsCount();
10918 if (count != expected)
HEAP->TracePathToGlobal();
10929 for (
int i = 0; i < 5; i++) {
10934 CheckSurvivingGlobalObjectsCount(0);
10938 v8_compile(
"Date")->Run();
10941 CheckSurvivingGlobalObjectsCount(0);
10945 v8_compile(
"/aaa/")->Run();
10948 CheckSurvivingGlobalObjectsCount(0);
10951 const char* extension_list[] = {
"v8/gc" };
10954 v8_compile(
"gc();")->Run();
10957 CheckSurvivingGlobalObjectsCount(0);
11011 to_be_disposed = handle2;
11046 const char* sources[nof] = {
11047 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
11051 for (
int i = 0; i < nof; i++) {
11052 const char* source = sources[i];
11055 CompileRun(source);
11059 CompileRun(source);
11081 CHECK(!str.IsEmpty());
11088 static int foo_count = 0;
11090 static int bar_count = 0;
11093 static void entry_hook(uintptr_t
function,
11094 uintptr_t return_addr_location) {
11096 reinterpret_cast<i::Address>(
function));
11099 if (bar_ptr !=
NULL && code == (*bar_ptr)->code())
11102 if (foo_ptr !=
NULL && code == (*foo_ptr)->code())
11111 static void RunLoopInNewEnv() {
11119 const char* script =
11122 " for (i = 0; i < 100; ++i)"
11126 "function foo(i) { return i * i; }";
11127 CompileRun(script);
11130 v8::Utils::OpenHandle(*env->Global()->Get(v8_str(
"bar"))));
11135 v8::Utils::OpenHandle(*env->Global()->Get(v8_str(
"foo"))));
11146 value = CompileRun(
"%OptimizeFunctionOnNextCall(foo);"
11148 CHECK(value->IsNumber());
11156 i::FLAG_allow_natives_syntax =
true;
11184 v8::internal::Isolate::Current()->compilation_cache()->Clear();
11194 static int saw_bar = 0;
11195 static int move_events = 0;
11198 static bool FunctionNameIs(
const char* expected,
11203 static const char kPreamble[] =
"LazyCompile:";
11204 static size_t kPreambleLen =
sizeof(kPreamble) - 1;
11206 if (event->
name.len <
sizeof(kPreamble) - 1 ||
11207 strncmp(kPreamble, event->
name.str, kPreambleLen) != 0) {
11211 const char* tail =
event->name.str + kPreambleLen;
11212 size_t tail_len =
event->name.len - kPreambleLen;
11213 size_t expected_len = strlen(expected);
11214 if (tail_len == expected_len + 1) {
11215 if (*tail ==
'*' || *tail ==
'~') {
11223 if (tail_len != expected_len)
11226 return strncmp(tail, expected, expected_len) == 0;
11234 switch (event->
type) {
11239 i::HashMap::Entry* entry =
11243 entry->value =
reinterpret_cast<void*
>(
event->code_len);
11245 if (FunctionNameIs(
"bar", event)) {
11260 i::HashMap::Entry* entry =
11262 if (entry !=
NULL) {
11272 entry->value =
reinterpret_cast<void*
>(
event->code_len);
11293 static bool MatchPointers(
void* key1,
void* key2) {
11294 return key1 == key2;
11299 const char* script =
11302 " for (i = 0; i < 100; ++i)"
11306 "function foo(i) { return i * i; };"
11321 i::FLAG_stress_compaction =
true;
11327 const int kIterations = 10;
11328 for (
int i = 0; i < kIterations; ++i) {
11335 compiled_script = v8_compile(script);
11337 compiled_script->
Run();
11340 ISOLATE->compilation_cache()->Clear();
11344 HEAP->CollectAllAvailableGarbage(
"TestSetJitCodeEventHandler");
11365 CompileRun(script);
11388 static int64_t cast(intptr_t x) {
return static_cast<int64_t
>(x); }
11395 const intptr_t kSize = 1024*1024;
11451 const char* resource_name,
11459 CHECK(!message.IsEmpty());
11460 CHECK_EQ(10 + line_offset, message->GetLineNumber());
11461 CHECK_EQ(91, message->GetStartPosition());
11462 CHECK_EQ(92, message->GetEndPosition());
11463 CHECK_EQ(2, message->GetStartColumn());
11464 CHECK_EQ(3, message->GetEndColumn());
11466 CHECK_EQ(
" throw 'nirk';", *line);
11476 "function Foo() {\n"
11480 "function Bar() {\n"
11484 "function Baz() {\n"
11490 const char* resource_name;
11492 resource_name =
"test.js";
11494 CheckTryCatchSourceInfo(script, resource_name, 0);
11496 resource_name =
"test1.js";
11499 CheckTryCatchSourceInfo(script, resource_name, 0);
11501 resource_name =
"test2.js";
11504 CheckTryCatchSourceInfo(script, resource_name, 7);
11534 Local<ObjectTemplate> t = ObjectTemplate::New();
11536 context->
Global()->Set(v8_str(
"obj"), t->NewInstance());
11557 for (
int i = 0; i < elmc; i++) {
11566 const char* elmv[]) {
11570 for (
int i = 0; i < elmc; i++) {
11583 "result[1] = {a: 1, b: 2};"
11584 "result[2] = [1, 2, 3];"
11585 "var proto = {x: 1, y: 2, z: 3};"
11586 "var x = { __proto__: proto, w: 0, z: 1 };"
11588 "result;"))->Run();
11592 const char** elmv0 =
NULL;
11596 const char* elmv1[] = {
"a",
"b"};
11600 const char* elmv2[] = {
"0",
"1",
"2"};
11604 const char* elmv3[] = {
"w",
"z",
"x",
"y"};
11607 const char* elmv4[] = {
"w",
"z"};
11617 "result[1] = {a: 1, b: 2};"
11618 "result[2] = [1, 2, 3];"
11619 "var proto = {x: 1, y: 2, z: 3};"
11620 "var x = { __proto__: proto, w: 0, z: 1 };"
11622 "result;"))->Run();
11626 const char** elmv0 =
NULL;
11632 for (uint32_t i = 0; i < props->
Length(); i++) {
11633 printf(
"p[%d]\n", i);
11637 static bool NamedSetAccessBlocker(Local<v8::Object> obj,
11640 Local<Value> data) {
11645 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
11648 Local<Value> data) {
11656 Local<ObjectTemplate> templ = ObjectTemplate::New();
11657 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
11658 IndexedSetAccessBlocker);
11659 templ->Set(v8_str(
"x"),
v8::True());
11660 Local<v8::Object> instance = templ->NewInstance();
11661 context->
Global()->Set(v8_str(
"obj"), instance);
11662 Local<Value> value = CompileRun(
"obj.x");
11663 CHECK(value->BooleanValue());
11667 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
11670 Local<Value> data) {
11675 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
11678 Local<Value> data) {
11687 Local<ObjectTemplate> templ = ObjectTemplate::New();
11688 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
11689 IndexedGetAccessBlocker);
11690 templ->Set(v8_str(
"a"), v8_str(
"a"));
11695 for (
char i =
'0'; i <=
'9' ; i++) {
11697 for (
char j =
'0'; j <=
'9'; j++) {
11699 for (
char k =
'0'; k <=
'9'; k++) {
11707 Local<v8::Object> instance_1 = templ->NewInstance();
11708 context->
Global()->Set(v8_str(
"obj_1"), instance_1);
11710 Local<Value> value_1 = CompileRun(
"obj_1.a");
11711 CHECK(value_1->IsUndefined());
11713 Local<v8::Object> instance_2 = templ->NewInstance();
11714 context->
Global()->Set(v8_str(
"obj_2"), instance_2);
11716 Local<Value> value_2 = CompileRun(
"obj_2.a");
11717 CHECK(value_2->IsUndefined());
11727 IndexedSetAccessBlocker);
11729 v8::Utils::OpenHandle(*global_template);
11730 CHECK(!internal_template->constructor()->IsUndefined());
11733 CHECK(!constructor->access_check_info()->IsUndefined());
11735 CHECK(!context0.IsEmpty());
11736 CHECK(!constructor->access_check_info()->IsUndefined());
11747 IndexedGetAccessBlocker,
11751 Context::Scope context_scope(context);
11754 context->Global()->Set(v8_str(
"a"), v8_num(1));
11755 CompileRun(
"function f1() {return a;}"
11756 "function f2() {return a;}"
11757 "function g1() {return h();}"
11758 "function g2() {return h();}"
11759 "function h() {return 1;}");
11760 Local<Function>
f1 =
11761 Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11762 Local<Function>
f2 =
11763 Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11764 Local<Function> g1 =
11765 Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11766 Local<Function> g2 =
11767 Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11768 Local<Function> h =
11769 Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
11777 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11778 for (
int i = 0; i < 4; i++) {
11779 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11783 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11784 for (
int i = 0; i < 4; i++) {
11785 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11789 context->DetachGlobal();
11790 context->Global()->TurnOnAccessCheck();
11793 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11794 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11797 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11798 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11801 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
11805 static const char* kPropertyA =
"a";
11806 static const char* kPropertyH =
"h";
11808 static bool NamedGetAccessBlockAandH(Local<v8::Object> obj,
11811 Local<Value> data) {
11812 if (!name->IsString())
return false;
11814 v8::Utils::OpenHandle(String::Cast(*name));
11828 IndexedGetAccessBlocker,
11832 Context::Scope context_scope(context);
11835 context->Global()->Set(v8_str(
"a"), v8_num(1));
11836 static const char* source =
"function f1() {return a;}"
11837 "function f2() {return a;}"
11838 "function g1() {return h();}"
11839 "function g2() {return h();}"
11840 "function h() {return 1;}";
11842 CompileRun(source);
11843 Local<Function>
f1;
11844 Local<Function>
f2;
11845 Local<Function> g1;
11846 Local<Function> g2;
11848 f1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11849 f2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11850 g1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11851 g2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11852 h = Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
11860 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11861 for (
int i = 0; i < 4; i++) {
11862 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11866 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
11867 for (
int i = 0; i < 4; i++) {
11868 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
11873 context->DetachGlobal();
11874 context->Global()->TurnOnAccessCheck();
11877 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11878 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11881 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11882 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11885 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
11889 CompileRun(source);
11890 f1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
11891 f2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
11892 g1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
11893 g2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
11894 CHECK(context->Global()->Get(v8_str(
"h"))->IsUndefined());
11897 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
11898 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
11901 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
11902 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
11913 const char* script =
"function foo(a) { return a+1; }";
11925 const char* script =
"function foo(a) { return 1 * * 2; }";
11935 const char* script =
" The Definintive Guide";
11946 const char* script =
"function foo(a) { return a+1; }";
11951 int serialized_data_length = sd->
Length();
11952 char* serialized_data = i::NewArray<char>(serialized_data_length);
11953 memcpy(serialized_data, sd->
Data(), serialized_data_length);
11965 delete deserialized_sd;
11972 const char* data =
"DONT CARE";
11973 int invalid_size = 3;
11983 TEST(PreCompileInvalidPreparseDataError) {
11988 const char* script =
"function foo(){ return 5;}\n"
11989 "function bar(){ return 6 + 7;} foo();";
11995 const int kFunctionEntrySize = i::FunctionEntry::kSize;
11996 const int kFunctionEntryStartOffset = 0;
11997 const int kFunctionEntryEndOffset = 1;
11998 unsigned* sd_data =
11999 reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
12002 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
12005 Local<String> source = String::New(script);
12006 Local<Script> compiled_script = Script::New(source,
NULL, sd);
12008 String::AsciiValue exception_value(try_catch.
Message()->Get());
12009 CHECK_EQ(
"Uncaught SyntaxError: Invalid preparser data for function bar",
12018 sd_data =
reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
12019 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
12021 compiled_script = Script::New(source,
NULL, sd);
12034 const char* cstring =
"function foo(a) { return a+1; }";
12048 sd_from_external_string->
Data(),
12049 sd_from_cstring->
Length()));
12053 sd_from_string->
Data(),
12054 sd_from_cstring->
Length()));
12057 delete sd_from_cstring;
12058 delete sd_from_external_string;
12059 delete sd_from_string;
12071 for (
int i = 0; i < 2; i++) {
12074 context->
Global()->Delete(v8_str(
"tmp"));
12075 CompileRun(
"for (var j = 0; j < 10; j++) new RegExp('');");
12078 for (
int i = 0; i < 2; i++) {
12081 context->
Global()->Delete(v8_str(
"tmp"));
12082 CompileRun(
"for (var j = 0; j < 10; j++) RegExp('')");
12095 Local<String> token = v8_str(
"<security token>");
12096 context0->SetSecurityToken(token);
12097 context1->SetSecurityToken(token);
12102 CompileRun(
"Object.prototype.x = 42; function C() {};");
12108 context1->Global()->Set(v8_str(
"other"), context0->Global());
12109 Local<Value> value = CompileRun(
"var instance = new other.C(); instance.x");
12110 CHECK(value->IsInt32());
12111 CHECK_EQ(42, value->Int32Value());
12127 gc_during_regexp_ = 0;
12128 regexp_success_ =
false;
12129 gc_success_ =
false;
12130 GCThread gc_thread(
this);
12134 LongRunningRegExp();
12140 CHECK(regexp_success_);
12141 CHECK(gc_success_);
12146 static const int kRequiredGCs = 5;
12151 : Thread(
"GCThread"), test_(test) {}
12152 virtual void Run() {
12153 test_->CollectGarbage();
12159 void CollectGarbage() {
12161 while (gc_during_regexp_ < kRequiredGCs) {
12170 gc_success_ =
true;
12173 void LongRunningRegExp() {
12176 while (gc_during_regexp_ < kRequiredGCs) {
12177 int gc_before = gc_count_;
12180 const char* c_source =
12181 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
12182 ".exec('aaaaaaaaaaaaaaab') === null";
12183 Local<String> source = String::New(c_source);
12184 Local<Script> script = Script::Compile(source);
12185 Local<Value> result = script->Run();
12186 if (!result->BooleanValue()) {
12187 gc_during_regexp_ = kRequiredGCs;
12193 const char* c_source =
12194 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
12195 ".exec('aaaaaaaaaaaaaaaab')[0] === 'aaaaaaaaaaaaaaaa'";
12196 Local<String> source = String::New(c_source);
12197 Local<Script> script = Script::Compile(source);
12198 Local<Value> result = script->Run();
12199 if (!result->BooleanValue()) {
12200 gc_during_regexp_ = kRequiredGCs;
12204 int gc_after = gc_count_;
12205 gc_during_regexp_ += gc_after - gc_before;
12209 regexp_success_ =
true;
12214 int gc_during_regexp_;
12215 bool regexp_success_;
12226 Local<Context> local_env;
12229 local_env = env.
local();
12233 CHECK(!local_env.IsEmpty());
12234 local_env->Enter();
12250 gc_during_apply_ = 0;
12251 apply_success_ =
false;
12252 gc_success_ =
false;
12253 GCThread gc_thread(
this);
12257 LongRunningApply();
12263 CHECK(apply_success_);
12264 CHECK(gc_success_);
12269 static const int kRequiredGCs = 2;
12274 : Thread(
"GCThread"), test_(test) {}
12275 virtual void Run() {
12276 test_->CollectGarbage();
12282 void CollectGarbage() {
12284 while (gc_during_apply_ < kRequiredGCs) {
12292 gc_success_ =
true;
12295 void LongRunningApply() {
12298 while (gc_during_apply_ < kRequiredGCs) {
12299 int gc_before = gc_count_;
12301 const char* c_source =
12302 "function do_very_little(bar) {"
12305 "for (var i = 0; i < 100000; i++) {"
12306 " do_very_little.apply(this, ['bar']);"
12308 Local<String> source = String::New(c_source);
12309 Local<Script> script = Script::Compile(source);
12310 Local<Value> result = script->Run();
12312 CHECK(!result.IsEmpty());
12314 int gc_after = gc_count_;
12315 gc_during_apply_ += gc_after - gc_before;
12318 apply_success_ =
true;
12323 int gc_during_apply_;
12324 bool apply_success_;
12335 Local<Context> local_env;
12338 local_env = env.
local();
12342 CHECK(!local_env.IsEmpty());
12343 local_env->Enter();
12359 "rv.alpha = 'hello';" \
12364 Local<Value> val = CompileRun(sample);
12365 CHECK(val->IsObject());
12366 Local<v8::Object> obj = val.As<
v8::Object>();
12367 obj->
Set(v8_str(
"gamma"), v8_str(
"cloneme"));
12369 CHECK_EQ(v8_str(
"hello"), obj->Get(v8_str(
"alpha")));
12371 CHECK_EQ(v8_str(
"cloneme"), obj->Get(v8_str(
"gamma")));
12374 Local<v8::Object> clone = obj->Clone();
12375 CHECK_EQ(v8_str(
"hello"), clone->Get(v8_str(
"alpha")));
12377 CHECK_EQ(v8_str(
"cloneme"), clone->Get(v8_str(
"gamma")));
12410 static void MorphAString(
i::String*
string,
12413 CHECK(i::StringShape(
string).IsExternal());
12416 CHECK(string->
map() ==
HEAP->external_ascii_string_map());
12418 string->set_map(
HEAP->external_string_map());
12426 string->set_map(
HEAP->external_ascii_string_map());
12437 char utf_buffer[129];
12438 const char* c_string =
"Now is the time for all good men"
12439 " to come to the aid of the party";
12440 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
12451 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
12453 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
12455 env->
Global()->Set(v8_str(
"lhs"), lhs);
12456 env->
Global()->Set(v8_str(
"rhs"), rhs);
12459 "var cons = lhs + rhs;"
12460 "var slice = lhs.substring(1, lhs.length - 1);"
12461 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);");
12463 CHECK(!lhs->MayContainNonAscii());
12464 CHECK(!rhs->MayContainNonAscii());
12466 MorphAString(*v8::Utils::OpenHandle(*lhs), &ascii_resource, &uc16_resource);
12467 MorphAString(*v8::Utils::OpenHandle(*rhs), &ascii_resource, &uc16_resource);
12470 Handle<String> cons = v8_compile(
"cons")->Run().As<String>();
12471 CHECK_EQ(128, cons->Utf8Length());
12473 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars));
12477 "Now is the time for all good men to come to the aid of the party"
12478 "Now is the time for all good men to come to the aid of the party"));
12482 "/[^a-z]/.test(cons);"
12483 "/[^a-z]/.test(slice);"
12484 "/[^a-z]/.test(slice_on_cons);");
12485 const char* expected_cons =
12486 "Now is the time for all good men to come to the aid of the party"
12487 "Now is the time for all good men to come to the aid of the party";
12488 const char* expected_slice =
12489 "ow is the time for all good men to come to the aid of the part";
12490 const char* expected_slice_on_cons =
12491 "ow is the time for all good men to come to the aid of the party"
12492 "Now is the time for all good men to come to the aid of the part";
12493 CHECK_EQ(String::New(expected_cons),
12494 env->
Global()->Get(v8_str(
"cons")));
12495 CHECK_EQ(String::New(expected_slice),
12496 env->
Global()->Get(v8_str(
"slice")));
12497 CHECK_EQ(String::New(expected_slice_on_cons),
12498 env->
Global()->Get(v8_str(
"slice_on_cons")));
12510 const char* ascii_sources[] = {
12518 for (
int i = 0; ascii_sources[i] !=
NULL; i++) {
12519 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
12533 : block_(i::OS::CreateSemaphore(0)),
12535 morphs_during_regexp_(0),
12536 ascii_resource_(i::Vector<const char>(
"aaaaaaaaaaaaaab", 15)),
12537 uc16_resource_(i::Vector<const
uint16_t>(two_byte_content_, 15)) {}
12540 regexp_success_ =
false;
12541 morph_success_ =
false;
12545 for (
int i = 0; i < 14; i++) {
12546 two_byte_content_[i] =
'a';
12548 two_byte_content_[14] =
'b';
12552 input_ =
FACTORY->NewExternalStringFromAscii(&ascii_resource_);
12557 i::Isolate::Current()->native_context()->global_object()->SetProperty(
12563 MorphThread morph_thread(
this);
12564 morph_thread.Start();
12566 LongRunningRegExp();
12569 morph_thread.Join();
12572 CHECK(regexp_success_);
12573 CHECK(morph_success_);
12578 static const int kRequiredModifications = 5;
12579 static const int kMaxModifications = 100;
12584 : Thread(
"MorphThread"), test_(test) {}
12585 virtual void Run() {
12586 test_->MorphString();
12592 void MorphString() {
12594 while (morphs_during_regexp_ < kRequiredModifications &&
12595 morphs_ < kMaxModifications) {
12600 MorphAString(
string, &ascii_resource_, &uc16_resource_);
12605 morph_success_ =
true;
12608 void LongRunningRegExp() {
12610 while (morphs_during_regexp_ < kRequiredModifications &&
12611 morphs_ < kMaxModifications) {
12612 int morphs_before = morphs_;
12616 const char* c_source =
12617 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
12618 ".exec(input) === null";
12619 Local<String> source = String::New(c_source);
12620 Local<Script> script = Script::Compile(source);
12621 Local<Value> result = script->Run();
12622 CHECK(result->IsTrue());
12624 int morphs_after = morphs_;
12625 morphs_during_regexp_ += morphs_after - morphs_before;
12627 regexp_success_ =
true;
12630 i::uc16 two_byte_content_[15];
12633 int morphs_during_regexp_;
12634 bool regexp_success_;
12635 bool morph_success_;
12648 Local<Context> local_env;
12651 local_env = env.
local();
12655 CHECK(!local_env.IsEmpty());
12656 local_env->Enter();
12668 i::FLAG_es5_readonly =
true;
12679 CompileRun(
"function f() { x = 42; return x; }; f()");
12682 res = CompileRun(
"function f() { eval('1'); y = 43; return y; }; f()");
12685 res = CompileRun(
"function f() { with (this) { y = 44 }; return y; }; f()");
12689 static int force_set_set_count = 0;
12690 static int force_set_get_count = 0;
12695 force_set_get_count++;
12706 force_set_set_count++;
12713 force_set_set_count++;
12718 force_set_get_count = 0;
12719 force_set_set_count = 0;
12720 pass_on_get =
false;
12725 templ->
SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
12732 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12735 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12738 CHECK_EQ(6, global->
Get(simple_property)->Int32Value());
12743 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
12747 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
12753 CHECK_EQ(8, global->
Get(access_property)->Int32Value());
12759 force_set_get_count = 0;
12760 force_set_set_count = 0;
12761 pass_on_get =
false;
12772 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12776 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12782 pass_on_get =
true;
12783 CHECK(global->
Get(some_property)->IsUndefined());
12789 CHECK_EQ(8, global->
Get(some_property)->Int32Value());
12794 pass_on_get =
false;
12795 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
12814 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12817 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
12820 CHECK(global->
Get(simple_property)->IsUndefined());
12824 static int force_delete_interceptor_count = 0;
12825 static bool pass_on_delete =
false;
12831 force_delete_interceptor_count++;
12832 if (pass_on_delete) {
12841 force_delete_interceptor_count = 0;
12842 pass_on_delete =
false;
12855 CHECK_EQ(0, force_delete_interceptor_count);
12857 CHECK_EQ(1, force_delete_interceptor_count);
12858 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
12861 pass_on_delete =
true;
12863 CHECK_EQ(2, force_delete_interceptor_count);
12864 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
12868 CHECK(global->
Get(some_property)->IsUndefined());
12869 CHECK_EQ(2, force_delete_interceptor_count);
12879 CompileRun(
"this.__proto__ = { foo: 'horse' };"
12880 "var foo = 'fish';"
12881 "function f() { return foo.length; }");
12883 CompileRun(
"for (var i = 0; i < 4; i++) f();");
12885 CHECK_EQ(4, CompileRun(
"f()")->Int32Value());
12887 CHECK(context->
Global()->ForceDelete(v8_str(
"foo")));
12891 CHECK_EQ(5, CompileRun(
"f()")->Int32Value());
12896 i::FLAG_allow_natives_syntax =
true;
12904 CompileRun(
"var G = 42; function foo() { return G; }");
12907 ctx2->Global()->Set(v8_str(
"o"), foo);
12909 "function f() { return o(); }"
12910 "for (var i = 0; i < 10; ++i) f();"
12911 "%OptimizeFunctionOnNextCall(f);"
12916 CHECK(ctx1->Global()->ForceDelete(G_property));
12923 " return e.toString();"
12926 "ReferenceError: G is not defined");
12945 CHECK(Context::GetCurrent() == calling_context0);
12946 CHECK(Context::GetCalling() == calling_context1);
12947 CHECK(Context::GetEntered() == calling_context2);
12955 calling_context0 = Context::New();
12956 calling_context1 = Context::New();
12957 calling_context2 = Context::New();
12960 Local<String> token = v8_str(
"<security token>");
12961 calling_context0->SetSecurityToken(token);
12962 calling_context1->SetSecurityToken(token);
12963 calling_context2->SetSecurityToken(token);
12966 calling_context0->Enter();
12967 Local<v8::FunctionTemplate> callback_templ =
12969 calling_context0->Global()->Set(v8_str(
"callback"),
12970 callback_templ->GetFunction());
12971 calling_context0->Exit();
12975 calling_context1->Enter();
12976 calling_context1->Global()->Set(v8_str(
"context0"),
12977 calling_context0->Global());
12978 CompileRun(
"function f() { context0.callback() }");
12979 calling_context1->Exit();
12983 calling_context2->Enter();
12984 calling_context2->Global()->Set(v8_str(
"context1"),
12985 calling_context1->Global());
12986 CompileRun(
"context1.f()");
12987 calling_context2->Exit();
12993 calling_context0.
Clear();
12994 calling_context1.
Clear();
12995 calling_context2.
Clear();
13002 i::FLAG_es52_globals =
true;
13006 CompileRun(
"__proto__.x = 42");
13027 CHECK(!obj->
Get(foo_string)->IsUndefined());
13036 CompileRun(
"function f(obj) { return obj.x; }\n"
13037 "var obj = { x: { foo: 42 }, y: 87 };\n"
13040 "for (var i = 0; i < 5; i++) f(obj);");
13045 CHECK_EQ(42, CompileRun(
"f(this).foo")->Int32Value());
13052 const int kElementCount = 260;
13053 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
13056 FACTORY->NewExternalArray(kElementCount,
13061 for (
int i = 0; i < kElementCount; i++) {
13062 pixels->set(i, i % 256);
13066 for (
int i = 0; i < kElementCount; i++) {
13067 CHECK_EQ(i % 256, pixels->get_scalar(i));
13078 context->
Global()->Set(v8_str(
"pixels"), obj);
13081 result = CompileRun(
"pixels[1]");
13082 CHECK_EQ(1, result->Int32Value());
13084 result = CompileRun(
"var sum = 0;"
13085 "for (var i = 0; i < 8; i++) {"
13086 " sum += pixels[i] = pixels[i] = -i;"
13089 CHECK_EQ(-28, result->Int32Value());
13091 result = CompileRun(
"var sum = 0;"
13092 "for (var i = 0; i < 8; i++) {"
13093 " sum += pixels[i] = pixels[i] = 0;"
13096 CHECK_EQ(0, result->Int32Value());
13098 result = CompileRun(
"var sum = 0;"
13099 "for (var i = 0; i < 8; i++) {"
13100 " sum += pixels[i] = pixels[i] = 255;"
13103 CHECK_EQ(8 * 255, result->Int32Value());
13105 result = CompileRun(
"var sum = 0;"
13106 "for (var i = 0; i < 8; i++) {"
13107 " sum += pixels[i] = pixels[i] = 256 + i;"
13110 CHECK_EQ(2076, result->Int32Value());
13112 result = CompileRun(
"var sum = 0;"
13113 "for (var i = 0; i < 8; i++) {"
13114 " sum += pixels[i] = pixels[i] = i;"
13117 CHECK_EQ(28, result->Int32Value());
13119 result = CompileRun(
"var sum = 0;"
13120 "for (var i = 0; i < 8; i++) {"
13121 " sum += pixels[i];"
13124 CHECK_EQ(28, result->Int32Value());
13131 i::USE(no_failure);
13137 i::USE(no_failure);
13139 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
13144 i::USE(no_failure);
13147 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13148 " pixels[i] = (i * 65) - 109;"
13150 "pixels[1] + pixels[6];");
13151 CHECK_EQ(255, result->Int32Value());
13155 i::Smi::cast(jsobj->GetElement(2)->ToObjectChecked())->value());
13157 i::Smi::cast(jsobj->GetElement(3)->ToObjectChecked())->value());
13159 i::Smi::cast(jsobj->GetElement(4)->ToObjectChecked())->value());
13161 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13163 i::Smi::cast(jsobj->GetElement(6)->ToObjectChecked())->value());
13165 i::Smi::cast(jsobj->GetElement(7)->ToObjectChecked())->value());
13166 result = CompileRun(
"var sum = 0;"
13167 "for (var i = 0; i < 8; i++) {"
13168 " sum += pixels[i];"
13171 CHECK_EQ(984, result->Int32Value());
13173 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13174 " pixels[i] = (i * 1.1);"
13176 "pixels[1] + pixels[6];");
13177 CHECK_EQ(8, result->Int32Value());
13187 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13188 " pixels[7] = undefined;"
13191 CHECK_EQ(0, result->Int32Value());
13194 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13195 " pixels[6] = '2.3';"
13198 CHECK_EQ(2, result->Int32Value());
13201 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13202 " pixels[5] = NaN;"
13205 CHECK_EQ(0, result->Int32Value());
13208 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13209 " pixels[8] = Infinity;"
13212 CHECK_EQ(255, result->Int32Value());
13214 i::Smi::cast(jsobj->GetElement(8)->ToObjectChecked())->value());
13216 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13217 " pixels[9] = -Infinity;"
13220 CHECK_EQ(0, result->Int32Value());
13223 result = CompileRun(
"pixels[3] = 33;"
13224 "delete pixels[3];"
13226 CHECK_EQ(33, result->Int32Value());
13228 result = CompileRun(
"pixels[0] = 10; pixels[1] = 11;"
13229 "pixels[2] = 12; pixels[3] = 13;"
13230 "pixels.__defineGetter__('2',"
13231 "function() { return 120; });"
13233 CHECK_EQ(12, result->Int32Value());
13235 result = CompileRun(
"var js_array = new Array(40);"
13236 "js_array[0] = 77;"
13240 result = CompileRun(
"pixels[1] = 23;"
13241 "pixels.__proto__ = [];"
13242 "js_array.__proto__ = pixels;"
13243 "js_array.concat(pixels);");
13247 result = CompileRun(
"pixels[1] = 23;");
13248 CHECK_EQ(23, result->Int32Value());
13252 result = CompileRun(
"pixels[256] = 255;");
13253 CHECK_EQ(255, result->Int32Value());
13254 result = CompileRun(
"var i = 0;"
13255 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
13257 CHECK_EQ(255, result->Int32Value());
13261 result = CompileRun(
"function pa_load(p) {"
13263 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13266 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13267 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
13268 "just_ints = new Object();"
13269 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13270 "for (var i = 0; i < 10; ++i) {"
13271 " result = pa_load(just_ints);"
13274 CHECK_EQ(32640, result->Int32Value());
13277 result = CompileRun(
"function pa_load(p, start) {"
13279 " for (var j = start; j < 256; j++) { sum += p[j]; }"
13282 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13283 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
13284 "for (var i = 0; i < 10; ++i) {"
13285 " result = pa_load(pixels,-10);"
13288 CHECK_EQ(0, result->Int32Value());
13291 result = CompileRun(
"function pa_load(p) {"
13293 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13296 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13297 "just_ints = new Object();"
13298 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13299 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
13300 "for (var i = 0; i < 10; ++i) {"
13301 " result = pa_load(pixels);"
13304 CHECK_EQ(32640, result->Int32Value());
13308 result = CompileRun(
"function pa_load(p, start) {"
13310 " for (var j = start; j < 256; j++) { sum += p[j]; }"
13313 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13314 "just_ints = new Object();"
13315 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13316 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
13317 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
13318 "for (var i = 0; i < 10; ++i) {"
13319 " result = pa_load(pixels,-10);"
13322 CHECK_EQ(0, result->Int32Value());
13327 result = CompileRun(
"function pa_load(p) {"
13329 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13332 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13333 "just_ints = new Object();"
13334 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13335 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
13336 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
13337 "sparse_array = new Object();"
13338 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
13339 "sparse_array[1000000] = 3;"
13340 "for (var i = 0; i < 10; ++i) {"
13341 " result = pa_load(sparse_array);"
13344 CHECK_EQ(32640, result->Int32Value());
13347 result = CompileRun(
"function pa_store(p) {"
13348 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
13350 "pa_store(pixels);"
13352 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13354 CHECK_EQ(48896, result->Int32Value());
13358 result = CompileRun(
"function pa_store(p,start) {"
13359 " for (var j = 0; j < 256; j++) {"
13360 " p[j+start] = j * 2;"
13363 "pa_store(pixels,0);"
13364 "pa_store(pixels,-128);"
13366 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13368 CHECK_EQ(65280, result->Int32Value());
13372 result = CompileRun(
"function pa_store(p,start) {"
13373 " for (var j = 0; j < 256; j++) {"
13374 " p[j+start] = j * 2;"
13377 "pa_store(pixels,0);"
13378 "just_ints = new Object();"
13379 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13380 "pa_store(just_ints, 0);"
13381 "pa_store(pixels,-128);"
13383 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13385 CHECK_EQ(65280, result->Int32Value());
13389 result = CompileRun(
"function pa_store(p) {"
13390 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
13392 "pa_store(pixels);"
13393 "just_ints = new Object();"
13394 "pa_store(just_ints);"
13395 "pa_store(pixels);"
13397 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13399 CHECK_EQ(48896, result->Int32Value());
13402 result = CompileRun(
"function pa_load(p) {"
13404 " for (var i=0; i<256; ++i) {"
13409 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13410 "for (var i = 0; i < 5000; ++i) {"
13411 " result = pa_load(pixels);"
13414 CHECK_EQ(32640, result->Int32Value());
13417 result = CompileRun(
"function pa_init(p) {"
13418 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
13420 "function pa_load(p) {"
13422 " for (var i=0; i<256; ++i) {"
13427 "for (var i = 0; i < 5000; ++i) {"
13428 " pa_init(pixels);"
13430 "result = pa_load(pixels);"
13432 CHECK_EQ(32640, result->Int32Value());
13441 for (
int size = 0; size < 100; size += 10) {
13442 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(size));
13455 const AccessorInfo& info) {
13463 Local<Value> value,
13464 const AccessorInfo& info) {
13473 const int kElementCount = 260;
13474 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
13477 FACTORY->NewExternalArray(kElementCount,
13480 for (
int i = 0; i < kElementCount; i++) {
13481 pixels->set(i, i % 256);
13485 NotHandledIndexedPropertySetter);
13488 context->
Global()->Set(v8_str(
"pixels"), obj);
13491 result = CompileRun(
"var sum = 0;"
13492 "for (var i = 0; i < 8; i++) {"
13493 " sum += pixels[i] = pixels[i] = -i;"
13496 CHECK_EQ(-28, result->Int32Value());
13497 result = CompileRun(
"pixels.hasOwnProperty('1')");
13498 CHECK(result->BooleanValue());
13504 switch (array_type) {
13531 template <
class ExternalArrayClass,
class ElementType>
13537 const int kElementCount = 40;
13538 int element_size = ExternalArrayElementSize(array_type);
13539 ElementType* array_data =
13540 static_cast<ElementType*
>(malloc(kElementCount * element_size));
13543 FACTORY->NewExternalArray(kElementCount, array_type, array_data));
13546 for (
int i = 0; i < kElementCount; i++) {
13547 array->set(i, static_cast<ElementType>(i));
13551 for (
int i = 0; i < kElementCount; i++) {
13553 static_cast<int64_t>(array->get_scalar(i)));
13554 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
13564 1, static_cast<int>(jsobj->GetElement(1)->ToObjectChecked()->Number()));
13566 context->
Global()->Set(v8_str(
"ext_array"), obj);
13569 result = CompileRun(
"ext_array[1]");
13570 CHECK_EQ(1, result->Int32Value());
13573 result = CompileRun(
"var sum = 0;"
13574 "for (var i = 0; i < 8; i++) {"
13575 " sum += ext_array[i] = ext_array[i] = -i;"
13578 CHECK_EQ(-28, result->Int32Value());
13581 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13582 " ext_array[i] = i;"
13585 "for (var i = 0; i < 8; i++) {"
13586 " sum += ext_array[i];"
13589 CHECK_EQ(28, result->Int32Value());
13592 result = CompileRun(
"for (var i = 8; --i >= 0; ) {"
13593 " ext_array[i] = i;"
13596 "for (var i = 0; i < 8; i++) {"
13597 " sum += ext_array[i];"
13600 CHECK_EQ(28, result->Int32Value());
13603 result = CompileRun(
"var sum = 0;"
13604 "for (var i = 0; i < 16; i+=2) {"
13605 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);"
13608 CHECK_EQ(-28, result->Int32Value());
13611 result = CompileRun(
"for (var i = 0; i < 16; i+=2) {"
13612 " ext_array[i] = (i * 0.5);"
13615 "for (var i = 0; i < 16; i+=2) {"
13616 " sum += ext_array[i];"
13619 CHECK_EQ(28, result->Int32Value());
13622 result = CompileRun(
"for (var i = 14; i >= 0; i-=2) {"
13623 " ext_array[i] = (i * 0.5);"
13626 "for (var i = 0; i < 16; i+=2) {"
13627 " sum += ext_array[i];"
13630 CHECK_EQ(28, result->Int32Value());
13636 const char* boundary_program =
13638 "for (var i = 0; i < 16; i++) {"
13639 " ext_array[i] = %lld;"
13641 " res = ext_array[i];"
13648 result = CompileRun(test_buf.start());
13649 CHECK_EQ(low, result->IntegerValue());
13654 result = CompileRun(test_buf.start());
13655 CHECK_EQ(high, result->IntegerValue());
13658 result = CompileRun(
"var tmp_array = ext_array;"
13660 "for (var i = 0; i < 8; i++) {"
13661 " tmp_array[i] = i;"
13662 " sum += tmp_array[i];"
13670 CHECK_EQ(28, result->Int32Value());
13674 "var caught_exception = false;"
13678 " caught_exception = true;"
13680 "caught_exception;",
13682 result = CompileRun(test_buf.start());
13683 CHECK_EQ(
false, result->BooleanValue());
13687 "var caught_exception = false;"
13689 " ext_array[%d] = 1;"
13691 " caught_exception = true;"
13693 "caught_exception;",
13695 result = CompileRun(test_buf.start());
13696 CHECK_EQ(
false, result->BooleanValue());
13699 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13700 " ext_array[7] = undefined;"
13703 CHECK_EQ(0, result->Int32Value());
13708 static_cast<int>(jsobj->GetElement(7)->ToObjectChecked()->Number()));
13711 jsobj->GetElement(7)->ToObjectChecked()->Number()));
13714 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13715 " ext_array[6] = '2.3';"
13718 CHECK_EQ(2, result->Int32Value());
13720 2, static_cast<int>(jsobj->GetElement(6)->ToObjectChecked()->Number()));
13726 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13727 " ext_array[i] = 5;"
13729 "for (var i = 0; i < 8; i++) {"
13730 " ext_array[i] = NaN;"
13733 CHECK_EQ(0, result->Int32Value());
13735 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13737 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13738 " ext_array[i] = 5;"
13740 "for (var i = 0; i < 8; i++) {"
13741 " ext_array[i] = Infinity;"
13744 int expected_value =
13746 CHECK_EQ(expected_value, result->Int32Value());
13748 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13750 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
13751 " ext_array[i] = 5;"
13753 "for (var i = 0; i < 8; i++) {"
13754 " ext_array[i] = -Infinity;"
13757 CHECK_EQ(0, result->Int32Value());
13759 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
13762 const char* unsigned_data =
13763 "var source_data = [0.6, 10.6];"
13764 "var expected_results = [0, 10];";
13765 const char* signed_data =
13766 "var source_data = [0.6, 10.6, -0.6, -10.6];"
13767 "var expected_results = [0, 10, 0, -10];";
13768 const char* pixel_data =
13769 "var source_data = [0.6, 10.6];"
13770 "var expected_results = [1, 11];";
13779 "var all_passed = true;"
13780 "for (var i = 0; i < source_data.length; i++) {"
13781 " for (var j = 0; j < 8; j++) {"
13782 " ext_array[j] = source_data[i];"
13784 " all_passed = all_passed &&"
13785 " (ext_array[5] == expected_results[i]);"
13790 (is_pixel_data ? pixel_data : signed_data)));
13791 result = CompileRun(test_buf.start());
13792 CHECK_EQ(
true, result->BooleanValue());
13795 for (
int i = 0; i < kElementCount; i++) {
13796 array->set(i, static_cast<ElementType>(i));
13799 result = CompileRun(
"function ee_op_test_complex_func(sum) {"
13800 " for (var i = 0; i < 40; ++i) {"
13801 " sum += (ext_array[i] += 1);"
13802 " sum += (ext_array[i] -= 1);"
13807 "for (var i=0;i<10000;++i) {"
13808 " sum=ee_op_test_complex_func(sum);"
13811 CHECK_EQ(16000000, result->Int32Value());
13814 result = CompileRun(
"function ee_op_test_count_func(sum) {"
13815 " for (var i = 0; i < 40; ++i) {"
13816 " sum += (++ext_array[i]);"
13817 " sum += (--ext_array[i]);"
13822 "for (var i=0;i<10000;++i) {"
13823 " sum=ee_op_test_count_func(sum);"
13826 CHECK_EQ(16000000, result->Int32Value());
13828 result = CompileRun(
"ext_array[3] = 33;"
13829 "delete ext_array[3];"
13831 CHECK_EQ(33, result->Int32Value());
13833 result = CompileRun(
"ext_array[0] = 10; ext_array[1] = 11;"
13834 "ext_array[2] = 12; ext_array[3] = 13;"
13835 "ext_array.__defineGetter__('2',"
13836 "function() { return 120; });"
13838 CHECK_EQ(12, result->Int32Value());
13840 result = CompileRun(
"var js_array = new Array(40);"
13841 "js_array[0] = 77;"
13845 result = CompileRun(
"ext_array[1] = 23;"
13846 "ext_array.__proto__ = [];"
13847 "js_array.__proto__ = ext_array;"
13848 "js_array.concat(ext_array);");
13852 result = CompileRun(
"ext_array[1] = 23;");
13853 CHECK_EQ(23, result->Int32Value());
13860 const int kXSize = 300;
13861 const int kYSize = 300;
13862 const int kLargeElementCount = kXSize * kYSize * 4;
13863 ElementType* large_array_data =
13864 static_cast<ElementType*
>(malloc(kLargeElementCount * element_size));
13869 kLargeElementCount);
13870 context->
Global()->Set(v8_str(
"large_array"), large_obj);
13872 for (
int x = 0; x < 300; x++) {
13874 int offset = row * 300 * 4;
13875 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13876 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13877 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13878 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13880 offset = row * 300 * 4;
13881 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13882 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13883 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13884 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13886 offset = row * 300 * 4;
13887 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
13888 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
13889 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
13890 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
13896 result = CompileRun(
"var failed = false;"
13898 "for (var i = 0; i < 300; i++) {"
13899 " if (large_array[4 * i] != 127 ||"
13900 " large_array[4 * i + 1] != 0 ||"
13901 " large_array[4 * i + 2] != 0 ||"
13902 " large_array[4 * i + 3] != 127) {"
13906 "offset = 150 * 300 * 4;"
13907 "for (var i = 0; i < 300; i++) {"
13908 " if (large_array[offset + 4 * i] != 127 ||"
13909 " large_array[offset + 4 * i + 1] != 0 ||"
13910 " large_array[offset + 4 * i + 2] != 0 ||"
13911 " large_array[offset + 4 * i + 3] != 127) {"
13915 "offset = 298 * 300 * 4;"
13916 "for (var i = 0; i < 300; i++) {"
13917 " if (large_array[offset + 4 * i] != 127 ||"
13918 " large_array[offset + 4 * i + 1] != 0 ||"
13919 " large_array[offset + 4 * i + 2] != 0 ||"
13920 " large_array[offset + 4 * i + 3] != 127) {"
13925 CHECK_EQ(
true, result->BooleanValue());
13926 free(large_array_data);
13933 result = CompileRun(
"ext_array[''] = 23; ext_array['']");
13934 CHECK_EQ(23, result->Int32Value());
13945 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13946 result = CompileRun(
"ext_array['']");
13947 CHECK_EQ(1503, result->Int32Value());
13959 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13960 result = CompileRun(
"ext_array['']");
13961 CHECK_EQ(1503, result->Int32Value());
13973 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13974 result = CompileRun(
"ext_array['']");
13985 context->
Global()->Set(v8_str(
"ext_array"), obj2);
13986 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
13987 "ext_array['']();");
13996 context->
Global()->Set(v8_str(
"ext_array"), obj3);
14013 context->
Global()->Set(v8_str(
"ext_array"), obj2);
14014 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
14015 "ext_array['']();");
14023 ExternalArrayTestHelper<i::ExternalByteArray, int8_t>(
14031 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>(
14039 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
14047 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
14055 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>(
14063 ExternalArrayTestHelper<i::ExternalIntArray, int32_t>(
14071 ExternalArrayTestHelper<i::ExternalUnsignedIntArray, uint32_t>(
14079 ExternalArrayTestHelper<i::ExternalFloatArray, float>(
14087 ExternalArrayTestHelper<i::ExternalDoubleArray, double>(
14095 TestExternalByteArray();
14096 TestExternalUnsignedByteArray();
14097 TestExternalShortArray();
14098 TestExternalUnsignedShortArray();
14099 TestExternalIntArray();
14100 TestExternalUnsignedIntArray();
14101 TestExternalFloatArray();
14108 for (
int size = 0; size < 100; size += 10) {
14109 int element_size = ExternalArrayElementSize(array_type);
14110 void* external_data = malloc(size * element_size);
14113 external_data, array_type, size);
14118 free(external_data);
14139 last_location = last_message =
NULL;
14174 const char *source =
"foo";
14191 const char *source =
"function foo() { FAIL.FAIL; }; foo();";
14197 CHECK(strstr(*stack,
"at foo (stack-trace-test") !=
NULL);
14203 const char* expected_func_name,
int expected_line_number,
14204 int expected_column,
bool is_eval,
bool is_constructor,
14209 if (*script_name ==
NULL) {
14213 CHECK(strstr(*script_name, expected_script_name) !=
NULL);
14215 CHECK(strstr(*func_name, expected_func_name) !=
NULL);
14225 const char* origin =
"capture-stack-trace-test";
14226 const int kOverviewTest = 1;
14227 const int kDetailedTest = 2;
14231 int testGroup = args[0]->Int32Value();
14232 if (testGroup == kOverviewTest) {
14248 }
else if (testGroup == kDetailedTest) {
14256 #ifdef ENABLE_DEBUGGER_SUPPORT
14257 bool is_eval =
true;
14258 #else // ENABLE_DEBUGGER_SUPPORT
14259 bool is_eval =
false;
14260 #endif // ENABLE_DEBUGGER_SUPPORT
14281 Local<ObjectTemplate> templ = ObjectTemplate::New();
14282 templ->Set(v8_str(
"AnalyzeStackInNativeCode"),
14288 const char *overview_source =
14289 "function bar() {\n"
14290 " var y; AnalyzeStackInNativeCode(1);\n"
14292 "function foo() {\n"
14296 "var x;eval('new foo();');";
14304 const char *detailed_source =
14305 "function bat() {AnalyzeStackInNativeCode(2);\n"
14308 "function baz() {\n"
14311 "eval('new baz();');";
14320 CHECK(!detailed_result.IsEmpty());
14321 CHECK(detailed_result->IsObject());
14325 static void StackTraceForUncaughtExceptionListener(
14336 TEST(CaptureStackTraceForUncaughtException) {
14343 Script::Compile(v8_str(
"function foo() {\n"
14346 "function bar() {\n"
14349 v8_str(
"origin"))->Run();
14351 Local<Value> trouble = global->
Get(v8_str(
"bar"));
14352 CHECK(trouble->IsFunction());
14353 Function::Cast(*trouble)->Call(global, 0,
NULL);
14359 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
14367 "var setters = ['column', 'lineNumber', 'scriptName',\n"
14368 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
14369 " 'isConstructor'];\n"
14370 "for (var i = 0; i < setters.length; i++) {\n"
14371 " var prop = setters[i];\n"
14372 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n"
14374 CompileRun(
"throw 'exception';");
14386 int line_number[] = {1, 2, 5};
14387 for (
int i = 0; i < frame_count; i++) {
14402 const char* source =
14403 "function g() { error; } \n"
14404 "function f() { g(); } \n"
14405 "function t(e) { throw e; } \n"
14408 "} catch (e1) { \n"
14411 " } catch (e2) { \n"
14417 CompileRun(source);
14429 int line_number[] = {3, 7};
14430 for (
int i = 0; i < frame_count; i++) {
14442 const char* source =
14443 "function g() { throw 404; } \n"
14444 "function f() { g(); } \n"
14445 "function t(e) { throw e; } \n"
14448 "} catch (e1) { \n"
14453 CompileRun(source);
14474 const char* source =
14475 "var e = new Error(); \n"
14479 CompileRun(source);
14499 const char* source =
14500 "var e = {__proto__: new Error()} \n"
14504 CompileRun(source);
14516 for (
int i = 0; i < 3; i++) {
14518 stackTrace->
GetFrame(i)->GetScriptNameOrSourceURL();
14528 Local<ObjectTemplate> templ = ObjectTemplate::New();
14529 templ->Set(v8_str(
"AnalyzeStackOfEvalWithSourceURL"),
14533 const char *source =
14534 "function outer() {\n"
14535 "function bar() {\n"
14536 " AnalyzeStackOfEvalWithSourceURL();\n"
14538 "function foo() {\n"
14544 "eval('(' + outer +')()//@ sourceURL=eval_url');";
14545 CHECK(CompileRun(source)->IsUndefined());
14556 for (
int i = 0; i < 3; i++) {
14558 stackTrace->
GetFrame(i)->GetScriptNameOrSourceURL();
14566 TEST(InlineScriptWithSourceURLInStackTrace) {
14568 Local<ObjectTemplate> templ = ObjectTemplate::New();
14569 templ->Set(v8_str(
"AnalyzeStackOfInlineScriptWithSourceURL"),
14574 const char *source =
14575 "function outer() {\n"
14576 "function bar() {\n"
14577 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
14579 "function foo() {\n"
14586 "//@ sourceURL=source_url";
14587 CHECK(CompileRunWithOrigin(source,
"url", 0, 1)->IsUndefined());
14598 for (
int i = 0; i < 3; i++) {
14600 stackTrace->
GetFrame(i)->GetScriptNameOrSourceURL();
14608 TEST(DynamicWithSourceURLInStackTrace) {
14610 Local<ObjectTemplate> templ = ObjectTemplate::New();
14611 templ->Set(v8_str(
"AnalyzeStackOfDynamicScriptWithSourceURL"),
14616 const char *source =
14617 "function outer() {\n"
14618 "function bar() {\n"
14619 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
14621 "function foo() {\n"
14628 "//@ sourceURL=source_url";
14629 CHECK(CompileRunWithOrigin(source,
"url", 0, 0)->IsUndefined());
14632 static void CreateGarbageInOldSpace() {
14635 for (
int i = 0; i < 1000; i++) {
14642 const intptr_t
MB = 1024 * 1024;
14645 intptr_t initial_size =
HEAP->SizeOfObjects();
14646 CreateGarbageInOldSpace();
14647 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14648 CHECK_GT(size_with_garbage, initial_size + MB);
14649 bool finished =
false;
14650 for (
int i = 0; i < 200 && !finished; i++) {
14653 intptr_t final_size =
HEAP->SizeOfObjects();
14655 CHECK_LT(final_size, initial_size + 1);
14661 const intptr_t
MB = 1024 * 1024;
14662 const int IdlePauseInMs = 900;
14665 intptr_t initial_size =
HEAP->SizeOfObjects();
14666 CreateGarbageInOldSpace();
14667 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14668 CHECK_GT(size_with_garbage, initial_size + MB);
14669 bool finished =
false;
14670 for (
int i = 0; i < 200 && !finished; i++) {
14673 intptr_t final_size =
HEAP->SizeOfObjects();
14675 CHECK_LT(final_size, initial_size + 1);
14681 const intptr_t
MB = 1024 * 1024;
14682 const int IdlePauseInMs = 900;
14685 intptr_t initial_size =
HEAP->SizeOfObjects();
14686 CreateGarbageInOldSpace();
14687 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14688 CHECK_GT(size_with_garbage, initial_size + MB);
14689 bool finished =
false;
14690 for (
int i = 0; i < 200 && !finished; i++) {
14693 intptr_t final_size =
HEAP->SizeOfObjects();
14695 CHECK_LT(final_size, initial_size + 1);
14700 const intptr_t
MB = 1024 * 1024;
14701 const int kShortIdlePauseInMs = 100;
14702 const int kLongIdlePauseInMs = 1000;
14705 intptr_t initial_size =
HEAP->SizeOfObjects();
14709 for (
int i = 0; i < 7; i++) {
14712 CreateGarbageInOldSpace();
14719 CreateGarbageInOldSpace();
14720 intptr_t size_with_garbage =
HEAP->SizeOfObjects();
14721 CHECK_GT(size_with_garbage, initial_size + MB);
14722 bool finished =
false;
14723 for (
int i = 0; i < 200 && !finished; i++) {
14726 intptr_t final_size =
HEAP->SizeOfObjects();
14727 CHECK_LT(final_size, initial_size + 1);
14730 static uint32_t* stack_limit;
14733 stack_limit =
reinterpret_cast<uint32_t*
>(
14734 i::Isolate::Current()->stack_guard()->real_climit());
14742 static uint32_t* ComputeStackLimit(uint32_t size) {
14743 uint32_t* answer = &size - (size /
sizeof(size));
14748 if (answer > &size)
return reinterpret_cast<uint32_t*
>(
sizeof(size));
14754 static const int K = 1024;
14755 uint32_t* set_limit = ComputeStackLimit(128 * K);
14765 Local<v8::FunctionTemplate> fun_templ =
14767 Local<Function> fun = fun_templ->GetFunction();
14768 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
14769 CompileRun(
"get_stack_limit();");
14771 CHECK(stack_limit == set_limit);
14776 uint32_t* set_limit;
14779 static const int K = 1024;
14780 set_limit = ComputeStackLimit(128 * K);
14790 Local<v8::FunctionTemplate> fun_templ =
14792 Local<Function> fun = fun_templ->GetFunction();
14793 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
14794 CompileRun(
"get_stack_limit();");
14796 CHECK(stack_limit == set_limit);
14800 CHECK(stack_limit == set_limit);
14822 found_resource1_(
false),
14823 found_resource2_(
false) {}
14831 string->GetExternalStringResource();
14833 if (resource1_ == resource) {
14834 CHECK(!found_resource1_);
14835 found_resource1_ =
true;
14837 if (resource2_ == resource) {
14838 CHECK(!found_resource2_);
14839 found_resource2_ =
true;
14843 CHECK(found_resource1_);
14844 CHECK(found_resource2_);
14850 bool found_resource1_;
14851 bool found_resource2_;
14857 const char*
string =
"Some string";
14858 uint16_t* two_byte_string = AsciiToTwoByteString(
string);
14870 visitor.CheckVisitedResources();
14874 static double DoubleFromBits(uint64_t value) {
14876 memcpy(&target, &value,
sizeof(target));
14881 static uint64_t DoubleToBits(
double value) {
14883 memcpy(&target, &value,
sizeof(target));
14888 static double DoubleToDateTime(
double input) {
14889 double date_limit = 864e13;
14890 if (IsNaN(input) || input < -date_limit || input > date_limit) {
14893 return (input < 0) ? -(floor(-input)) : floor(input);
14898 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
14899 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
14909 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
14910 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
14911 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
14912 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
14913 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
14914 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
14915 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
14919 double date_limit = 864e13;
14921 double test_values[] = {
14943 int num_test_values = 20;
14945 for (
int i = 0; i < num_test_values; i++) {
14946 double test_value = test_values[i];
14951 if (!IsNaN(test_value)) {
14952 CHECK_EQ(test_value, stored_number);
14954 uint64_t stored_bits = DoubleToBits(stored_number);
14956 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
14959 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
14961 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
14968 double expected_stored_date = DoubleToDateTime(test_value);
14970 if (!IsNaN(expected_stored_date)) {
14971 CHECK_EQ(expected_stored_date, stored_date);
14973 uint64_t stored_bits = DoubleToBits(stored_date);
14975 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
14978 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
14980 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
15010 " toString: function () {"
15022 CHECK_EQ(0, strcmp(*value,
"Hey!"));
15036 other_context = Context::New();
15040 const char* source_simple =
"1";
15041 context = Context::New();
15047 context->SetData(obj);
15048 CompileRun(source_simple);
15053 for (gc_count = 1; gc_count < 10; gc_count++) {
15054 other_context->Enter();
15055 CompileRun(source_simple);
15056 other_context->Exit();
15058 if (GetGlobalObjectsCount() == 1)
break;
15061 CHECK_EQ(1, GetGlobalObjectsCount());
15065 const char* source_eval =
"function f(){eval('1')}; f()";
15066 context = Context::New();
15071 CompileRun(source_eval);
15076 for (gc_count = 1; gc_count < 10; gc_count++) {
15077 other_context->Enter();
15078 CompileRun(source_eval);
15079 other_context->Exit();
15081 if (GetGlobalObjectsCount() == 1)
break;
15084 CHECK_EQ(1, GetGlobalObjectsCount());
15088 const char* source_exception =
"function f(){throw 1;} f()";
15089 context = Context::New();
15095 CompileRun(source_exception);
15098 CHECK(!message.IsEmpty());
15099 CHECK_EQ(1, message->GetLineNumber());
15104 for (gc_count = 1; gc_count < 10; gc_count++) {
15105 other_context->Enter();
15106 CompileRun(source_exception);
15107 other_context->Exit();
15109 if (GetGlobalObjectsCount() == 1)
break;
15112 CHECK_EQ(1, GetGlobalObjectsCount());
15124 "function f() {}\n\nfunction g() {}");
15137 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
15145 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
15157 "function f() {}\n\nfunction g() {}");
15174 "function foo() {}\n\n function bar() {}");
15191 "function foo() {}\n\n function bar() {}");
15204 const AccessorInfo& info) {
15205 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15206 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15211 static void SetterWhichSetsYOnThisTo23(Local<String> name,
15212 Local<Value> value,
15213 const AccessorInfo& info) {
15214 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15215 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15216 info.This()->Set(v8_str(
"y"), v8_num(23));
15221 const AccessorInfo& info) {
15222 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15223 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15224 if (!name->Equals(v8_str(
"foo")))
return Handle<Value>();
15230 Local<Value> value,
15231 const AccessorInfo& info) {
15232 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15233 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15234 if (!name->Equals(v8_str(
"foo")))
return Handle<Value>();
15235 info.This()->Set(v8_str(
"y"), v8_num(23));
15242 Local<ObjectTemplate> templ = ObjectTemplate::New();
15243 templ->SetAccessor(v8_str(
"x"),
15244 GetterWhichReturns42,
15245 SetterWhichSetsYOnThisTo23);
15247 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
15248 CompileRun(
"function C1() {"
15251 "C1.prototype = P;"
15255 "C2.prototype = { };"
15256 "C2.prototype.__proto__ = P;");
15260 for (
int i = 0; i < 10; i++) {
15262 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
15263 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
15267 for (
int i = 0; i < 10; i++) {
15269 CHECK_EQ(42, c2->
Get(v8_str(
"x"))->Int32Value());
15270 CHECK_EQ(23, c2->
Get(v8_str(
"y"))->Int32Value());
15276 Local<String> name,
const AccessorInfo& info) {
15282 Local<String> name, Local<Value> value,
const AccessorInfo& info) {
15283 if (name->Equals(v8_str(
"x"))) {
15284 info.This()->Set(v8_str(
"y"), v8_num(23));
15292 Local<ObjectTemplate> templ = ObjectTemplate::New();
15293 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
15294 NamedPropertySetterWhichSetsYOnThisTo23);
15296 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
15297 CompileRun(
"function C1() {"
15300 "C1.prototype = P;"
15304 "C2.prototype = { };"
15305 "C2.prototype.__proto__ = P;");
15309 for (
int i = 0; i < 10; i++) {
15311 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
15312 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
15316 for (
int i = 0; i < 10; i++) {
15318 CHECK_EQ(23, c2->
Get(v8_str(
"x"))->Int32Value());
15319 CHECK_EQ(42, c2->
Get(v8_str(
"y"))->Int32Value());
15325 const char* source =
"function C1() {"
15328 "C1.prototype = P;";
15336 prototype->
Set(v8_str(
"y"), v8_num(42));
15337 context->
Global()->Set(v8_str(
"P"), prototype);
15340 CompileRun(source);
15345 for (
int i = 0; i < 256; i++) {
15347 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
15348 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
15352 Local<ObjectTemplate> templ = ObjectTemplate::New();
15353 templ->SetAccessor(v8_str(
"x"),
15354 GetterWhichReturns42,
15355 SetterWhichSetsYOnThisTo23);
15356 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
15359 CompileRun(source);
15362 for (
int i = 0; i < 10; i++) {
15364 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
15365 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
15405 CHECK_EQ(1, prologue_call_count_second);
15406 CHECK_EQ(1, epilogue_call_count_second);
15412 CHECK_EQ(2, prologue_call_count_second);
15413 CHECK_EQ(2, epilogue_call_count_second);
15419 CHECK_EQ(2, prologue_call_count_second);
15420 CHECK_EQ(2, epilogue_call_count_second);
15425 i::FLAG_allow_natives_syntax =
true;
15434 " var r0 = %_GetFromCache(0, key0);"
15435 " var r1 = %_GetFromCache(0, key1);"
15436 " var r0_ = %_GetFromCache(0, key0);"
15438 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
15439 " var r1_ = %_GetFromCache(0, key1);"
15441 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
15442 " return 'PASSED';"
15444 HEAP->ClearJSFunctionResultCaches();
15445 ExpectString(code,
"PASSED");
15449 static const int k0CacheSize = 16;
15452 i::FLAG_allow_natives_syntax =
true;
15460 " var r = %_GetFromCache(0, k);"
15461 " for (var i = 0; i < 16; i++) {"
15462 " %_GetFromCache(0, 'a' + i);"
15464 " if (r === %_GetFromCache(0, k))"
15465 " return 'FAILED: k0CacheSize is too small';"
15466 " return 'PASSED';"
15468 HEAP->ClearJSFunctionResultCaches();
15469 ExpectString(code,
"PASSED");
15474 i::FLAG_allow_natives_syntax =
true;
15482 " for (var i = 0; i < 16; i++) keys.push(i);"
15483 " var values = [];"
15484 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15485 " for (var i = 0; i < 16; i++) {"
15486 " var v = %_GetFromCache(0, keys[i]);"
15487 " if (v.toString() !== values[i].toString())"
15488 " return 'Wrong value for ' + "
15489 " keys[i] + ': ' + v + ' vs. ' + values[i];"
15491 " return 'PASSED';"
15493 HEAP->ClearJSFunctionResultCaches();
15494 ExpectString(code,
"PASSED");
15499 i::FLAG_allow_natives_syntax =
true;
15507 " for (var i = 0; i < 16; i++) keys.push(i);"
15508 " var values = [];"
15509 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15510 " for (var i = 15; i >= 16; i--) {"
15511 " var v = %_GetFromCache(0, keys[i]);"
15512 " if (v !== values[i])"
15513 " return 'Wrong value for ' + "
15514 " keys[i] + ': ' + v + ' vs. ' + values[i];"
15516 " return 'PASSED';"
15518 HEAP->ClearJSFunctionResultCaches();
15519 ExpectString(code,
"PASSED");
15524 i::FLAG_allow_natives_syntax =
true;
15531 " for (var i = 0; i < 2*16; i++) {"
15532 " %_GetFromCache(0, 'a' + i);"
15534 " return 'PASSED';"
15536 HEAP->ClearJSFunctionResultCaches();
15537 ExpectString(code,
"PASSED");
15546 const char* init_code =
15547 "var str1 = 'abelspendabel';"
15548 "var str2 = str1 + str1 + str1;"
15550 Local<Value> result = CompileRun(init_code);
15552 Local<Value> indexof = CompileRun(
"str2.indexOf('els')");
15553 Local<Value> lastindexof = CompileRun(
"str2.lastIndexOf('dab')");
15555 CHECK(result->IsString());
15557 int length =
string->length();
15558 CHECK(string->IsAsciiRepresentation());
15563 CHECK(string->IsAsciiRepresentation());
15564 CHECK(flat_string->IsAsciiRepresentation());
15570 uc16_buffer[length] = 0;
15574 flat_string->MakeExternal(&resource);
15576 CHECK(flat_string->IsTwoByteRepresentation());
15583 CHECK(string->IsAsciiRepresentation());
15585 CHECK_EQ(0, cons->second()->length());
15586 CHECK(cons->first()->IsTwoByteRepresentation());
15591 Local<Value> reresult = CompileRun(
"str2.match(/abel/g).length;");
15592 CHECK_EQ(6, reresult->Int32Value());
15595 reresult = CompileRun(
"str2.match(/abe./g).length;");
15596 CHECK_EQ(6, reresult->Int32Value());
15598 reresult = CompileRun(
"str2.search(/bel/g);");
15599 CHECK_EQ(1, reresult->Int32Value());
15601 reresult = CompileRun(
"str2.search(/be./g);");
15602 CHECK_EQ(1, reresult->Int32Value());
15604 ExpectTrue(
"/bel/g.test(str2);");
15606 ExpectTrue(
"/be./g.test(str2);");
15608 reresult = CompileRun(
"/bel/g.exec(str2);");
15609 CHECK(!reresult->IsNull());
15611 reresult = CompileRun(
"/be./g.exec(str2);");
15612 CHECK(!reresult->IsNull());
15614 ExpectString(
"str2.substring(2, 10);",
"elspenda");
15616 ExpectString(
"str2.substring(2, 20);",
"elspendabelabelspe");
15618 ExpectString(
"str2.charAt(2);",
"e");
15620 ExpectObject(
"str2.indexOf('els');", indexof);
15622 ExpectObject(
"str2.lastIndexOf('dab');", lastindexof);
15624 reresult = CompileRun(
"str2.charCodeAt(2);");
15625 CHECK_EQ(static_cast<int32_t>(
'e'), reresult->Int32Value());
15632 Local<v8::Value> data) {
15650 IndexedGetAccessBlocker,
15656 context0->
Global()->Set(v8_str(
"x"), v8_num(42));
15662 context1->
Global()->Set(v8_str(
"other"), global0);
15665 ExpectUndefined(
"other.x");
15668 ExpectUndefined(
"other[0]");
15675 result = CompileRun(
"other[0] = new Object()");
15676 CHECK(result->IsObject());
15679 ExpectFalse(
"\'x\' in other");
15682 ExpectFalse(
"0 in other");
15685 ExpectFalse(
"delete other.x");
15695 ExpectUndefined(
"Object.prototype.__defineGetter__.call("
15696 " other, \'x\', function() { return 42; })");
15699 ExpectUndefined(
"Object.prototype.__lookupGetter__.call("
15703 ExpectFalse(
"Object.prototype.hasOwnProperty.call(other, \'0\')");
15717 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15718 printf(
"*** %s\n",
"DefaultIsolateGetCurrent success");
15725 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15726 CHECK(current_isolate != isolate);
15730 last_location = last_message =
NULL;
15741 ExpectString(
"'hello'",
"hello");
15742 current_isolate->
Enter();
15743 ExpectString(
"'still working'",
"still working");
15744 current_isolate->
Exit();
15745 ExpectString(
"'still working 2'",
"still working 2");
15746 current_isolate->
Exit();
15751 ExpectString(
"'still working 3'",
"still working 3");
15760 ExpectString(
"'run some V8'",
"run some V8");
15763 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
15764 last_location = last_message =
NULL;
15785 CompileRun(
"var foo = 153;");
15786 ExpectTrue(
"function f() { return foo == 153; }; f()");
15792 ExpectTrue(
"function f() {"
15804 last_location = last_message =
NULL;
15810 ExpectTrue(
"function f() { return bar == 371; }; f()");
15820 ExpectTrue(
"true");
15822 last_location = last_message =
NULL;
15839 CompileRun(
"var foo = 'isolate 1';");
15840 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15854 CompileRun(
"var foo = 'isolate 2';");
15855 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
15862 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15875 ExpectTrue(
"function f() {"
15883 "var isDefaultIsolate = true;"
15893 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
15899 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
15911 last_location = last_message =
NULL;
15925 ExpectTrue(
"function f() { return isDefaultIsolate; }; f()");
15929 static int CalcFibonacci(
v8::Isolate* isolate,
int limit) {
15935 " if (n <= 2) return 1;"
15936 " return fib(n-1) + fib(n-2);"
15939 Local<Value> value = CompileRun(code.start());
15940 CHECK(value->IsNumber());
15941 return static_cast<int>(value->NumberValue());
15947 :
Thread(
"IsolateThread"),
15949 fib_limit_(fib_limit),
15953 result_ = CalcFibonacci(isolate_, fib_limit_);
15964 TEST(MultipleIsolatesOnIndividualThreads) {
15994 Persistent<v8::Context> context;
16000 Local<Value> v = CompileRun(
"2");
16001 CHECK(v->IsNumber());
16002 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
16009 Local<Value> v = CompileRun(
"22");
16010 CHECK(v->IsNumber());
16011 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
16027 :
Thread(
"InitDefaultIsolateThread"),
16028 testCase_(testCase),
16032 switch (testCase_) {
16038 static const int K = 1024;
16080 TEST(InitializeDefaultIsolateOnSecondaryThread1) {
16084 TEST(InitializeDefaultIsolateOnSecondaryThread2) {
16088 TEST(InitializeDefaultIsolateOnSecondaryThread3) {
16092 TEST(InitializeDefaultIsolateOnSecondaryThread4) {
16096 TEST(InitializeDefaultIsolateOnSecondaryThread5) {
16100 TEST(InitializeDefaultIsolateOnSecondaryThread6) {
16107 "(function() { return \"a\".charAt(0); })()";
16113 ExpectString(code,
"a");
16114 ExpectString(code,
"a");
16122 CompileRun(
"String.prototype.charAt = function() { return \"not a\"; }");
16123 ExpectString(code,
"not a");
16130 "(function() { return (42).toString(); })()";
16136 ExpectString(code,
"42");
16137 ExpectString(code,
"42");
16145 CompileRun(
"Number.prototype.toString = function() { return \"not 42\"; }");
16146 ExpectString(code,
"not 42");
16153 "(function() { return true.toString(); })()";
16159 ExpectString(code,
"true");
16160 ExpectString(code,
"true");
16168 CompileRun(
"Boolean.prototype.toString = function() { return \"\"; }");
16169 ExpectString(code,
"");
16175 const char* function_code =
16176 "function readCell() { while (true) { return cell; } }";
16183 CompileRun(
"var cell = \"first\";");
16184 ExpectBoolean(
"delete cell",
false);
16185 CompileRun(function_code);
16186 ExpectString(
"readCell()",
"first");
16187 ExpectString(
"readCell()",
"first");
16194 CompileRun(
"cell = \"second\";");
16195 CompileRun(function_code);
16196 ExpectString(
"readCell()",
"second");
16197 ExpectBoolean(
"delete cell",
true);
16198 ExpectString(
"(function() {"
16200 " return readCell();"
16202 " return e.toString();"
16205 "ReferenceError: cell is not defined");
16206 CompileRun(
"cell = \"new_second\";");
16208 ExpectString(
"readCell()",
"new_second");
16209 ExpectString(
"readCell()",
"new_second");
16214 TEST(DontDeleteCellLoadICForceDelete) {
16215 const char* function_code =
16216 "function readCell() { while (true) { return cell; } }";
16222 CompileRun(
"var cell = \"value\";");
16223 ExpectBoolean(
"delete cell",
false);
16224 CompileRun(function_code);
16225 ExpectString(
"readCell()",
"value");
16226 ExpectString(
"readCell()",
"value");
16230 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
16231 ExpectString(
"(function() {"
16233 " return readCell();"
16235 " return e.toString();"
16238 "ReferenceError: cell is not defined");
16243 const char* function_code =
16244 "function readCell() { while (true) { return cell; } }";
16251 ExpectBoolean(
"delete cell",
false);
16252 CompileRun(function_code);
16253 ExpectString(
"readCell()",
"value");
16254 ExpectString(
"readCell()",
"value");
16258 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
16259 ExpectString(
"(function() {"
16261 " return readCell();"
16263 " return e.toString();"
16266 "ReferenceError: cell is not defined");
16277 if (class_id == 42) {
16278 CHECK(value->IsObject());
16281 CHECK_EQ(42, visited.WrapperClassId());
16297 CHECK_EQ(0,
object.WrapperClassId());
16298 object.SetWrapperClassId(42);
16299 CHECK_EQ(42,
object.WrapperClassId());
16321 CHECK(re->IsRegExp());
16322 CHECK(re->GetSource()->Equals(v8_str(
"bar")));
16324 static_cast<int>(re->GetFlags()));
16329 CHECK(re->IsRegExp());
16330 CHECK(re->GetSource()->Equals(v8_str(
"baz")));
16332 static_cast<int>(re->GetFlags()));
16335 CHECK(re->IsRegExp());
16336 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
16339 re = CompileRun(
"/quux/gm").As<
v8::RegExp>();
16340 CHECK(re->IsRegExp());
16341 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
16343 static_cast<int>(re->GetFlags()));
16347 CompileRun(
"RegExp = function() {}");
16350 CHECK(re->IsRegExp());
16351 CHECK(re->GetSource()->Equals(v8_str(
"foobar")));
16357 CHECK(re->IsRegExp());
16358 CHECK(re->GetSource()->Equals(v8_str(
"foobarbaz")));
16360 static_cast<int>(re->GetFlags()));
16362 context->
Global()->Set(v8_str(
"re"), re);
16363 ExpectTrue(
"re.test('FoobarbaZ')");
16372 CHECK(re.IsEmpty());
16373 CHECK(try_catch.HasCaught());
16374 context->
Global()->Set(v8_str(
"ex"), try_catch.Exception());
16375 ExpectTrue(
"ex instanceof SyntaxError");
16400 return v8_str(
"42!");
16406 result->
Set(0, v8_str(
"universalAnswer"));
16417 tmpl->SetNamedPropertyHandler(Getter,
NULL,
NULL,
NULL, Enumerator);
16418 context->
Global()->Set(v8_str(
"o"), tmpl->NewInstance());
16420 "var result = []; for (var k in o) result.push(k); result"));
16422 CHECK_EQ(v8_str(
"universalAnswer"), result->
Get(0));
16431 CompileRun(
"(function() {"
16432 " Object.defineProperty("
16435 " { configurable: true, enumerable: true, value: 3 });"
16436 "})").
As<Function>();
16438 define_property->
Call(proxy, 0,
NULL);
16443 Context::Scope scope(context);
16444 CompileRun(
"Object.prototype").As<
Object>()->
16450 CHECK_EQ(expected, object->Get(v8_str(
"context_id"))->Int32Value());
16455 HandleScope handle_scope;
16456 Persistent<Context> context1 = Context::New();
16457 InstallContextId(context1, 1);
16458 Persistent<Context> context2 = Context::New();
16459 InstallContextId(context2, 2);
16460 Persistent<Context> context3 = Context::New();
16461 InstallContextId(context3, 3);
16465 Local<Object> object1;
16466 Local<Function> func1;
16468 Context::Scope scope(context1);
16469 object1 = Object::New();
16470 func1 = tmpl->GetFunction();
16473 Local<Object> object2;
16474 Local<Function> func2;
16476 Context::Scope scope(context2);
16477 object2 = Object::New();
16478 func2 = tmpl->GetFunction();
16481 Local<Object> instance1;
16482 Local<Object> instance2;
16485 Context::Scope scope(context3);
16486 instance1 = func1->NewInstance();
16487 instance2 = func2->NewInstance();
16490 CHECK(object1->CreationContext() == context1);
16491 CheckContextId(object1, 1);
16492 CHECK(func1->CreationContext() == context1);
16493 CheckContextId(func1, 1);
16494 CHECK(instance1->CreationContext() == context1);
16495 CheckContextId(instance1, 1);
16496 CHECK(object2->CreationContext() == context2);
16497 CheckContextId(object2, 2);
16498 CHECK(func2->CreationContext() == context2);
16499 CheckContextId(func2, 2);
16500 CHECK(instance2->CreationContext() == context2);
16501 CheckContextId(instance2, 2);
16504 Context::Scope scope(context1);
16505 CHECK(object1->CreationContext() == context1);
16506 CheckContextId(object1, 1);
16507 CHECK(func1->CreationContext() == context1);
16508 CheckContextId(func1, 1);
16509 CHECK(instance1->CreationContext() == context1);
16510 CheckContextId(instance1, 1);
16511 CHECK(object2->CreationContext() == context2);
16512 CheckContextId(object2, 2);
16513 CHECK(func2->CreationContext() == context2);
16514 CheckContextId(func2, 2);
16515 CHECK(instance2->CreationContext() == context2);
16516 CheckContextId(instance2, 2);
16520 Context::Scope scope(context2);
16521 CHECK(object1->CreationContext() == context1);
16522 CheckContextId(object1, 1);
16523 CHECK(func1->CreationContext() == context1);
16524 CheckContextId(func1, 1);
16525 CHECK(instance1->CreationContext() == context1);
16526 CheckContextId(instance1, 1);
16527 CHECK(object2->CreationContext() == context2);
16528 CheckContextId(object2, 2);
16529 CHECK(func2->CreationContext() == context2);
16530 CheckContextId(func2, 2);
16531 CHECK(instance2->CreationContext() == context2);
16532 CheckContextId(instance2, 2);
16535 context1.Dispose();
16536 context2.Dispose();
16537 context3.Dispose();
16542 HandleScope handle_scope;
16543 Persistent<Context> context = Context::New();
16544 InstallContextId(context, 1);
16546 Local<Object>
function;
16548 Context::Scope scope(context);
16549 function = CompileRun(
"function foo() {}; foo").As<
Object>();
16552 CHECK(function->CreationContext() == context);
16553 CheckContextId(
function, 1);
16560 const AccessorInfo& info) {
16561 if (index == 42)
return v8_str(
"yes");
16562 return Handle<v8::Integer>();
16567 const AccessorInfo& info) {
16568 if (property->Equals(v8_str(
"foo")))
return v8_str(
"yes");
16569 return Handle<Value>();
16574 uint32_t index,
const AccessorInfo& info) {
16576 return Handle<v8::Integer>();
16581 Local<String> property,
const AccessorInfo& info) {
16582 if (property->Equals(v8_str(
"foo")))
return v8_num(1).
As<
v8::Integer>();
16583 return Handle<v8::Integer>();
16588 Local<String> property,
const AccessorInfo& info) {
16589 if (property->Equals(v8_str(
"bar")))
return v8_num(1).
As<
v8::Integer>();
16590 return Handle<v8::Integer>();
16595 const AccessorInfo& info) {
16596 return v8_str(
"yes");
16604 Handle<Value> value = CompileRun(
16607 " this.__defineGetter__('baz', function() { return 1; });"
16609 "function Bar() { "
16611 " this.__defineGetter__('bla', function() { return 2; });"
16613 "Bar.prototype = new Foo();"
16615 CHECK(value->IsObject());
16616 Handle<Object>
object = value->ToObject();
16617 CHECK(object->Has(v8_str(
"foo")));
16618 CHECK(!object->HasOwnProperty(v8_str(
"foo")));
16619 CHECK(object->HasOwnProperty(v8_str(
"bar")));
16620 CHECK(object->Has(v8_str(
"baz")));
16621 CHECK(!object->HasOwnProperty(v8_str(
"baz")));
16622 CHECK(object->HasOwnProperty(v8_str(
"bla")));
16625 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16627 Handle<Object> instance = templ->NewInstance();
16628 CHECK(!instance->HasOwnProperty(v8_str(
"42")));
16629 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
16630 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
16633 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16635 Handle<Object> instance = templ->NewInstance();
16636 CHECK(instance->HasOwnProperty(v8_str(
"42")));
16637 CHECK(!instance->HasOwnProperty(v8_str(
"43")));
16638 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
16641 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16643 Handle<Object> instance = templ->NewInstance();
16644 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
16645 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
16648 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16650 Handle<Object> instance = templ->NewInstance();
16651 CHECK(instance->HasOwnProperty(v8_str(
"42")));
16652 CHECK(!instance->HasOwnProperty(v8_str(
"41")));
16655 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16657 Handle<Object> instance = templ->NewInstance();
16658 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
16659 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
16662 Handle<ObjectTemplate> templ = ObjectTemplate::New();
16666 Handle<Object> instance = templ->NewInstance();
16667 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
16668 CHECK(instance->HasOwnProperty(v8_str(
"bar")));
16674 Handle<Value> result = CompileRun(
"eval('42')");
16675 CHECK_EQ(42, result->Int32Value());
16676 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
16677 CHECK_EQ(42, result->Int32Value());
16678 result = CompileRun(
"var f = new Function('return 42'); f()");
16679 CHECK_EQ(42, result->Int32Value());
16684 TryCatch try_catch;
16686 Handle<Value> result = CompileRun(
"eval('42')");
16687 CHECK(result.IsEmpty());
16688 CHECK(try_catch.HasCaught());
16691 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
16692 CHECK(result.IsEmpty());
16693 CHECK(try_catch.HasCaught());
16696 result = CompileRun(
"var f = new Function('return 42'); f()");
16697 CHECK(result.IsEmpty());
16698 CHECK(try_catch.HasCaught());
16744 TEST(SetErrorMessageForCodeGenFromStrings) {
16747 TryCatch try_catch;
16749 Handle<String> message = v8_str(
"Message") ;
16750 Handle<String> expected_message = v8_str(
"Uncaught EvalError: Message");
16754 Handle<Value> result = CompileRun(
"eval('42')");
16755 CHECK(result.IsEmpty());
16756 CHECK(try_catch.HasCaught());
16757 Handle<String> actual_message = try_catch.Message()->Get();
16758 CHECK(expected_message->Equals(actual_message));
16771 Handle<Function>
function = templ->GetFunction();
16772 context->
Global()->Set(v8_str(
"f"),
function);
16773 TryCatch try_catch;
16774 CompileRun(
"f.call(2)");
16781 Local<ObjectTemplate> templ = ObjectTemplate::New();
16784 Local<v8::Object> obj = templ->NewInstance();
16785 context->
Global()->Set(v8_str(
"obj"), obj);
16786 obj->Set(v8_str(
"1"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16787 obj->Set(v8_str(
"1"), v8_str(
"foobar"));
16788 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"1")));
16789 obj->Set(v8_num(2), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16790 obj->Set(v8_num(2), v8_str(
"foobar"));
16791 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_num(2)));
16794 obj->Set(v8_str(
"2000000000"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
16795 obj->Set(v8_str(
"2000000000"), v8_str(
"foobar"));
16796 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"2000000000")));
16805 CompileRun(
"({'a': 0})");
16815 i::Isolate::Current()->heap()->CollectAllGarbage(
16817 {
i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache();
16818 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) {
16826 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
16829 Local<Value> data) {
16832 name->IsString() &&
16833 name->ToString()->Length() == 9 &&
16834 name->ToString()->Utf8Length() == 9) {
16836 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
16837 return strncmp(buffer,
"__proto__", 9) != 0;
16850 no_proto_template->SetAccessCheckCallbacks(
16851 BlockProtoNamedSecurityTestCallback,
16852 IndexedSecurityTestCallback);
16856 hidden_proto_template->SetHiddenPrototype(
true);
16858 Local<FunctionTemplate> protected_hidden_proto_template =
16860 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
16861 BlockProtoNamedSecurityTestCallback,
16862 IndexedSecurityTestCallback);
16863 protected_hidden_proto_template->SetHiddenPrototype(
true);
16870 Local<Object> simple_object = Object::New();
16873 Local<Object> protected_object =
16874 no_proto_template->NewInstance();
16877 Local<Object> proxy_object =
16881 Local<Object> global_object =
16882 proxy_object->GetPrototype()->ToObject();
16886 hidden_proto_template->GetFunction()->NewInstance();
16887 Local<Object> object_with_hidden =
16889 object_with_hidden->SetPrototype(hidden_prototype);
16892 Local<Object> protected_hidden_prototype =
16893 protected_hidden_proto_template->GetFunction()->NewInstance();
16894 Local<Object> object_with_protected_hidden =
16896 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
16902 Local<ObjectTemplate> global_template = ObjectTemplate::New();
16903 global_template->Set(v8_str(
"simple"), simple_object);
16904 global_template->Set(v8_str(
"protected"), protected_object);
16905 global_template->Set(v8_str(
"global"), global_object);
16906 global_template->Set(v8_str(
"proxy"), proxy_object);
16907 global_template->Set(v8_str(
"hidden"), object_with_hidden);
16908 global_template->Set(v8_str(
"phidden"), object_with_protected_hidden);
16912 Local<Value> result1 = CompileRun(
"Object.getPrototypeOf(simple)");
16913 CHECK(result1->Equals(simple_object->GetPrototype()));
16915 Local<Value> result2 = CompileRun(
"Object.getPrototypeOf(protected)");
16918 Local<Value> result3 = CompileRun(
"Object.getPrototypeOf(global)");
16919 CHECK(result3->Equals(global_object->GetPrototype()));
16921 Local<Value> result4 = CompileRun(
"Object.getPrototypeOf(proxy)");
16924 Local<Value> result5 = CompileRun(
"Object.getPrototypeOf(hidden)");
16925 CHECK(result5->Equals(
16926 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
16928 Local<Value> result6 = CompileRun(
"Object.getPrototypeOf(phidden)");
16937 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
16940 env->
Global()->Set(v8_str(
"Intercept"), intercept->GetFunction());
16941 CompileRun(
"var a = new Object();"
16942 "var b = new Intercept();"
16943 "var c = new Object();"
16947 "for (var i = 0; i < 3; i++) c.x;");
16948 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
16949 ExpectInt32(
"c.x", 23);
16950 CompileRun(
"a.y = 42;"
16951 "for (var i = 0; i < 3; i++) c.x;");
16952 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
16953 ExpectInt32(
"c.x", 23);
16954 ExpectBoolean(
"c.hasOwnProperty('y')",
false);
16955 ExpectInt32(
"c.y", 42);
16959 static void TestReceiver(Local<Value> expected_result,
16960 Local<Value> expected_receiver,
16961 const char* code) {
16962 Local<Value> result = CompileRun(code);
16963 CHECK(result->IsObject());
16964 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
16965 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
16978 foreign_context->Enter();
16979 Local<Value> foreign_function =
16980 CompileRun(
"function func() { return { 0: this.id, "
16982 " toString: function() { "
16989 CHECK(foreign_function->IsFunction());
16990 foreign_context->Exit();
16994 Local<String> password = v8_str(
"Password");
16998 foreign_context->SetSecurityToken(password);
17000 Local<String> i = v8_str(
"i");
17001 Local<String> o = v8_str(
"o");
17002 Local<String>
id = v8_str(
"id");
17004 CompileRun(
"function ownfunc() { return { 0: this.id, "
17006 " toString: function() { "
17013 context->
Global()->Set(v8_str(
"func"), foreign_function);
17016 CHECK(i->Equals(foreign_context->Global()->Get(
id)));
17021 TestReceiver(o, context->
Global(),
"ownfunc.call()");
17022 TestReceiver(o, context->
Global(),
"ownfunc.apply()");
17024 TestReceiver(o, context->
Global(),
"[1].map(ownfunc)[0]");
17025 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/,ownfunc)[1]")));
17026 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[1]")));
17027 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[3]")));
17029 TestReceiver(o, context->
Global(),
"ownfunc()");
17031 TestReceiver(o, context->
Global(),
"(1,ownfunc)()");
17035 TestReceiver(i, foreign_context->Global(),
"func.call()");
17036 TestReceiver(i, foreign_context->Global(),
"func.apply()");
17038 TestReceiver(i, foreign_context->Global(),
17039 "Function.prototype.call.call(func)");
17040 TestReceiver(i, foreign_context->Global(),
17041 "Function.prototype.call.apply(func)");
17042 TestReceiver(i, foreign_context->Global(),
17043 "Function.prototype.apply.call(func)");
17044 TestReceiver(i, foreign_context->Global(),
17045 "Function.prototype.apply.apply(func)");
17047 TestReceiver(i, foreign_context->Global(),
"[1].map(func)[0]");
17049 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/,func)[1]")));
17050 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[1]")));
17051 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[3]")));
17055 TestReceiver(o, context->
Global(),
"func()");
17057 TestReceiver(o, context->
Global(),
"(1,func)()");
17059 foreign_context.Dispose();
17068 callback_fired ^= 1;
17074 callback_fired ^= 2;
17079 int32_t level = args[0]->Int32Value();
17082 i::OS::Print(
"Entering recursion level %d.\n", level);
17086 CompileRun(script_vector.
start());
17102 env->
Global()->Set(v8_str(
"recursion"),
17109 Local<Script> script =
17115 callback_fired = 0;
17121 callback_fired = 0;
17122 Local<Function> recursive_function =
17123 Local<Function>::Cast(env->
Global()->Get(v8_str(
"recursion")));
17125 recursive_function->Call(env->
Global(), 1, args);
17132 CompileRun(
"1+1;");
17138 CompileRun(
"throw 'second exception';");
17142 TEST(CallCompletedCallbackOneException) {
17146 CompileRun(
"throw 'exception';");
17150 TEST(CallCompletedCallbackTwoExceptions) {
17154 CompileRun(
"throw 'first exception';");
17158 static int probes_counter = 0;
17159 static int misses_counter = 0;
17160 static int updates_counter = 0;
17163 static int* LookupCounter(
const char* name) {
17164 if (strcmp(name,
"c:V8.MegamorphicStubCacheProbes") == 0) {
17165 return &probes_counter;
17166 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheMisses") == 0) {
17167 return &misses_counter;
17168 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheUpdates") == 0) {
17169 return &updates_counter;
17175 static const char* kMegamorphicTestProgram =
17176 "function ClassA() { };"
17177 "function ClassB() { };"
17178 "ClassA.prototype.foo = function() { };"
17179 "ClassB.prototype.foo = function() { };"
17180 "function fooify(obj) { obj.foo(); };"
17181 "var a = new ClassA();"
17182 "var b = new ClassB();"
17183 "for (var i = 0; i < 10000; i++) {"
17189 static void StubCacheHelper(
bool primary) {
17190 V8::SetCounterFunction(LookupCounter);
17191 USE(kMegamorphicTestProgram);
17193 i::FLAG_native_code_counters =
true;
17195 i::FLAG_test_primary_stub_cache =
true;
17197 i::FLAG_test_secondary_stub_cache =
true;
17199 i::FLAG_crankshaft =
false;
17202 int initial_probes = probes_counter;
17203 int initial_misses = misses_counter;
17204 int initial_updates = updates_counter;
17205 CompileRun(kMegamorphicTestProgram);
17206 int probes = probes_counter - initial_probes;
17207 int misses = misses_counter - initial_misses;
17208 int updates = updates_counter - initial_updates;
17217 StubCacheHelper(
true);
17222 StubCacheHelper(
false);
17226 static int fatal_error_callback_counter = 0;
17227 static void CountingErrorCallback(
const char* location,
const char* message) {
17228 printf(
"CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
17229 fatal_error_callback_counter++;
17242 CHECK(*v8::Utils::OpenHandle(*
v8::Null(isolate)) == *null_value);
17245 CHECK(*v8::Utils::OpenHandle(*
v8::True(isolate)) == *true_value);
17248 CHECK(*v8::Utils::OpenHandle(*
v8::False(isolate)) == *false_value);
17252 CHECK_EQ(0, fatal_error_callback_counter);
17255 i::Isolate::Current()->TearDown();
17257 CHECK_EQ(1, fatal_error_callback_counter);
17259 CHECK_EQ(2, fatal_error_callback_counter);
17261 CHECK_EQ(3, fatal_error_callback_counter);
17263 CHECK_EQ(4, fatal_error_callback_counter);
17265 CHECK_EQ(5, fatal_error_callback_counter);
17267 CHECK_EQ(6, fatal_error_callback_counter);
17269 CHECK_EQ(7, fatal_error_callback_counter);
17271 CHECK_EQ(8, fatal_error_callback_counter);
17273 CHECK_EQ(9, fatal_error_callback_counter);
17281 static void* data1 =
reinterpret_cast<void*
>(0xacce55ed);
17285 static void* data2 =
reinterpret_cast<void*
>(0xdecea5ed);
17305 CHECK_EQ(0, fatal_error_callback_counter);
17308 i::Isolate::Current()->TearDown();
17310 CHECK_EQ(1, fatal_error_callback_counter);
17312 CHECK_EQ(2, fatal_error_callback_counter);
17314 CHECK_EQ(3, fatal_error_callback_counter);
17318 static int instance_checked_getter_count = 0;
17319 static Handle<Value> InstanceCheckedGetter(Local<String> name,
17320 const AccessorInfo& info) {
17322 instance_checked_getter_count++;
17327 static int instance_checked_setter_count = 0;
17328 static void InstanceCheckedSetter(Local<String> name,
17329 Local<Value> value,
17330 const AccessorInfo& info) {
17333 instance_checked_setter_count++;
17337 static void CheckInstanceCheckedResult(
int getters,
17339 bool expects_callbacks,
17340 TryCatch* try_catch) {
17341 if (expects_callbacks) {
17342 CHECK(!try_catch->HasCaught());
17343 CHECK_EQ(getters, instance_checked_getter_count);
17344 CHECK_EQ(setters, instance_checked_setter_count);
17346 CHECK(try_catch->HasCaught());
17347 CHECK_EQ(0, instance_checked_getter_count);
17348 CHECK_EQ(0, instance_checked_setter_count);
17350 try_catch->Reset();
17354 static void CheckInstanceCheckedAccessors(
bool expects_callbacks) {
17355 instance_checked_getter_count = 0;
17356 instance_checked_setter_count = 0;
17357 TryCatch try_catch;
17360 CompileRun(
"obj.foo");
17361 CheckInstanceCheckedResult(1, 0, expects_callbacks, &try_catch);
17362 CompileRun(
"obj.foo = 23");
17363 CheckInstanceCheckedResult(1, 1, expects_callbacks, &try_catch);
17366 CompileRun(
"function test_get(o) { o.foo; }"
17368 CheckInstanceCheckedResult(2, 1, expects_callbacks, &try_catch);
17369 CompileRun(
"test_get(obj);");
17370 CheckInstanceCheckedResult(3, 1, expects_callbacks, &try_catch);
17371 CompileRun(
"test_get(obj);");
17372 CheckInstanceCheckedResult(4, 1, expects_callbacks, &try_catch);
17373 CompileRun(
"function test_set(o) { o.foo = 23; }"
17375 CheckInstanceCheckedResult(4, 2, expects_callbacks, &try_catch);
17376 CompileRun(
"test_set(obj);");
17377 CheckInstanceCheckedResult(4, 3, expects_callbacks, &try_catch);
17378 CompileRun(
"test_set(obj);");
17379 CheckInstanceCheckedResult(4, 4, expects_callbacks, &try_catch);
17382 CompileRun(
"%OptimizeFunctionOnNextCall(test_get);"
17384 CheckInstanceCheckedResult(5, 4, expects_callbacks, &try_catch);
17385 CompileRun(
"%OptimizeFunctionOnNextCall(test_set);"
17387 CheckInstanceCheckedResult(5, 5, expects_callbacks, &try_catch);
17390 CompileRun(
"%DeoptimizeFunction(test_get);"
17391 "%ClearFunctionTypeFeedback(test_get);"
17392 "%DeoptimizeFunction(test_set);"
17393 "%ClearFunctionTypeFeedback(test_set);");
17398 v8::internal::FLAG_allow_natives_syntax =
true;
17402 Local<FunctionTemplate> templ = FunctionTemplate::New();
17403 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17404 inst->SetAccessor(v8_str(
"foo"),
17405 InstanceCheckedGetter, InstanceCheckedSetter,
17410 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
17412 printf(
"Testing positive ...\n");
17413 CompileRun(
"var obj = new f();");
17414 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17415 CheckInstanceCheckedAccessors(
true);
17417 printf(
"Testing negative ...\n");
17418 CompileRun(
"var obj = {};"
17419 "obj.__proto__ = new f();");
17420 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17421 CheckInstanceCheckedAccessors(
false);
17426 v8::internal::FLAG_allow_natives_syntax =
true;
17430 Local<FunctionTemplate> templ = FunctionTemplate::New();
17431 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17433 inst->SetAccessor(v8_str(
"foo"),
17434 InstanceCheckedGetter, InstanceCheckedSetter,
17439 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
17441 printf(
"Testing positive ...\n");
17442 CompileRun(
"var obj = new f();");
17443 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17444 CheckInstanceCheckedAccessors(
true);
17446 printf(
"Testing negative ...\n");
17447 CompileRun(
"var obj = {};"
17448 "obj.__proto__ = new f();");
17449 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17450 CheckInstanceCheckedAccessors(
false);
17455 v8::internal::FLAG_allow_natives_syntax =
true;
17459 Local<FunctionTemplate> templ = FunctionTemplate::New();
17460 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
17461 proto->SetAccessor(v8_str(
"foo"),
17462 InstanceCheckedGetter, InstanceCheckedSetter,
17467 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
17469 printf(
"Testing positive ...\n");
17470 CompileRun(
"var obj = new f();");
17471 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17472 CheckInstanceCheckedAccessors(
true);
17474 printf(
"Testing negative ...\n");
17475 CompileRun(
"var obj = {};"
17476 "obj.__proto__ = new f();");
17477 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17478 CheckInstanceCheckedAccessors(
false);
17480 printf(
"Testing positive with modified prototype chain ...\n");
17481 CompileRun(
"var obj = new f();"
17483 "pro.__proto__ = obj.__proto__;"
17484 "obj.__proto__ = pro;");
17485 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
17486 CheckInstanceCheckedAccessors(
true);
17497 TryCatch try_catch;
17498 const char* trigger_ic =
17500 " throw new Error('test'); \n"
17505 CompileRun(trigger_ic);
17506 CHECK(try_catch.HasCaught());
17507 Local<Message> message = try_catch.Message();
17508 CHECK(!message.IsEmpty());
17509 CHECK_EQ(2, message->GetLineNumber());
17515 TryCatch try_catch;
17516 const char* throw_again =
17518 " throw new Error('test'); \n"
17522 " throw new Error('again'); \n"
17524 CompileRun(throw_again);
17525 CHECK(try_catch.HasCaught());
17526 Local<Message> message = try_catch.Message();
17527 CHECK(!message.IsEmpty());
17528 CHECK_EQ(6, message->GetLineNumber());
17533 static void Helper137002(
bool do_store,
17535 bool remove_accessor,
17536 bool interceptor) {
17538 Local<ObjectTemplate> templ = ObjectTemplate::New();
17542 templ->SetAccessor(v8_str(
"foo"),
17543 GetterWhichReturns42,
17544 SetterWhichSetsYOnThisTo23);
17546 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
17550 CompileRun(do_store ?
17551 "function f(x) { x.foo = void 0; }" :
17552 "function f(x) { return x.foo; }");
17553 CompileRun(
"obj.y = void 0;");
17554 if (!interceptor) {
17555 CompileRun(
"%OptimizeObjectForAddingMultipleProperties(obj, 1);");
17557 CompileRun(
"obj.__proto__ = null;"
17558 "f(obj); f(obj); f(obj);");
17560 CompileRun(
"f({});");
17562 CompileRun(
"obj.y = void 0;"
17563 "%OptimizeFunctionOnNextCall(f);");
17564 if (remove_accessor) {
17565 CompileRun(
"delete obj.foo;");
17567 CompileRun(
"var result = f(obj);");
17569 CompileRun(
"result = obj.y;");
17571 if (remove_accessor && !interceptor) {
17572 CHECK(context->
Global()->Get(v8_str(
"result"))->IsUndefined());
17575 context->
Global()->Get(v8_str(
"result"))->Int32Value());
17581 i::FLAG_allow_natives_syntax =
true;
17582 i::FLAG_compilation_cache =
false;
17584 for (
int i = 0; i < 16; i++) {
17585 Helper137002(i & 8, i & 4, i & 2, i & 1);
17591 i::FLAG_allow_natives_syntax =
true;
17594 Local<ObjectTemplate> templ = ObjectTemplate::New();
17595 templ->SetAccessor(v8_str(
"foo"),
17596 GetterWhichReturns42,
17597 SetterWhichSetsYOnThisTo23);
17598 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
17602 CompileRun(
"function load(x) { return x.foo; }"
17603 "function store(x) { x.foo = void 0; }"
17604 "function keyed_load(x, key) { return x[key]; }"
17608 "function load2(x) { void 0; return x.foo; }"
17609 "function store2(x) { void 0; x.foo = void 0; }"
17610 "function keyed_load2(x, key) { void 0; return x[key]; }"
17613 "obj.__proto__ = null;"
17615 "subobj.y = void 0;"
17616 "subobj.__proto__ = obj;"
17617 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
17620 "load(obj); load(obj);"
17621 "load2(subobj); load2(subobj);"
17622 "store(obj); store(obj);"
17623 "store2(subobj); store2(subobj);"
17624 "keyed_load(obj, 'foo'); keyed_load(obj, 'foo');"
17625 "keyed_load2(subobj, 'foo'); keyed_load2(subobj, 'foo');"
17633 "keyed_load(obj, 'foo');"
17634 "keyed_load2(subobj, 'foo');"
17639 "subobj.y = void 0;"
17641 "var load_result = load(obj);"
17642 "var load_result2 = load2(subobj);"
17643 "var keyed_load_result = keyed_load(obj, 'foo');"
17644 "var keyed_load_result2 = keyed_load2(subobj, 'foo');"
17647 "var y_from_obj = obj.y;"
17648 "var y_from_subobj = subobj.y;");
17649 CHECK(context->
Global()->Get(v8_str(
"load_result"))->IsUndefined());
17650 CHECK(context->
Global()->Get(v8_str(
"load_result2"))->IsUndefined());
17651 CHECK(context->
Global()->Get(v8_str(
"keyed_load_result"))->IsUndefined());
17652 CHECK(context->
Global()->Get(v8_str(
"keyed_load_result2"))->IsUndefined());
17653 CHECK(context->
Global()->Get(v8_str(
"y_from_obj"))->IsUndefined());
17654 CHECK(context->
Global()->Get(v8_str(
"y_from_subobj"))->IsUndefined());
17659 i::FLAG_allow_natives_syntax =
true;
17662 Local<ObjectTemplate> templ = ObjectTemplate::New();
17663 templ->SetAccessor(v8_str(
"foo"),
17664 GetterWhichReturns42,
17665 SetterWhichSetsYOnThisTo23);
17666 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
17668 CompileRun(
"function load(x) { return x.foo; }"
17669 "var o = Object.create(obj);"
17670 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
17671 "load(o); load(o); load(o); load(o);");
17676 i::FLAG_expose_gc =
true;
17682 TryCatch try_catch;
17683 try_catch.SetVerbose(
true);
17684 CompileRun(
"try { throw new Error(); } finally { gc(); }");
17685 CHECK(try_catch.HasCaught());
17692 Handle<FunctionTemplate> templ = FunctionTemplate::New();
17694 context->
Global()->Set(v8_str(
"Bug"), templ->GetFunction());
17695 CompileRun(
"Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
17702 Local<ObjectTemplate> templ = ObjectTemplate::New();
17703 Local<Object> obj = templ->NewInstance();
17705 obj->DeleteHiddenValue(v8_str(
"Bug"));
17718 InterruptThread i_thread(
this);
17722 CHECK_EQ(kExpectedValue, sem_value_);
17726 static const int kExpectedValue = 1;
17728 class InterruptThread :
public i::Thread {
17731 : Thread(
"InterruptThread"), test_(test) {}
17733 virtual void Run() {
17734 struct sigaction action;
17740 memset(&action, 0,
sizeof(action));
17741 action.sa_handler = SignalHandler;
17742 sigaction(SIGCHLD, &action,
NULL);
17745 kill(getpid(), SIGCHLD);
17751 test_->sem_value_ = 1;
17752 test_->sem_->Signal();
17755 static void SignalHandler(
int signal) {
17760 struct sigaction sa_;
17764 volatile int sem_value_;
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
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)
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
bool IsIndependent() 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)
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< Value > FooSetInterceptor(Local< String > name, Local< Value > value, const AccessorInfo &info)
Handle< Primitive > V8EXPORT Null()
v8::Handle< Script > getScript()
v8::Persistent< Context > calling_context0
~RegExpStringModificationTest()
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
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)
static bool AddMessageListener(MessageCallback that)
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)
static Number * Cast(v8::Value *obj)
v8::Handle< Value > call_ic_function3
v8::Handle< Value > AnalyzeStackOfInlineScriptWithSourceURL(const v8::Arguments &args)
void CallCompletedCallbackException()
void ExternalArrayLimitTestHelper(v8::ExternalArrayType array_type, int size)
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()
bool Equals(String *other)
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
uint32_t ComputePointerHash(void *ptr)
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()
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)
bool ToArrayIndex(uint32_t *index)
v8::Handle< v8::Object > bottom
void CallCompletedCallback1()
TestAsciiResource(const char *data, int *counter=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 >())
uint32_t occupancy() const
v8::Handle< v8::Value > DirectApiCallback(const v8::Arguments &args)
void SetInternalFieldCount(int value)
Handle< v8::Integer > HasOwnPropertyNamedPropertyQuery(Local< String > property, const AccessorInfo &info)
void SimulateFullSpace(i::PagedSpace *space)
static void SetFatalErrorHandler(FatalErrorCallback that)
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage message
static int ContextDisposedNotification()
bool CodeGenerationDisallowed(Local< Context > context)
static bool SetFunctionEntryHook(FunctionEntryHook entry_hook)
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
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
static FunctionTemplateInfo * cast(Object *obj)
V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t *data, int length)
V8EXPORT void TurnOnAccessCheck()
int prologue_call_count_second
v8::Persistent< v8::Object > object_
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
static Code * GetCodeFromTargetAddress(Address address)
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)
activate correct semantics for inheriting readonliness false
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
V8EXPORT bool BooleanValue() const
void set_resource(const Resource *buffer)
v8::Handle< v8::Array > CheckThisNamedPropertyEnumerator(const AccessorInfo &info)
Handle< Value > FooGetInterceptor(Local< String > name, const AccessorInfo &info)
Handle< Value > HasOwnPropertyNamedPropertyGetter(Local< String > property, const AccessorInfo &info)
virtual void VisitPersistentHandle(Persistent< Value > value, uint16_t class_id)
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)
V8EXPORT double Value() const
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)
struct v8::JitCodeEvent::@0::@2 name
V8EXPORT bool IsNumber() const
void CallCompletedCallback2()
void EpilogueCallback(v8::GCType, v8::GCCallbackFlags)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< String > name)
v8::Handle< Value > AnalyzeStackOfDynamicScriptWithSourceURL(const v8::Arguments &args)
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()
kPropertyAccessorsOffset kNamedPropertyHandlerOffset kInstanceTemplateOffset kAccessCheckInfoOffset kEvalFrominstructionsOffsetOffset kInstanceClassNameOffset hidden_prototype
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)
void * Remove(void *key, uint32_t hash)
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)
static void VisitHandlesWithClassIds(PersistentHandleVisitor *visitor)
V8EXPORT Flags GetFlags() const
static Persistent< T > Cast(Persistent< S > that)
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)
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 use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra 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 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
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)
static void SetCreateHistogramFunction(CreateHistogramCallback)
Local< T > Close(Handle< T > value)
V8EXPORT bool IsNumberObject() 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
void SetErrorMessageForCodeGenerationFromStrings(Handle< String > message)
int match(Handle< Value > value)
Local< v8::Message > Message() const
Handle< Value > EmptyInterceptorGetter(Local< String > name, const AccessorInfo &info)
static bool IsLocked(Isolate *isolate=NULL)
void Inherit(Handle< FunctionTemplate > parent)
Visitor42(v8::Persistent< v8::Object > object)
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
V8EXPORT int GetIdentityHash()
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()