53 #include "../include/v8-util.h"
55 static const bool kLogThreading =
false;
58 using ::v8::BooleanObject;
60 using ::v8::Extension;
62 using ::v8::FunctionTemplate;
64 using ::v8::HandleScope;
69 using ::v8::ObjectTemplate;
70 using ::v8::Persistent;
72 using ::v8::StackTrace;
81 #define THREADED_PROFILED_TEST(Name) \
82 static void Test##Name(); \
83 TEST(Name##WithProfiler) { \
84 RunWithProfiler(&Test##Name); \
98 reinterpret_cast<i::CpuProfiler*
>(cpu_profiler)->DeleteAllProfiles();
102 static void ExpectString(
const char*
code,
const char* expected) {
103 Local<Value> result = CompileRun(code);
104 CHECK(result->IsString());
105 String::Utf8Value utf8(result);
110 static void ExpectInt32(
const char* code,
int expected) {
111 Local<Value> result = CompileRun(code);
112 CHECK(result->IsInt32());
113 CHECK_EQ(expected, result->Int32Value());
117 static void ExpectBoolean(
const char* code,
bool expected) {
118 Local<Value> result = CompileRun(code);
119 CHECK(result->IsBoolean());
120 CHECK_EQ(expected, result->BooleanValue());
124 static void ExpectTrue(
const char* code) {
125 ExpectBoolean(code,
true);
129 static void ExpectFalse(
const char* code) {
130 ExpectBoolean(code,
false);
134 static void ExpectObject(
const char* code, Local<Value> expected) {
135 Local<Value> result = CompileRun(code);
136 CHECK(result->Equals(expected));
140 static void ExpectUndefined(
const char* code) {
141 Local<Value> result = CompileRun(code);
142 CHECK(result->IsUndefined());
146 static int signature_callback_count;
147 static Local<Value> signature_expected_receiver;
148 static void IncrementingSignatureCallback(
151 signature_callback_count++;
156 for (
int i = 0; i < args.
Length(); i++)
162 static void SignatureCallback(
167 for (
int i = 0; i < args.
Length(); i++) {
175 TEST(InitializeAndDisposeOnce) {
182 TEST(InitializeAndDisposeMultiple) {
194 Local<Context> local_env;
197 local_env = env.
local();
201 CHECK(!local_env.IsEmpty());
208 const char* source =
"1 + 2 + 3";
209 Local<Script> script = v8_compile(source);
210 CHECK_EQ(6, script->Run()->Int32Value());
231 static void TestSignature(
const char* loop_js, Local<Value> receiver) {
234 "for (var i = 0; i < 10; i++) {"
238 signature_callback_count = 0;
239 signature_expected_receiver = receiver;
240 bool expected_to_throw = receiver.IsEmpty();
242 CompileRun(source.start());
244 if (!expected_to_throw) {
245 CHECK_EQ(10, signature_callback_count);
247 CHECK_EQ(v8_str(
"TypeError: Illegal invocation"),
262 isolate, IncrementingSignatureCallback, Local<Value>(), sig);
271 fun_proto->
Set(v8_str(
"prop_sig"), callback_sig);
272 fun_proto->
Set(v8_str(
"prop"), callback);
274 v8_str(
"accessor_sig"), callback_sig, callback_sig);
282 env->
Global()->Set(v8_str(
"fun_instance"), fun_instance);
283 env->
Global()->Set(v8_str(
"sub_fun_instance"), sub_fun_instance);
285 "var accessor_sig_key = 'accessor_sig';"
286 "var accessor_key = 'accessor';"
287 "var prop_sig_key = 'prop_sig';"
288 "var prop_key = 'prop';"
290 "function copy_props(obj) {"
291 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];"
292 " var source = Fun.prototype;"
293 " for (var i in keys) {"
294 " var key = keys[i];"
295 " var desc = Object.getOwnPropertyDescriptor(source, key);"
296 " Object.defineProperty(obj, key, desc);"
302 "var unrel = new UnrelFun();"
303 "copy_props(unrel);");
305 const char* test_objects[] = {
306 "fun_instance",
"sub_fun_instance",
"obj",
"unrel" };
307 unsigned bad_signature_start_offset = 2;
308 for (
unsigned i = 0; i <
ARRAY_SIZE(test_objects); i++) {
311 source,
"var test_object = %s; test_object", test_objects[i]);
312 Local<Value> test_object = CompileRun(source.
start());
313 TestSignature(
"test_object.prop();", test_object);
314 TestSignature(
"test_object.accessor;", test_object);
315 TestSignature(
"test_object[accessor_key];", test_object);
316 TestSignature(
"test_object.accessor = 1;", test_object);
317 TestSignature(
"test_object[accessor_key] = 1;", test_object);
318 if (i >= bad_signature_start_offset) test_object = Local<Value>();
319 TestSignature(
"test_object.prop_sig();", test_object);
320 TestSignature(
"test_object.accessor_sig;", test_object);
321 TestSignature(
"test_object[accessor_sig_key];", test_object);
322 TestSignature(
"test_object.accessor_sig = 1;", test_object);
323 TestSignature(
"test_object[accessor_sig_key] = 1;", test_object);
348 CHECK(value2->IsTrue());
351 CHECK(value3->IsTrue());
354 cons1->SetClassName(v8_str(
"Cons1"));
369 env->
Global()->Set(v8_str(
"Cons1"), cons1->GetFunction());
374 "Fun2(new Cons1(), new Cons2(), new Cons3()) =="
375 "'[object Cons1],[object Cons2],[object Cons3]'");
379 "Fun2(new Cons1(), new Cons2(), 5) == '[object Cons1],[object Cons2],'");
380 CHECK(value5->IsTrue());
383 "Fun2(new Cons3(), new Cons2(), new Cons1()) == ',[object Cons2],'");
384 CHECK(value6->IsTrue());
387 "Fun2(new Cons1(), new Cons2(), new Cons3(), 'd') == "
388 "'[object Cons1],[object Cons2],[object Cons3],d';");
389 CHECK(value7->IsTrue());
392 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'");
393 CHECK(value8->IsTrue());
402 Local<String> undef_str = undef->
ToString();
403 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1);
404 undef_str->WriteUtf8(value);
405 CHECK_EQ(0, strcmp(value,
"undefined"));
415 Local<Value> foo_before = obj->Get(v8_str(
"foo"));
416 CHECK(foo_before->IsUndefined());
417 Local<String> bar_str = v8_str(
"bar");
418 obj->Set(v8_str(
"foo"), bar_str);
419 Local<Value> foo_after = obj->Get(v8_str(
"foo"));
420 CHECK(!foo_after->IsUndefined());
421 CHECK(foo_after->IsString());
430 Local<Value> before = obj->Get(1);
431 CHECK(before->IsUndefined());
432 Local<String> bar_str = v8_str(
"bar");
433 obj->Set(1, bar_str);
434 Local<Value> after = obj->Get(1);
435 CHECK(!after->IsUndefined());
436 CHECK(after->IsString());
439 Local<v8::Array> value = CompileRun(
"[\"a\", \"b\"]").As<
v8::Array>();
440 CHECK_EQ(v8_str(
"a"), value->Get(0));
441 CHECK_EQ(v8_str(
"b"), value->Get(1));
448 const char* source =
"1 + 2 + 3";
449 Local<Script> script = v8_compile(source);
450 CHECK_EQ(6, script->Run()->Int32Value());
454 static uint16_t* AsciiToTwoByteString(
const char* source) {
456 uint16_t* converted = i::NewArray<uint16_t>(array_length);
457 for (
int i = 0; i < array_length; i++) converted[i] = source[i];
465 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
466 while (data[length_]) ++length_;
471 if (counter_ !=
NULL) ++*counter_;
494 data_(data + offset),
495 length_(strlen(data) - offset),
496 counter_(counter) { }
500 if (counter_ !=
NULL) ++*counter_;
512 const char* orig_data_;
520 int dispose_count = 0;
521 const char* c_source =
"1 + 2 * 3";
522 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
527 Local<String> source = String::NewExternal(env->
GetIsolate(), resource);
528 Local<Script> script = v8_compile(source);
529 Local<Value> value = script->Run();
530 CHECK(value->IsNumber());
532 CHECK(source->IsExternal());
534 static_cast<TestResource*>(source->GetExternalStringResource()));
535 String::Encoding encoding = String::UNKNOWN_ENCODING;
536 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
537 source->GetExternalStringResourceBase(&encoding));
538 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
549 int dispose_count = 0;
550 const char* c_source =
"1 + 2 * 3";
556 Local<String> source = String::NewExternal(env->
GetIsolate(), resource);
557 CHECK(source->IsExternalAscii());
558 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
559 source->GetExternalAsciiStringResource());
560 String::Encoding encoding = String::UNKNOWN_ENCODING;
561 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
562 source->GetExternalStringResourceBase(&encoding));
563 CHECK_EQ(String::ASCII_ENCODING, encoding);
564 Local<Script> script = v8_compile(source);
565 Local<Value> value = script->Run();
566 CHECK(value->IsNumber());
578 int dispose_count = 0;
579 uint16_t* two_byte_source = AsciiToTwoByteString(
"1 + 2 * 3");
583 Local<String> source =
584 String::NewFromTwoByte(env->
GetIsolate(), two_byte_source);
588 CHECK_EQ(source->IsExternal(),
false);
589 CHECK_EQ(source->IsExternalAscii(),
false);
590 String::Encoding encoding = String::UNKNOWN_ENCODING;
591 CHECK_EQ(
NULL, source->GetExternalStringResourceBase(&encoding));
592 CHECK_EQ(String::ASCII_ENCODING, encoding);
593 bool success = source->MakeExternal(
new TestResource(two_byte_source,
596 Local<Script> script = v8_compile(source);
597 Local<Value> value = script->Run();
598 CHECK(value->IsNumber());
610 int dispose_count = 0;
611 const char* c_source =
"1 + 2 * 3";
615 Local<String> source = v8_str(c_source);
619 bool success = source->MakeExternal(
622 Local<Script> script = v8_compile(source);
623 Local<Value> value = script->Run();
624 CHECK(value->IsNumber());
635 TEST(MakingExternalStringConditions) {
643 uint16_t* two_byte_string = AsciiToTwoByteString(
"s1");
644 Local<String> small_string =
645 String::NewFromTwoByte(env->
GetIsolate(), two_byte_string);
649 CHECK(!small_string->CanMakeExternal());
654 CHECK(small_string->CanMakeExternal());
656 two_byte_string = AsciiToTwoByteString(
"small string 2");
657 small_string = String::NewFromTwoByte(env->
GetIsolate(), two_byte_string);
661 CHECK(!small_string->CanMakeExternal());
662 for (
int i = 0; i < 100; i++) {
663 String::Value value(small_string);
666 CHECK(small_string->CanMakeExternal());
668 const int buf_size = 10 * 1024;
669 char* buf = i::NewArray<char>(buf_size);
670 memset(buf,
'a', buf_size);
671 buf[buf_size - 1] =
'\0';
673 two_byte_string = AsciiToTwoByteString(buf);
674 Local<String> large_string =
675 String::NewFromTwoByte(env->
GetIsolate(), two_byte_string);
679 CHECK(large_string->CanMakeExternal());
683 TEST(MakingExternalAsciiStringConditions) {
691 Local<String> small_string = String::NewFromUtf8(env->
GetIsolate(),
"s1");
693 CHECK(!small_string->CanMakeExternal());
698 CHECK(small_string->CanMakeExternal());
700 small_string = String::NewFromUtf8(env->
GetIsolate(),
"small string 2");
702 CHECK(!small_string->CanMakeExternal());
703 for (
int i = 0; i < 100; i++) {
704 String::Value value(small_string);
707 CHECK(small_string->CanMakeExternal());
709 const int buf_size = 10 * 1024;
710 char* buf = i::NewArray<char>(buf_size);
711 memset(buf,
'a', buf_size);
712 buf[buf_size - 1] =
'\0';
713 Local<String> large_string = String::NewFromUtf8(env->
GetIsolate(), buf);
716 CHECK(large_string->CanMakeExternal());
720 TEST(MakingExternalUnalignedAsciiString) {
724 CompileRun(
"function cons(a, b) { return a + b; }"
725 "function slice(a) { return a.substring(1); }");
727 Local<String> cons = Local<String>::Cast(CompileRun(
728 "cons('abcdefghijklm', 'nopqrstuvwxyz');"));
730 Local<String> slice = Local<String>::Cast(CompileRun(
731 "slice('abcdefghijklmnopqrstuvwxyz');"));
739 const char* c_cons =
"_abcdefghijklmnopqrstuvwxyz";
740 bool success = cons->MakeExternal(
743 const char* c_slice =
"_bcdefghijklmnopqrstuvwxyz";
744 success = slice->MakeExternal(
758 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
759 Local<String>
string = String::NewExternal(
767 CHECK(isymbol->IsInternalizedString());
778 const char* one_byte_string =
"test string";
779 Local<String>
string = String::NewExternal(
787 CHECK(isymbol->IsInternalizedString());
795 i::FLAG_stress_compaction =
false;
796 i::FLAG_gc_global =
false;
797 int dispose_count = 0;
798 bool in_new_space =
false;
801 uint16_t* two_byte_string = AsciiToTwoByteString(
"test string");
802 Local<String>
string = String::NewExternal(
817 i::FLAG_stress_compaction =
false;
818 i::FLAG_gc_global =
false;
819 int dispose_count = 0;
820 bool in_new_space =
false;
823 const char* one_byte_string =
"test string";
824 Local<String>
string = String::NewExternal(
847 dispose_(dispose) { }
851 if (dispose_)
delete this;
862 TEST(ExternalStringWithDisposeHandling) {
863 const char* c_source =
"1 + 2 * 3";
866 TestAsciiResourceWithDisposeControl::dispose_count = 0;
867 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
872 Local<String> source = String::NewExternal(env->
GetIsolate(), &res_stack);
873 Local<Script> script = v8_compile(source);
874 Local<Value> value = script->Run();
875 CHECK(value->IsNumber());
878 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
882 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
883 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
886 TestAsciiResourceWithDisposeControl::dispose_count = 0;
887 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
893 Local<String> source = String::NewExternal(env->
GetIsolate(), res_heap);
894 Local<Script> script = v8_compile(source);
895 Local<Value> value = script->Run();
896 CHECK(value->IsNumber());
899 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
903 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
904 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
912 const char* one_byte_string_1 =
"function a_times_t";
913 const char* two_byte_string_1 =
"wo_plus_b(a, b) {return ";
914 const char* one_byte_extern_1 =
"a * 2 + b;} a_times_two_plus_b(4, 8) + ";
915 const char* two_byte_extern_1 =
"a_times_two_plus_b(4, 8) + ";
916 const char* one_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
917 const char* two_byte_string_2 =
"a_times_two_plus_b(4, 8) + ";
918 const char* two_byte_extern_2 =
"a_times_two_plus_b(1, 2);";
919 Local<String> left = v8_str(one_byte_string_1);
921 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
922 Local<String> right =
923 String::NewFromTwoByte(env->
GetIsolate(), two_byte_source);
926 Local<String> source = String::Concat(left, right);
927 right = String::NewExternal(
929 source = String::Concat(source, right);
930 right = String::NewExternal(
932 new TestResource(AsciiToTwoByteString(two_byte_extern_1)));
933 source = String::Concat(source, right);
934 right = v8_str(one_byte_string_2);
935 source = String::Concat(source, right);
937 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
938 right = String::NewFromTwoByte(env->
GetIsolate(), two_byte_source);
941 source = String::Concat(source, right);
942 right = String::NewExternal(
944 new TestResource(AsciiToTwoByteString(two_byte_extern_2)));
945 source = String::Concat(source, right);
946 Local<Script> script = v8_compile(source);
947 Local<Value> value = script->Run();
948 CHECK(value->IsNumber());
961 global->Set(v8_str(
"pi"), v8_num(3.1415926));
962 Local<Value> pi = global->Get(v8_str(
"pi"));
963 CHECK_EQ(3.1415926, pi->NumberValue());
968 static void CheckReturnValue(
const T& t,
i::Address callback) {
973 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
975 bool is_runtime = (*o)->IsTheHole();
977 CHECK(!(*o)->IsTheHole() && !(*o)->IsUndefined());
979 CHECK((*o)->IsTheHole() || (*o)->IsUndefined());
980 CHECK_EQ(is_runtime, (*o)->IsTheHole());
985 if (isolate->cpu_profiler()->is_profiling()) {
987 CHECK(isolate->external_callback_scope());
988 CHECK_EQ(callback, isolate->external_callback_scope()->callback());
996 CheckReturnValue(info, callback);
1003 return handle_callback_impl(info,
FUNCTION_ADDR(handle_callback));
1008 return handle_callback_impl(info,
FUNCTION_ADDR(handle_callback_2));
1011 static void construct_callback(
1015 info.
This()->Set(v8_str(
"x"), v8_num(1));
1016 info.
This()->Set(v8_str(
"y"), v8_num(2));
1022 static void Return239Callback(
1031 template<
typename Handler>
1032 static void TestFunctionTemplateInitializer(Handler handler,
1033 Handler handler_2) {
1040 Local<v8::FunctionTemplate> fun_templ =
1042 Local<Function> fun = fun_templ->GetFunction();
1043 env->
Global()->Set(v8_str(
"obj"), fun);
1044 Local<Script> script = v8_compile(
"obj()");
1045 for (
int i = 0; i < 30; i++) {
1046 CHECK_EQ(102, script->Run()->Int32Value());
1057 fun_templ->SetCallHandler(handler_2);
1058 Local<Function> fun = fun_templ->GetFunction();
1059 env->
Global()->Set(v8_str(
"obj"), fun);
1060 Local<Script> script = v8_compile(
"obj()");
1061 for (
int i = 0; i < 30; i++) {
1062 CHECK_EQ(102, script->Run()->Int32Value());
1068 template<
typename Constructor,
typename Accessor>
1069 static void TestFunctionTemplateAccessor(Constructor constructor,
1070 Accessor accessor) {
1074 Local<v8::FunctionTemplate> fun_templ =
1076 fun_templ->SetClassName(v8_str(
"funky"));
1077 fun_templ->InstanceTemplate()->SetAccessor(v8_str(
"m"), accessor);
1078 Local<Function> fun = fun_templ->GetFunction();
1079 env->
Global()->Set(v8_str(
"obj"), fun);
1080 Local<Value> result = v8_compile(
"(new obj()).toString()")->Run();
1081 CHECK_EQ(v8_str(
"[object funky]"), result);
1082 CompileRun(
"var obj_instance = new obj();");
1083 Local<Script> script;
1084 script = v8_compile(
"obj_instance.x");
1085 for (
int i = 0; i < 30; i++) {
1086 CHECK_EQ(1, script->Run()->Int32Value());
1088 script = v8_compile(
"obj_instance.m");
1089 for (
int i = 0; i < 30; i++) {
1090 CHECK_EQ(239, script->Run()->Int32Value());
1096 TestFunctionTemplateInitializer(handle_callback, handle_callback_2);
1097 TestFunctionTemplateAccessor(construct_callback, Return239Callback);
1108 template<
typename Callback>
1109 static void TestSimpleCallback(Callback callback) {
1116 object_template->
Set(isolate,
"callback",
1119 (*env)->Global()->Set(v8_str(
"callback_object"),
object);
1121 script = v8_compile(
"callback_object.callback(17)");
1122 for (
int i = 0; i < 30; i++) {
1125 script = v8_compile(
"callback_object.callback(17, 24)");
1126 for (
int i = 0; i < 30; i++) {
1133 TestSimpleCallback(SimpleCallback);
1137 template<
typename T>
1141 static int32_t fast_return_value_int32 = 471;
1142 static uint32_t fast_return_value_uint32 = 571;
1143 static const double kFastReturnValueDouble = 2.7;
1145 static bool fast_return_value_bool =
false;
1152 static bool fast_return_value_object_is_empty =
false;
1192 switch (fast_return_value_void) {
1209 if (!fast_return_value_object_is_empty) {
1215 template<
typename T>
1223 object_template->
Set(isolate,
"callback",
1226 (*env)->Global()->Set(v8_str(
"callback_object"),
object);
1227 return scope.
Escape(CompileRun(
"callback_object.callback()"));
1240 for (
size_t i = 0; i <
ARRAY_SIZE(int_values); i++) {
1241 for (
int modifier = -1; modifier <= 1; modifier++) {
1242 int int_value = int_values[i] + modifier;
1244 fast_return_value_int32 = int_value;
1245 value = TestFastReturnValues<int32_t>();
1249 fast_return_value_uint32 =
static_cast<uint32_t
>(int_value);
1250 value = TestFastReturnValues<uint32_t>();
1256 value = TestFastReturnValues<double>();
1260 for (
int i = 0; i < 2; i++) {
1261 fast_return_value_bool = i == 0;
1262 value = TestFastReturnValues<bool>();
1272 for (
size_t i = 0; i <
ARRAY_SIZE(oddballs); i++) {
1273 fast_return_value_void = oddballs[i];
1274 value = TestFastReturnValues<void>();
1275 switch (fast_return_value_void) {
1289 fast_return_value_object_is_empty =
false;
1290 value = TestFastReturnValues<Object>();
1292 fast_return_value_object_is_empty =
true;
1293 value = TestFastReturnValues<Object>();
1303 Local<v8::FunctionTemplate> fun_templ =
1306 Handle<v8::Value>(),
1307 Handle<v8::Signature>(),
1309 Local<Function> fun = fun_templ->GetFunction();
1310 env->
Global()->Set(v8_str(
"obj"), fun);
1311 Local<Script> script = v8_compile(
"obj.length");
1312 CHECK_EQ(23, script->Run()->Int32Value());
1315 Local<v8::FunctionTemplate> fun_templ =
1317 fun_templ->SetLength(22);
1318 Local<Function> fun = fun_templ->GetFunction();
1319 env->
Global()->Set(v8_str(
"obj"), fun);
1320 Local<Script> script = v8_compile(
"obj.length");
1321 CHECK_EQ(22, script->Run()->Int32Value());
1325 Local<v8::FunctionTemplate> fun_templ =
1327 Local<Function> fun = fun_templ->GetFunction();
1328 env->
Global()->Set(v8_str(
"obj"), fun);
1329 Local<Script> script = v8_compile(
"obj.length");
1330 CHECK_EQ(0, script->Run()->Int32Value());
1335 static void* expected_ptr;
1343 static void TestExternalPointerWrapping() {
1352 obj->
Set(v8_str(
"func"),
1354 env->
Global()->Set(v8_str(
"obj"), obj);
1357 "function foo() {\n"
1358 " for (var i = 0; i < 13; i++) obj.func();\n"
1360 "foo(), true")->BooleanValue());
1368 TestExternalPointerWrapping();
1373 expected_ptr = &
foo;
1374 TestExternalPointerWrapping();
1378 char* s =
new char[n];
1379 for (
int i = 0; i < n; i++) {
1380 expected_ptr = s + i;
1381 TestExternalPointerWrapping();
1387 expected_ptr =
reinterpret_cast<void*
>(1);
1388 TestExternalPointerWrapping();
1390 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef);
1391 TestExternalPointerWrapping();
1393 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeef + 1);
1394 TestExternalPointerWrapping();
1396 #if defined(V8_HOST_ARCH_X64)
1398 expected_ptr =
reinterpret_cast<void*
>(0x400000000);
1399 TestExternalPointerWrapping();
1401 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef);
1402 TestExternalPointerWrapping();
1404 expected_ptr =
reinterpret_cast<void*
>(0xdeadbeefdeadbeef + 1);
1405 TestExternalPointerWrapping();
1418 derived->Inherit(base);
1420 Local<v8::Function> base_function = base->GetFunction();
1421 Local<v8::Function> derived_function = derived->GetFunction();
1422 Local<v8::Function> other_function = other->GetFunction();
1424 Local<v8::Object> base_instance = base_function->NewInstance();
1425 Local<v8::Object> derived_instance = derived_function->NewInstance();
1426 Local<v8::Object> derived_instance2 = derived_function->NewInstance();
1427 Local<v8::Object> other_instance = other_function->NewInstance();
1428 derived_instance2->Set(v8_str(
"__proto__"), derived_instance);
1429 other_instance->Set(v8_str(
"__proto__"), derived_instance2);
1433 base_instance->FindInstanceInPrototypeChain(base));
1434 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty());
1435 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty());
1439 derived_instance->FindInstanceInPrototypeChain(base));
1441 derived_instance->FindInstanceInPrototypeChain(derived));
1442 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty());
1450 other_instance->FindInstanceInPrototypeChain(base));
1452 other_instance->FindInstanceInPrototypeChain(derived));
1454 other_instance->FindInstanceInPrototypeChain(other));
1465 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1468 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1479 if (i::SmiValuesAre31Bits()) {
1484 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1487 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1498 if (i::SmiValuesAre31Bits()) {
1507 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1510 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1520 uint32_t value = 239;
1523 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1526 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1540 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1543 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1557 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1560 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1569 uint32_t INT32_MAX_AS_UINT = (1
U << 31) - 1;
1570 uint32_t value = INT32_MAX_AS_UINT + 1;
1571 CHECK(value > INT32_MAX_AS_UINT);
1574 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1577 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1585 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1586 CHECK(syntax_error->IsNativeError());
1588 CHECK(!not_error->IsNativeError());
1590 CHECK(!not_object->IsNativeError());
1598 CHECK(boxed_string->IsStringObject());
1600 CHECK(!unboxed_string->IsStringObject());
1602 CHECK(!boxed_not_string->IsStringObject());
1604 CHECK(!not_object->IsStringObject());
1606 CHECK(!as_boxed.IsEmpty());
1607 Local<v8::String> the_string = as_boxed->ValueOf();
1608 CHECK(!the_string.IsEmpty());
1609 ExpectObject(
"\"test\"", the_string);
1613 the_string = as_boxed->
ValueOf();
1614 CHECK(!the_string.IsEmpty());
1615 ExpectObject(
"\"test\"", the_string);
1623 CHECK(boxed_number->IsNumberObject());
1625 CHECK(!unboxed_number->IsNumberObject());
1627 CHECK(!boxed_not_number->IsNumberObject());
1629 CHECK(!as_boxed.IsEmpty());
1630 double the_number = as_boxed->ValueOf();
1636 the_number = as_boxed->
ValueOf();
1645 CHECK(boxed_boolean->IsBooleanObject());
1647 CHECK(!unboxed_boolean->IsBooleanObject());
1649 CHECK(!boxed_not_boolean->IsBooleanObject());
1652 CHECK(!as_boxed.IsEmpty());
1653 bool the_boolean = as_boxed->ValueOf();
1660 CHECK_EQ(
true, as_boxed->ValueOf());
1662 CHECK_EQ(
false, as_boxed->ValueOf());
1670 Local<Value> primitive_false = Boolean::New(env->
GetIsolate(),
false);
1671 CHECK(primitive_false->IsBoolean());
1672 CHECK(!primitive_false->IsBooleanObject());
1673 CHECK(!primitive_false->BooleanValue());
1674 CHECK(!primitive_false->IsTrue());
1675 CHECK(primitive_false->IsFalse());
1677 Local<Value> false_value = BooleanObject::New(
false);
1678 CHECK(!false_value->IsBoolean());
1679 CHECK(false_value->IsBooleanObject());
1680 CHECK(false_value->BooleanValue());
1681 CHECK(!false_value->IsTrue());
1682 CHECK(!false_value->IsFalse());
1684 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>();
1685 CHECK(!false_boolean_object->IsBoolean());
1686 CHECK(false_boolean_object->IsBooleanObject());
1689 CHECK(!false_boolean_object->ValueOf());
1690 CHECK(!false_boolean_object->IsTrue());
1691 CHECK(!false_boolean_object->IsFalse());
1693 Local<Value> primitive_true = Boolean::New(env->
GetIsolate(),
true);
1694 CHECK(primitive_true->IsBoolean());
1695 CHECK(!primitive_true->IsBooleanObject());
1696 CHECK(primitive_true->BooleanValue());
1697 CHECK(primitive_true->IsTrue());
1698 CHECK(!primitive_true->IsFalse());
1700 Local<Value> true_value = BooleanObject::New(
true);
1701 CHECK(!true_value->IsBoolean());
1702 CHECK(true_value->IsBooleanObject());
1703 CHECK(true_value->BooleanValue());
1704 CHECK(!true_value->IsTrue());
1705 CHECK(!true_value->IsFalse());
1707 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>();
1708 CHECK(!true_boolean_object->IsBoolean());
1709 CHECK(true_boolean_object->IsBooleanObject());
1712 CHECK(true_boolean_object->ValueOf());
1713 CHECK(!true_boolean_object->IsTrue());
1714 CHECK(!true_boolean_object->IsFalse());
1721 double PI = 3.1415926;
1723 CHECK_EQ(PI, pi_obj->NumberValue());
1731 Local<String> str = v8_str(
"3.1415926");
1732 CHECK_EQ(3.1415926, str->NumberValue());
1743 double PI = 3.1415926;
1745 CHECK_EQ(3.0, date->NumberValue());
1746 date.As<
v8::Date>()->Set(v8_str(
"property"),
1761 CHECK(!u->BooleanValue());
1763 CHECK(!n->BooleanValue());
1765 CHECK(!str1->BooleanValue());
1767 CHECK(str2->BooleanValue());
1772 CHECK(!v8_compile(
"NaN")->Run()->BooleanValue());
1782 static void GetM(Local<String> name,
1797 templ->Set(isolate,
"x", v8_num(200));
1798 templ->SetAccessor(v8_str(
"m"), GetM);
1802 CHECK_EQ(13.4, result->NumberValue());
1803 CHECK_EQ(200, v8_compile(
"x")->Run()->Int32Value());
1804 CHECK_EQ(876, v8_compile(
"m")->Run()->Int32Value());
1811 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate);
1812 templ1->Set(isolate,
"x", v8_num(10));
1813 templ1->Set(isolate,
"y", v8_num(13));
1815 Local<v8::Object> instance1 = templ1->NewInstance();
1816 env->
Global()->Set(v8_str(
"p"), instance1);
1817 CHECK(v8_compile(
"(p.x == 10)")->Run()->BooleanValue());
1818 CHECK(v8_compile(
"(p.y == 13)")->Run()->BooleanValue());
1820 fun->PrototypeTemplate()->Set(isolate,
"nirk", v8_num(123));
1821 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
1822 templ2->Set(isolate,
"a", v8_num(12));
1823 templ2->Set(isolate,
"b", templ1);
1824 Local<v8::Object> instance2 = templ2->NewInstance();
1825 env->
Global()->Set(v8_str(
"q"), instance2);
1826 CHECK(v8_compile(
"(q.nirk == 123)")->Run()->BooleanValue());
1827 CHECK(v8_compile(
"(q.a == 12)")->Run()->BooleanValue());
1828 CHECK(v8_compile(
"(q.b.x == 10)")->Run()->BooleanValue());
1829 CHECK(v8_compile(
"(q.b.y == 13)")->Run()->BooleanValue());
1839 static void GetKnurd(Local<String> property,
1872 CHECK(CompileRun(
"base1.prototype.__proto__ == s.prototype")->BooleanValue());
1873 CHECK(CompileRun(
"base2.prototype.__proto__ == s.prototype")->BooleanValue());
1875 CHECK(v8_compile(
"s.prototype.PI == 3.14")->Run()->BooleanValue());
1878 CHECK(CompileRun(
"s.knurd == undefined")->BooleanValue());
1879 CHECK(CompileRun(
"s.prototype.knurd == undefined")->BooleanValue());
1880 CHECK(CompileRun(
"base1.prototype.knurd == undefined")->BooleanValue());
1882 env->
Global()->Set(v8_str(
"obj"),
1884 CHECK_EQ(17.2, v8_compile(
"obj.flabby()")->Run()->NumberValue());
1885 CHECK(v8_compile(
"'flabby' in obj")->Run()->BooleanValue());
1886 CHECK_EQ(15.2, v8_compile(
"obj.knurd")->Run()->NumberValue());
1887 CHECK(v8_compile(
"'knurd' in obj")->Run()->BooleanValue());
1888 CHECK_EQ(20.1, v8_compile(
"obj.v1")->Run()->NumberValue());
1890 env->
Global()->Set(v8_str(
"obj2"),
1892 CHECK_EQ(17.2, v8_compile(
"obj2.flabby()")->Run()->NumberValue());
1893 CHECK(v8_compile(
"'flabby' in obj2")->Run()->BooleanValue());
1894 CHECK_EQ(15.2, v8_compile(
"obj2.knurd")->Run()->NumberValue());
1895 CHECK(v8_compile(
"'knurd' in obj2")->Run()->BooleanValue());
1896 CHECK_EQ(10.1, v8_compile(
"obj2.v2")->Run()->NumberValue());
1899 CHECK(v8_compile(
"obj.v2")->Run()->IsUndefined());
1900 CHECK(v8_compile(
"obj2.v1")->Run()->IsUndefined());
1907 static void EchoNamedProperty(Local<String> name,
1911 echo_named_call_count++;
1920 Handle<Object>
self = info.
This();
1922 self->Get(String::Concat(v8_str(
"accessor_"), name)));
1927 Handle<Object>
self = info.
This();
1928 self->Set(String::Concat(v8_str(
"accessor_"), name), value);
1943 String::Utf8Value utf8(name);
1944 char* name_str = *utf8;
1945 char prefix[] =
"interceptor_";
1947 for (i = 0; name_str[i] && prefix[i]; ++i) {
1948 if (name_str[i] != prefix[i])
return;
1950 Handle<Object>
self = info.
This();
1951 info.
GetReturnValue().Set(self->GetHiddenValue(v8_str(name_str + i)));
1959 String::Utf8Value utf8(name);
1960 char* name_str = *utf8;
1961 char prefix[] =
"accessor_";
1963 for (i = 0; name_str[i] && prefix[i]; ++i) {
1964 if (name_str[i] != prefix[i])
break;
1966 if (!prefix[i])
return;
1968 if (value->IsInt32() && value->Int32Value() < 10000) {
1969 Handle<Object>
self = info.
This();
1970 self->SetHiddenValue(name, value);
1976 Handle<String> name,
1979 templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
1985 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1991 Handle<FunctionTemplate> parent = FunctionTemplate::New(
CcTest::isolate());
1992 Handle<FunctionTemplate> child = FunctionTemplate::New(
CcTest::isolate());
1993 child->Inherit(parent);
1998 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
1999 CompileRun(
"var child = new Child;"
2001 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
2002 ExpectInt32(
"child.age", 10);
2003 ExpectInt32(
"child.accessor_age", 10);
2009 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
2012 env->
Global()->Set(v8_str(
"Constructor"), templ->GetFunction());
2013 CompileRun(
"var o1 = new Constructor;"
2015 "Object.defineProperty(o1, 'x', {value: 10});");
2016 CompileRun(
"var o2 = new Constructor;"
2018 "Object.defineProperty(o2, 'x', {value: 10});");
2025 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate);
2026 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate);
2027 child->Inherit(parent);
2030 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2031 CompileRun(
"var child = new Child;"
2032 "var parent = child.__proto__;"
2033 "Object.defineProperty(parent, 'age', "
2034 " {get: function(){ return this.accessor_age; }, "
2035 " set: function(v){ this.accessor_age = v; }, "
2036 " enumerable: true, configurable: true});"
2038 ExpectBoolean(
"child.hasOwnProperty('age')",
false);
2039 ExpectInt32(
"child.age", 10);
2040 ExpectInt32(
"child.accessor_age", 10);
2047 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate);
2048 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate);
2049 child->Inherit(parent);
2052 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2053 CompileRun(
"var child = new Child;"
2054 "var parent = child.__proto__;"
2055 "parent.name = 'Alice';");
2056 ExpectBoolean(
"child.hasOwnProperty('name')",
false);
2057 ExpectString(
"child.name",
"Alice");
2058 CompileRun(
"child.name = 'Bob';");
2059 ExpectString(
"child.name",
"Bob");
2060 ExpectBoolean(
"child.hasOwnProperty('name')",
true);
2061 ExpectString(
"parent.name",
"Alice");
2067 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
2072 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
2073 CompileRun(
"var obj = new Obj;"
2074 "function setAge(i){ obj.age = i; };"
2075 "for(var i = 0; i <= 10000; i++) setAge(i);");
2077 ExpectInt32(
"obj.interceptor_age", 9999);
2079 ExpectInt32(
"obj.accessor_age", 10000);
2085 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
2090 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
2091 CompileRun(
"var obj = new Obj;"
2092 "function setAge(i){ obj.age = i; };"
2093 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2095 ExpectInt32(
"obj.accessor_age", 10000);
2097 ExpectInt32(
"obj.interceptor_age", 9999);
2103 Handle<FunctionTemplate> parent = FunctionTemplate::New(
CcTest::isolate());
2104 Handle<FunctionTemplate> child = FunctionTemplate::New(
CcTest::isolate());
2105 child->Inherit(parent);
2110 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2111 CompileRun(
"var child = new Child;"
2112 "function setAge(i){ child.age = i; };"
2113 "for(var i = 0; i <= 10000; i++) setAge(i);");
2115 ExpectInt32(
"child.interceptor_age", 9999);
2117 ExpectInt32(
"child.accessor_age", 10000);
2123 Handle<FunctionTemplate> parent = FunctionTemplate::New(
CcTest::isolate());
2124 Handle<FunctionTemplate> child = FunctionTemplate::New(
CcTest::isolate());
2125 child->Inherit(parent);
2130 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2131 CompileRun(
"var child = new Child;"
2132 "function setAge(i){ child.age = i; };"
2133 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2135 ExpectInt32(
"child.accessor_age", 10000);
2137 ExpectInt32(
"child.interceptor_age", 9999);
2143 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
2146 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
2147 CompileRun(
"var obj = new Obj;"
2148 "function setter(i) { this.accessor_age = i; };"
2149 "function getter() { return this.accessor_age; };"
2150 "function setAge(i) { obj.age = i; };"
2151 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2152 "for(var i = 0; i <= 10000; i++) setAge(i);");
2154 ExpectInt32(
"obj.interceptor_age", 9999);
2156 ExpectInt32(
"obj.accessor_age", 10000);
2160 ExpectInt32(
"obj.age", 10000);
2161 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
2162 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
2168 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
2171 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
2172 CompileRun(
"var obj = new Obj;"
2173 "function setter(i) { this.accessor_age = i; };"
2174 "function getter() { return this.accessor_age; };"
2175 "function setAge(i) { obj.age = i; };"
2176 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2177 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2179 ExpectInt32(
"obj.accessor_age", 10000);
2181 ExpectInt32(
"obj.interceptor_age", 9999);
2185 ExpectInt32(
"obj.age", 10000);
2186 ExpectBoolean(
"obj.hasOwnProperty('age')",
true);
2187 ExpectUndefined(
"Object.getOwnPropertyDescriptor(obj, 'age').value");
2193 Handle<FunctionTemplate> parent = FunctionTemplate::New(
CcTest::isolate());
2194 Handle<FunctionTemplate> child = FunctionTemplate::New(
CcTest::isolate());
2195 child->Inherit(parent);
2198 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2199 CompileRun(
"var child = new Child;"
2200 "function setAge(i){ child.age = i; };"
2201 "for(var i = 0; i <= 10000; i++) setAge(i);");
2203 ExpectInt32(
"child.interceptor_age", 9999);
2205 ExpectInt32(
"child.age", 10000);
2211 Handle<FunctionTemplate> parent = FunctionTemplate::New(
CcTest::isolate());
2212 Handle<FunctionTemplate> child = FunctionTemplate::New(
CcTest::isolate());
2213 child->Inherit(parent);
2216 env->
Global()->Set(v8_str(
"Child"), child->GetFunction());
2217 CompileRun(
"var child = new Child;"
2218 "function setAge(i){ child.age = i; };"
2219 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2221 ExpectInt32(
"child.age", 10000);
2223 ExpectInt32(
"child.interceptor_age", 9999);
2228 echo_named_call_count = 0;
2236 env->
Global()->Set(v8_str(
"obj"),
2238 CHECK_EQ(echo_named_call_count, 0);
2239 v8_compile(
"obj.x")->Run();
2240 CHECK_EQ(echo_named_call_count, 1);
2241 const char* code =
"var str = 'oddle'; obj[str] + obj.poddle;";
2243 String::Utf8Value value(str);
2246 CHECK_EQ(v8_compile(
"obj.flob = 10;")->Run()->Int32Value(), 10);
2247 CHECK(v8_compile(
"'myProperty' in obj")->Run()->BooleanValue());
2248 CHECK(v8_compile(
"delete obj.myProperty")->Run()->BooleanValue());
2255 static void EchoIndexedProperty(
2260 echo_indexed_call_count++;
2273 env->
Global()->Set(v8_str(
"obj"),
2275 Local<Script> script = v8_compile(
"obj[900]");
2276 CHECK_EQ(script->Run()->Int32Value(), 900);
2282 static void CheckThisIndexedPropertyHandler(
2285 CheckReturnValue(info,
FUNCTION_ADDR(CheckThisIndexedPropertyHandler));
2290 static void CheckThisNamedPropertyHandler(
2293 CheckReturnValue(info,
FUNCTION_ADDR(CheckThisNamedPropertyHandler));
2309 Local<String> property,
2327 Local<String> property,
2345 Local<String> property,
2377 CheckThisIndexedPropertyHandler,
2384 CheckThisNamedPropertyHandler,
2391 Local<v8::Object> top = templ->
GetFunction()->NewInstance();
2392 Local<v8::Object> middle = templ->
GetFunction()->NewInstance();
2395 middle->SetPrototype(top);
2396 env->
Global()->Set(v8_str(
"obj"), bottom);
2399 CompileRun(
"obj[0]");
2400 CompileRun(
"obj.x");
2403 CompileRun(
"obj[1] = 42");
2404 CompileRun(
"obj.y = 42");
2407 CompileRun(
"0 in obj");
2408 CompileRun(
"'x' in obj");
2411 CompileRun(
"delete obj[0]");
2412 CompileRun(
"delete obj.x");
2415 CompileRun(
"for (var p in obj) ;");
2419 static void PrePropertyHandlerGet(
2423 if (v8_str(
"pre")->Equals(key)) {
2429 static void PrePropertyHandlerQuery(
2432 if (v8_str(
"pre")->Equals(key)) {
2444 PrePropertyHandlerQuery);
2446 CompileRun(
"var pre = 'Object: pre'; var on = 'Object: on';");
2448 CHECK_EQ(v8_str(
"PrePropertyHandler: pre"), result_pre);
2450 CHECK_EQ(v8_str(
"Object: on"), result_on);
2460 CHECK(result->IsFalse());
2465 static const int kTargetRecursionDepth = 200;
2468 static void CallScriptRecursivelyCall(
2471 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
2472 if (depth == kTargetRecursionDepth)
return;
2473 args.
This()->Set(v8_str(
"depth"),
2479 static void CallFunctionRecursivelyCall(
2482 int depth = args.
This()->Get(v8_str(
"depth"))->Int32Value();
2483 if (depth == kTargetRecursionDepth) {
2484 printf(
"[depth = %d]\n", depth);
2487 args.
This()->Set(v8_str(
"depth"),
2490 args.
This()->Get(v8_str(
"callFunctionRecursively"));
2492 function.As<Function>()->Call(args.
This(), 0,
NULL));
2500 global->
Set(v8_str(
"callScriptRecursively"),
2502 global->
Set(v8_str(
"callFunctionRecursively"),
2507 call_recursively_script = v8_compile(
"callScriptRecursively()");
2508 call_recursively_script->Run();
2512 CompileRun(
"callFunctionRecursively()");
2516 static void ThrowingPropertyHandlerGet(
2524 static void ThrowingPropertyHandlerSet(
2538 ThrowingPropertyHandlerSet);
2542 "try { with (obj) { otto; } } catch (e) { e; }");
2545 "try { with (obj) { netto = 4; } } catch (e) { e; }");
2554 Foo->PrototypeTemplate()->Set(v8_str(
"plak"), v8_num(321));
2556 env->
Global()->Set(v8_str(
"Foo"), Foo->GetFunction());
2557 Local<Script> script = v8_compile(
"Foo.prototype.plak");
2558 CHECK_EQ(script->Run()->Int32Value(), 321);
2568 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2569 instance_templ->SetInternalFieldCount(1);
2570 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2571 CHECK_EQ(1, obj->InternalFieldCount());
2572 CHECK(obj->GetInternalField(0)->IsUndefined());
2573 obj->SetInternalField(0, v8_num(17));
2574 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
2582 global_template->SetInternalFieldCount(1);
2603 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj,
2605 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2606 obj->SetAlignedPointerInInternalField(0, value);
2608 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
2618 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2619 instance_templ->SetInternalFieldCount(1);
2620 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2621 CHECK_EQ(1, obj->InternalFieldCount());
2623 CheckAlignedPointerInInternalField(obj,
NULL);
2625 int* heap_allocated =
new int[100];
2626 CheckAlignedPointerInInternalField(obj, heap_allocated);
2627 delete[] heap_allocated;
2629 int stack_allocated[100];
2630 CheckAlignedPointerInInternalField(obj, stack_allocated);
2632 void* huge =
reinterpret_cast<void*
>(~static_cast<uintptr_t>(1));
2633 CheckAlignedPointerInInternalField(obj, huge);
2636 CHECK_EQ(1, Object::InternalFieldCount(persistent));
2637 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0));
2641 static void CheckAlignedPointerInEmbedderData(
LocalContext* env,
2644 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2645 (*env)->SetAlignedPointerInEmbedderData(index, value);
2647 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index));
2651 static void* AlignedTestPointer(
int i) {
2652 return reinterpret_cast<void*
>(i * 1234);
2660 CheckAlignedPointerInEmbedderData(&env, 0,
NULL);
2662 int* heap_allocated =
new int[100];
2663 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated);
2664 delete[] heap_allocated;
2666 int stack_allocated[100];
2667 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated);
2669 void* huge =
reinterpret_cast<void*
>(~static_cast<uintptr_t>(1));
2670 CheckAlignedPointerInEmbedderData(&env, 3, huge);
2673 for (
int i = 0; i < 100; i++) {
2677 for (
int i = 0; i < 100; i++) {
2686 (*env)->SetEmbedderData(index, data);
2687 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2700 "over the lazy dog."));
2715 int hash = obj->GetIdentityHash();
2716 int hash1 = obj->GetIdentityHash();
2729 int hash4 = obj->GetIdentityHash();
2735 CompileRun(
"Object.prototype['v8::IdentityHash'] = 42;\n");
2738 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2742 "function cnst() { return 42; };\n"
2743 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2746 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2752 i::FLAG_harmony_symbols =
true;
2779 CHECK(sym2->
Name()->Equals(v8_str(
"my-symbol")));
2782 CHECK(sym_val->IsSymbol());
2783 CHECK(sym_val->Equals(sym2));
2784 CHECK(sym_val->StrictEquals(sym2));
2788 CHECK(sym_obj->IsSymbolObject());
2791 CHECK(!sym_obj->Equals(sym2));
2792 CHECK(!sym_obj->StrictEquals(sym2));
2835 child->SetPrototype(obj);
2836 CHECK(child->Has(sym1));
2837 CHECK_EQ(2002, child->Get(sym1)->Int32Value());
2838 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2894 child->SetPrototype(obj);
2895 CHECK(child->HasPrivate(priv1));
2896 CHECK_EQ(2002, child->GetPrivate(priv1)->Int32Value());
2897 CHECK_EQ(0, child->GetOwnPropertyNames()->Length());
2902 i::FLAG_harmony_symbols =
true;
2916 CHECK(!glob_api->SameValue(glob));
2919 CHECK(!sym->SameValue(glob));
2921 CompileRun(
"var sym2 = Symbol.for('my-symbol')");
2923 CHECK(sym2->SameValue(glob));
2924 CHECK(!sym2->SameValue(glob_api));
2944 CompileRun(
"var intern = %CreateGlobalPrivateSymbol('my-private')");
2954 : contents_(contents) {}
2962 template <
typename T>
2963 static void CheckInternalFieldsAreZero(
v8::Handle<T> value) {
2964 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount());
2965 for (
int i = 0; i < value->InternalFieldCount(); i++) {
2966 CHECK_EQ(0, value->GetInternalField(i)->Int32Value());
2977 CheckInternalFieldsAreZero(ab);
2978 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2979 CHECK(!ab->IsExternal());
2983 CHECK(ab->IsExternal());
2985 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2986 uint8_t* data =
static_cast<uint8_t*
>(ab_contents.Data());
2988 env->
Global()->Set(v8_str(
"ab"), ab);
2993 result = CompileRun(
"var u8 = new Uint8Array(ab);"
2997 CHECK_EQ(1024, result->Int32Value());
3002 result = CompileRun(
"u8[0] + u8[1]");
3003 CHECK_EQ(0xDD, result->Int32Value());
3014 CompileRun(
"var ab1 = new ArrayBuffer(2);"
3015 "var u8_a = new Uint8Array(ab1);"
3017 "u8_a[1] = 0xFF; u8_a.buffer");
3018 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result);
3019 CheckInternalFieldsAreZero(ab1);
3020 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
3021 CHECK(!ab1->IsExternal());
3023 CHECK(ab1->IsExternal());
3025 result = CompileRun(
"ab1.byteLength");
3027 result = CompileRun(
"u8_a[0]");
3028 CHECK_EQ(0xAA, result->Int32Value());
3029 result = CompileRun(
"u8_a[1]");
3030 CHECK_EQ(0xFF, result->Int32Value());
3031 result = CompileRun(
"var u8_b = new Uint8Array(ab1);"
3034 CHECK_EQ(0xBB, result->Int32Value());
3035 result = CompileRun(
"u8_b[1]");
3036 CHECK_EQ(0xFF, result->Int32Value());
3038 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
3039 uint8_t* ab1_data =
static_cast<uint8_t*
>(ab1_contents.Data());
3044 result = CompileRun(
"u8_a[0] + u8_a[1]");
3045 CHECK_EQ(0xDD, result->Int32Value());
3055 memset(my_data.
start(), 0, 100);
3056 Local<v8::ArrayBuffer> ab3 =
3058 CheckInternalFieldsAreZero(ab3);
3059 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
3060 CHECK(ab3->IsExternal());
3062 env->
Global()->Set(v8_str(
"ab3"), ab3);
3067 result = CompileRun(
"var u8_b = new Uint8Array(ab3);"
3071 CHECK_EQ(100, result->Int32Value());
3076 result = CompileRun(
"u8_b[0] + u8_b[1]");
3077 CHECK_EQ(0xDD, result->Int32Value());
3094 static void CheckIsTypedArrayVarNeutered(
const char* name) {
3097 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0",
3099 CHECK(CompileRun(source.start())->IsTrue());
3102 CheckIsNeutered(ta);
3106 template <
typename TypedArray,
int kElementSize>
3107 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab,
3111 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
3112 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
3113 CHECK_EQ(length, static_cast<int>(ta->Length()));
3114 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
3127 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023);
3129 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023);
3131 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023);
3134 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511);
3136 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511);
3139 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
3141 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
3144 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
3146 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
3149 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
3150 CHECK_EQ(1, static_cast<int>(dv->ByteOffset()));
3151 CHECK_EQ(1023, static_cast<int>(dv->ByteLength()));
3155 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
3156 CheckIsNeutered(u8a);
3157 CheckIsNeutered(u8c);
3158 CheckIsNeutered(i8a);
3159 CheckIsNeutered(u16a);
3160 CheckIsNeutered(i16a);
3161 CheckIsNeutered(u32a);
3162 CheckIsNeutered(i32a);
3163 CheckIsNeutered(f32a);
3164 CheckIsNeutered(f64a);
3165 CheckDataViewIsNeutered(dv);
3175 "var ab = new ArrayBuffer(1024);"
3176 "var u8a = new Uint8Array(ab, 1, 1023);"
3177 "var u8c = new Uint8ClampedArray(ab, 1, 1023);"
3178 "var i8a = new Int8Array(ab, 1, 1023);"
3179 "var u16a = new Uint16Array(ab, 2, 511);"
3180 "var i16a = new Int16Array(ab, 2, 511);"
3181 "var u32a = new Uint32Array(ab, 4, 255);"
3182 "var i32a = new Int32Array(ab, 4, 255);"
3183 "var f32a = new Float32Array(ab, 4, 255);"
3184 "var f64a = new Float64Array(ab, 8, 127);"
3185 "var dv = new DataView(ab, 1, 1023);");
3188 Local<v8::ArrayBuffer>::Cast(CompileRun(
"ab"));
3196 CHECK_EQ(0, CompileRun(
"ab.byteLength")->Int32Value());
3198 CheckIsTypedArrayVarNeutered(
"u8a");
3199 CheckIsTypedArrayVarNeutered(
"u8c");
3200 CheckIsTypedArrayVarNeutered(
"i8a");
3201 CheckIsTypedArrayVarNeutered(
"u16a");
3202 CheckIsTypedArrayVarNeutered(
"i16a");
3203 CheckIsTypedArrayVarNeutered(
"u32a");
3204 CheckIsTypedArrayVarNeutered(
"i32a");
3205 CheckIsTypedArrayVarNeutered(
"f32a");
3206 CheckIsTypedArrayVarNeutered(
"f64a");
3208 CHECK(CompileRun(
"dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue());
3209 CheckDataViewIsNeutered(dv);
3239 CHECK(obj->
Get(empty)->IsUndefined());
3251 CHECK_EQ(2008, obj->
Get(prop_name)->Int32Value());
3278 "set_called = false;"
3279 "Object.defineProperty("
3280 " Object.prototype,"
3282 " {get: function() { return 45; },"
3283 " set: function() { set_called = true; }})");
3285 CHECK(obj->GetHiddenValue(key).IsEmpty());
3290 ExpectFalse(
"set_called");
3291 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value());
3295 static bool interceptor_for_hidden_properties_called;
3296 static void InterceptorForHiddenProperties(
3298 interceptor_for_hidden_properties_called =
true;
3307 interceptor_for_hidden_properties_called =
false;
3313 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
3314 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
3315 Local<v8::Function>
function = fun_templ->GetFunction();
3316 Local<v8::Object> obj =
function->NewInstance();
3318 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
3319 CHECK(!interceptor_for_hidden_properties_called);
3328 env->
Global()->Set(v8_str(
"ext"), ext);
3329 Local<Value> reext_obj = CompileRun(
"this.ext");
3331 int* ptr =
static_cast<int*
>(reext->
Value());
3360 global.
Reset(isolate, v8_str(
"str"));
3369 global.
Reset(isolate, v8_str(
"str"));
3384 global.
Reset(isolate, v8_str(
"str"));
3395 global.
Reset(isolate, v8_str(
"longer"));
3412 global.
Reset(isolate, v8_str(
"str"));
3423 Local<String> empty;
3424 global.
Reset(isolate, empty);
3433 return unique.
Pass();
3441 return unique.
Pass();
3450 global.
Reset(isolate, v8_str(
"str"));
3462 CHECK(copy == global);
3465 unique = copy.
Pass();
3471 CHECK(copy == global);
3474 unique = copy.
Pass();
3480 CHECK(copy == global);
3483 unique = copy.
Pass();
3490 CHECK(unique == global);
3498 template<
typename K,
typename V>
3508 Impl* impl,
const K& key, Local<V> value) {
3526 Impl* impl, K key) { }
3530 template<
typename Map>
3531 static void TestPersistentValueMap() {
3540 HandleScope scope(isolate);
3541 Local<v8::Object> obj =
map.Get(7);
3542 CHECK(obj.IsEmpty());
3544 map.Set(7, expected);
3550 CHECK(expected == removed);
3551 removed =
map.Remove(7);
3553 map.Set(8, expected);
3555 map.Set(8, expected);
3572 TestPersistentValueMap<v8::StdPersistentValueMap<int, v8::Object> >();
3577 TestPersistentValueMap<WeakPersistentValueMap>();
3590 global_string.
Reset();
3600 global1.
Reset(isolate, v8_str(
"str"));
3601 global2.
Reset(isolate, v8_str(
"str2"));
3603 CHECK_EQ(global1 == global1,
true);
3604 CHECK_EQ(global1 != global1,
false);
3607 Local<String> local1 = Local<String>::New(isolate, global1);
3608 Local<String> local2 = Local<String>::New(isolate, global2);
3611 CHECK_EQ(global1 != local1,
false);
3613 CHECK_EQ(local1 != global1,
false);
3615 CHECK_EQ(global1 == local2,
false);
3617 CHECK_EQ(local2 == global1,
false);
3623 Local<String> anotherLocal1 = Local<String>::New(isolate, global1);
3624 CHECK_EQ(local1 == anotherLocal1,
true);
3625 CHECK_EQ(local1 != anotherLocal1,
false);
3648 int number_of_weak_calls_;
3652 template<
typename T>
3655 : counter(counter) {}
3661 template <
typename T>
3662 static void WeakPointerCallback(
3664 CHECK_EQ(1234, data.GetParameter()->counter->id());
3665 data.GetParameter()->counter->increment();
3666 data.GetParameter()->handle.Reset();
3670 template<
typename T>
3671 static UniqueId MakeUniqueId(
const Persistent<T>& p) {
3679 HandleScope scope(iso);
3691 HandleScope scope(iso);
3692 g1s1.
handle.Reset(iso, Object::New(iso));
3693 g1s2.
handle.Reset(iso, Object::New(iso));
3694 g1c1.
handle.Reset(iso, Object::New(iso));
3695 g1s1.
handle.SetWeak(&g1s1, &WeakPointerCallback);
3696 g1s2.
handle.SetWeak(&g1s2, &WeakPointerCallback);
3697 g1c1.
handle.SetWeak(&g1c1, &WeakPointerCallback);
3699 g2s1.
handle.Reset(iso, Object::New(iso));
3700 g2s2.
handle.Reset(iso, Object::New(iso));
3701 g2c1.
handle.Reset(iso, Object::New(iso));
3702 g2s1.
handle.SetWeak(&g2s1, &WeakPointerCallback);
3703 g2s2.
handle.SetWeak(&g2s2, &WeakPointerCallback);
3704 g2c1.
handle.SetWeak(&g2c1, &WeakPointerCallback);
3712 HandleScope scope(iso);
3714 Set(0, Local<Value>::New(iso, g2s2.
handle)));
3716 Set(0, Local<Value>::New(iso, g1s1.
handle)));
3720 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3721 UniqueId id2 = MakeUniqueId(g2s2.
handle);
3738 root.
handle.SetWeak(&root, &WeakPointerCallback);
3746 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3747 UniqueId id2 = MakeUniqueId(g2s2.
handle);
3762 g1c1.
handle.SetWeak(&g1c1, &WeakPointerCallback);
3763 g2c1.
handle.SetWeak(&g2c1, &WeakPointerCallback);
3773 HandleScope scope(iso);
3785 HandleScope scope(iso);
3786 g1s1.
handle.Reset(iso, Object::New(iso));
3787 g1s2.
handle.Reset(iso, String::NewFromUtf8(iso,
"foo1"));
3788 g1c1.
handle.Reset(iso, String::NewFromUtf8(iso,
"foo2"));
3789 g1s1.
handle.SetWeak(&g1s1, &WeakPointerCallback);
3790 g1s2.
handle.SetWeak(&g1s2, &WeakPointerCallback);
3791 g1c1.
handle.SetWeak(&g1c1, &WeakPointerCallback);
3793 g2s1.
handle.Reset(iso, Object::New(iso));
3794 g2s2.
handle.Reset(iso, String::NewFromUtf8(iso,
"foo3"));
3795 g2c1.
handle.Reset(iso, String::NewFromUtf8(iso,
"foo4"));
3796 g2s1.
handle.SetWeak(&g2s1, &WeakPointerCallback);
3797 g2s2.
handle.SetWeak(&g2s2, &WeakPointerCallback);
3798 g2c1.
handle.SetWeak(&g2c1, &WeakPointerCallback);
3806 HandleScope scope(iso);
3814 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3815 UniqueId id2 = MakeUniqueId(g2s2.
handle);
3832 root.
handle.SetWeak(&root, &WeakPointerCallback);
3840 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3841 UniqueId id2 = MakeUniqueId(g2s2.
handle);
3856 g1c1.
handle.SetWeak(&g1c1, &WeakPointerCallback);
3857 g2c1.
handle.SetWeak(&g2c1, &WeakPointerCallback);
3867 HandleScope scope(iso);
3881 HandleScope scope(iso);
3882 g1s1.
handle.Reset(iso, Object::New(iso));
3883 g1s2.
handle.Reset(iso, Object::New(iso));
3884 g1s1.
handle.SetWeak(&g1s1, &WeakPointerCallback);
3885 g1s2.
handle.SetWeak(&g1s2, &WeakPointerCallback);
3889 g2s1.
handle.Reset(iso, Object::New(iso));
3890 g2s2.
handle.Reset(iso, Object::New(iso));
3891 g2s1.
handle.SetWeak(&g2s1, &WeakPointerCallback);
3892 g2s2.
handle.SetWeak(&g2s2, &WeakPointerCallback);
3896 g3s1.
handle.Reset(iso, Object::New(iso));
3897 g3s2.
handle.Reset(iso, Object::New(iso));
3898 g3s1.
handle.SetWeak(&g3s1, &WeakPointerCallback);
3899 g3s2.
handle.SetWeak(&g3s2, &WeakPointerCallback);
3903 g4s1.
handle.Reset(iso, Object::New(iso));
3904 g4s2.
handle.Reset(iso, Object::New(iso));
3905 g4s1.
handle.SetWeak(&g4s1, &WeakPointerCallback);
3906 g4s2.
handle.SetWeak(&g4s2, &WeakPointerCallback);
3918 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3919 UniqueId id2 = MakeUniqueId(g2s1.
handle);
3920 UniqueId id3 = MakeUniqueId(g3s1.
handle);
3921 UniqueId id4 = MakeUniqueId(g4s1.
handle);
3944 root.
handle.SetWeak(&root, &WeakPointerCallback);
3948 UniqueId id1 = MakeUniqueId(g1s1.
handle);
3949 UniqueId id2 = MakeUniqueId(g2s1.
handle);
3950 UniqueId id3 = MakeUniqueId(g3s1.
handle);
3951 UniqueId id4 = MakeUniqueId(g4s1.
handle);
3975 TEST(ApiObjectGroupsCycleForScavenger) {
3976 i::FLAG_stress_compaction =
false;
3977 i::FLAG_gc_global =
false;
3980 HandleScope scope(iso);
3992 HandleScope scope(iso);
3993 g1s1.
handle.Reset(iso, Object::New(iso));
3994 g1s2.
handle.Reset(iso, Object::New(iso));
3995 g1s1.
handle.SetWeak(&g1s1, &WeakPointerCallback);
3996 g1s2.
handle.SetWeak(&g1s2, &WeakPointerCallback);
3998 g2s1.
handle.Reset(iso, Object::New(iso));
3999 g2s2.
handle.Reset(iso, Object::New(iso));
4000 g2s1.
handle.SetWeak(&g2s1, &WeakPointerCallback);
4001 g2s2.
handle.SetWeak(&g2s2, &WeakPointerCallback);
4003 g3s1.
handle.Reset(iso, Object::New(iso));
4004 g3s2.
handle.Reset(iso, Object::New(iso));
4005 g3s1.
handle.SetWeak(&g3s1, &WeakPointerCallback);
4006 g3s2.
handle.SetWeak(&g3s2, &WeakPointerCallback);
4012 root.
handle.MarkPartiallyDependent();
4018 HandleScope handle_scope(iso);
4019 g1s1.
handle.MarkPartiallyDependent();
4020 g1s2.
handle.MarkPartiallyDependent();
4021 g2s1.
handle.MarkPartiallyDependent();
4022 g2s2.
handle.MarkPartiallyDependent();
4023 g3s1.
handle.MarkPartiallyDependent();
4024 g3s2.
handle.MarkPartiallyDependent();
4028 v8_str(
"x"), Local<Value>::New(iso, g2s1.
handle));
4032 v8_str(
"x"), Local<Value>::New(iso, g3s1.
handle));
4036 v8_str(
"x"), Local<Value>::New(iso, g1s1.
handle));
4047 root.
handle.SetWeak(&root, &WeakPointerCallback);
4048 root.
handle.MarkPartiallyDependent();
4052 HandleScope handle_scope(iso);
4053 g1s1.
handle.MarkPartiallyDependent();
4054 g1s2.
handle.MarkPartiallyDependent();
4055 g2s1.
handle.MarkPartiallyDependent();
4056 g2s2.
handle.MarkPartiallyDependent();
4057 g3s1.
handle.MarkPartiallyDependent();
4058 g3s2.
handle.MarkPartiallyDependent();
4062 v8_str(
"x"), Local<Value>::New(iso, g2s1.
handle));
4066 v8_str(
"x"), Local<Value>::New(iso, g3s1.
handle));
4070 v8_str(
"x"), Local<Value>::New(iso, g1s1.
handle));
4083 Local<Script> script = v8_compile(
"throw 'panama!';");
4085 Local<Value> result = script->Run();
4086 CHECK(result.IsEmpty());
4088 String::Utf8Value exception_value(try_catch.
Exception());
4089 CHECK_EQ(*exception_value,
"panama!");
4097 CompileRun(
"function CustomError() { this.a = 'b'; }"
4098 "(function f() { throw new CustomError(); })();");
4099 CHECK(try_catch.HasCaught());
4100 CHECK(try_catch.Exception()->ToObject()->
4101 Get(v8_str(
"a"))->Equals(v8_str(
"b")));
4113 message_received =
true;
4118 message_received =
false;
4120 CHECK(!message_received);
4125 CHECK(message_received);
4136 message_received =
true;
4141 message_received =
false;
4143 CHECK(!message_received);
4146 CompileRun(
"throw 1337;");
4147 CHECK(message_received);
4159 CHECK(v8_str(
"hidden value")->Equals(hidden_property));
4161 message_received =
true;
4166 message_received =
false;
4168 CHECK(!message_received);
4173 v8_str(
"hidden value"));
4174 context->
Global()->Set(v8_str(
"error"), error);
4175 CompileRun(
"throw error;");
4176 CHECK(message_received);
4186 message_received =
true;
4191 message_received =
false;
4194 CHECK(!message_received);
4205 CHECK(message_received);
4215 message_received =
true;
4220 message_received =
false;
4223 CHECK(!message_received);
4234 CHECK(message_received);
4244 message_received =
true;
4252 message_received =
true;
4257 message_received =
false;
4260 CHECK(!message_received);
4271 CHECK(message_received);
4275 message_received =
false;
4282 script = Script::Compile(v8_str(
"throw 'error'"),
4285 CHECK(message_received);
4295 context->
Global()->Set(v8_str(
"foo"), v8_num(14));
4296 context->
Global()->Set(v8_str(
"12"), v8_num(92));
4298 context->
Global()->Set(v8_num(13), v8_num(56));
4299 Local<Value>
foo = CompileRun(
"this.foo");
4301 Local<Value> twelve = CompileRun(
"this[12]");
4302 CHECK_EQ(92, twelve->Int32Value());
4303 Local<Value> sixteen = CompileRun(
"this[16]");
4304 CHECK_EQ(32, sixteen->Int32Value());
4305 Local<Value> thirteen = CompileRun(
"this[13]");
4306 CHECK_EQ(56, thirteen->Int32Value());
4309 CHECK_EQ(92, context->
Global()->Get(v8_str(
"12"))->Int32Value());
4313 CHECK_EQ(32, context->
Global()->Get(v8_str(
"16"))->Int32Value());
4317 CHECK_EQ(56, context->
Global()->Get(v8_str(
"13"))->Int32Value());
4326 Local<String> prop = v8_str(
"none");
4327 context->
Global()->Set(prop, v8_num(7));
4330 prop = v8_str(
"read_only");
4334 CompileRun(
"read_only = 9");
4336 context->
Global()->Set(prop, v8_num(10));
4339 prop = v8_str(
"dont_delete");
4342 CompileRun(
"delete dont_delete");
4346 prop = v8_str(
"dont_enum");
4350 prop = v8_str(
"absent");
4352 Local<Value> fake_prop = v8_num(1);
4356 Local<Value> exception =
4357 CompileRun(
"({ toString: function() { throw 'exception';} })");
4359 CHECK(try_catch.HasCaught());
4360 String::Utf8Value exception_value(try_catch.Exception());
4361 CHECK_EQ(
"exception", *exception_value);
4371 CHECK(array->Get(0)->IsUndefined());
4372 CHECK(!array->Has(0));
4373 CHECK(array->Get(100)->IsUndefined());
4374 CHECK(!array->Has(100));
4375 array->Set(2, v8_num(7));
4377 CHECK(!array->Has(0));
4378 CHECK(!array->Has(1));
4379 CHECK(array->Has(2));
4380 CHECK_EQ(7, array->Get(2)->Int32Value());
4381 Local<Value> obj = CompileRun(
"[1, 2, 3]");
4382 Local<v8::Array> arr = obj.As<
v8::Array>();
4384 CHECK_EQ(1, arr->Get(0)->Int32Value());
4385 CHECK_EQ(2, arr->Get(1)->Int32Value());
4386 CHECK_EQ(3, arr->Get(2)->Int32Value());
4398 for (
int i = 0; i < args.
Length(); i++)
4399 result->Set(i, args[i]);
4407 Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
4411 const char* fun =
"f()";
4412 Local<v8::Array> a0 = CompileRun(fun).As<
v8::Array>();
4415 const char* fun2 =
"f(11)";
4416 Local<v8::Array> a1 = CompileRun(fun2).As<
v8::Array>();
4418 CHECK_EQ(11, a1->Get(0)->Int32Value());
4420 const char* fun3 =
"f(12, 13)";
4421 Local<v8::Array> a2 = CompileRun(fun3).As<
v8::Array>();
4423 CHECK_EQ(12, a2->Get(0)->Int32Value());
4424 CHECK_EQ(13, a2->Get(1)->Int32Value());
4426 const char* fun4 =
"f(14, 15, 16)";
4427 Local<v8::Array> a3 = CompileRun(fun4).As<
v8::Array>();
4429 CHECK_EQ(14, a3->Get(0)->Int32Value());
4430 CHECK_EQ(15, a3->Get(1)->Int32Value());
4431 CHECK_EQ(16, a3->Get(2)->Int32Value());
4433 const char* fun5 =
"f(17, 18, 19, 20)";
4434 Local<v8::Array> a4 = CompileRun(fun5).As<
v8::Array>();
4436 CHECK_EQ(17, a4->Get(0)->Int32Value());
4437 CHECK_EQ(18, a4->Get(1)->Int32Value());
4438 CHECK_EQ(19, a4->Get(2)->Int32Value());
4439 CHECK_EQ(20, a4->Get(3)->Int32Value());
4450 " for (var i = 0; i < arguments.length; i++) {"
4451 " result.push(arguments[i]);"
4455 "function ReturnThisSloppy() {"
4458 "function ReturnThisStrict() {"
4462 Local<Function> Foo =
4463 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
4464 Local<Function> ReturnThisSloppy =
4465 Local<Function>::Cast(context->
Global()->Get(v8_str(
"ReturnThisSloppy")));
4466 Local<Function> ReturnThisStrict =
4467 Local<Function>::Cast(context->
Global()->Get(v8_str(
"ReturnThisStrict")));
4470 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
4474 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
4480 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2));
4488 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3));
4498 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
4507 Local<v8::Value>
r2 = ReturnThisSloppy->Call(
v8::Null(isolate), 0,
NULL);
4509 Local<v8::Value>
r3 = ReturnThisSloppy->Call(v8_num(42), 0,
NULL);
4510 CHECK(r3->IsNumberObject());
4512 Local<v8::Value>
r4 = ReturnThisSloppy->Call(v8_str(
"hello"), 0,
NULL);
4513 CHECK(r4->IsStringObject());
4515 Local<v8::Value>
r5 = ReturnThisSloppy->Call(
v8::True(isolate), 0,
NULL);
4516 CHECK(r5->IsBooleanObject());
4520 CHECK(r6->IsUndefined());
4521 Local<v8::Value>
r7 = ReturnThisStrict->Call(
v8::Null(isolate), 0,
NULL);
4522 CHECK(r7->IsNull());
4523 Local<v8::Value>
r8 = ReturnThisStrict->Call(v8_num(42), 0,
NULL);
4524 CHECK(r8->StrictEquals(v8_num(42)));
4525 Local<v8::Value>
r9 = ReturnThisStrict->Call(v8_str(
"hello"), 0,
NULL);
4526 CHECK(r9->StrictEquals(v8_str(
"hello")));
4527 Local<v8::Value>
r10 = ReturnThisStrict->Call(
v8::True(isolate), 0,
NULL);
4539 " for (var i = 0; i < arguments.length; i++) {"
4540 " result.push(arguments[i]);"
4544 Local<Function> Foo =
4545 Local<Function>::Cast(context->
Global()->Get(v8_str(
"Foo")));
4548 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0));
4552 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1));
4558 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2));
4566 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3));
4576 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4));
4587 String::Utf8Value str_value(try_catch->
Exception());
4597 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
4598 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
4599 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
4600 CHECK_EQ(0, obj->ToInt32()->Value());
4601 CHECK(0u == obj->ToUint32()->Value());
4603 CompileRun(
"var obj = -1234567890123;");
4604 obj = env->
Global()->Get(v8_str(
"obj"));
4605 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
4606 CHECK_EQ(-1912276171, obj->ToInt32()->Value());
4607 CHECK(2382691125u == obj->ToUint32()->Value());
4609 CompileRun(
"var obj = 42;");
4610 obj = env->
Global()->Get(v8_str(
"obj"));
4611 CHECK_EQ(42.0, obj->ToNumber()->Value());
4612 CHECK_EQ(42, obj->ToInt32()->Value());
4613 CHECK(42u == obj->ToUint32()->Value());
4615 CompileRun(
"var obj = -37;");
4616 obj = env->
Global()->Get(v8_str(
"obj"));
4617 CHECK_EQ(-37.0, obj->ToNumber()->Value());
4618 CHECK_EQ(-37, obj->ToInt32()->Value());
4619 CHECK(4294967259u == obj->ToUint32()->Value());
4621 CompileRun(
"var obj = 0x81234567;");
4622 obj = env->
Global()->Get(v8_str(
"obj"));
4623 CHECK_EQ(2166572391.0, obj->ToNumber()->Value());
4624 CHECK_EQ(-2128394905, obj->ToInt32()->Value());
4625 CHECK(2166572391u == obj->ToUint32()->Value());
4627 CompileRun(
"var obj = 42.3;");
4628 obj = env->
Global()->Get(v8_str(
"obj"));
4629 CHECK_EQ(42.3, obj->ToNumber()->Value());
4630 CHECK_EQ(42, obj->ToInt32()->Value());
4631 CHECK(42u == obj->ToUint32()->Value());
4633 CompileRun(
"var obj = -5726623061.75;");
4634 obj = env->
Global()->Get(v8_str(
"obj"));
4635 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
4636 CHECK_EQ(-1431655765, obj->ToInt32()->Value());
4637 CHECK(2863311531u == obj->ToUint32()->Value());
4645 CompileRun(
"var obj = Math.pow(2,32) * 1237;");
4646 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
4647 CHECK(!obj->IsInt32());
4648 CHECK(!obj->IsUint32());
4650 CompileRun(
"var obj = -1234567890123;");
4651 obj = env->
Global()->Get(v8_str(
"obj"));
4652 CHECK(!obj->IsInt32());
4653 CHECK(!obj->IsUint32());
4655 CompileRun(
"var obj = 42;");
4656 obj = env->
Global()->Get(v8_str(
"obj"));
4657 CHECK(obj->IsInt32());
4658 CHECK(obj->IsUint32());
4660 CompileRun(
"var obj = -37;");
4661 obj = env->
Global()->Get(v8_str(
"obj"));
4662 CHECK(obj->IsInt32());
4663 CHECK(!obj->IsUint32());
4665 CompileRun(
"var obj = 0x81234567;");
4666 obj = env->
Global()->Get(v8_str(
"obj"));
4667 CHECK(!obj->IsInt32());
4668 CHECK(obj->IsUint32());
4670 CompileRun(
"var obj = 42.3;");
4671 obj = env->
Global()->Get(v8_str(
"obj"));
4672 CHECK(!obj->IsInt32());
4673 CHECK(!obj->IsUint32());
4675 CompileRun(
"var obj = -5726623061.75;");
4676 obj = env->
Global()->Get(v8_str(
"obj"));
4677 CHECK(!obj->IsInt32());
4678 CHECK(!obj->IsUint32());
4680 CompileRun(
"var obj = 0.0;");
4681 obj = env->
Global()->Get(v8_str(
"obj"));
4682 CHECK(obj->IsInt32());
4683 CHECK(obj->IsUint32());
4685 CompileRun(
"var obj = -0.0;");
4686 obj = env->
Global()->Get(v8_str(
"obj"));
4687 CHECK(!obj->IsInt32());
4688 CHECK(!obj->IsUint32());
4697 "function TestClass() { };"
4698 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
4699 "var obj = new TestClass();");
4700 Local<Value> obj = env->
Global()->Get(v8_str(
"obj"));
4704 Local<Value> to_string_result = obj->ToString();
4705 CHECK(to_string_result.IsEmpty());
4706 CheckUncle(&try_catch);
4708 Local<Value> to_number_result = obj->ToNumber();
4709 CHECK(to_number_result.IsEmpty());
4710 CheckUncle(&try_catch);
4712 Local<Value> to_integer_result = obj->ToInteger();
4713 CHECK(to_integer_result.IsEmpty());
4714 CheckUncle(&try_catch);
4716 Local<Value> to_uint32_result = obj->ToUint32();
4717 CHECK(to_uint32_result.IsEmpty());
4718 CheckUncle(&try_catch);
4720 Local<Value> to_int32_result = obj->ToInt32();
4721 CHECK(to_int32_result.IsEmpty());
4722 CheckUncle(&try_catch);
4724 Local<Value> to_object_result =
v8::Undefined(isolate)->ToObject();
4725 CHECK(to_object_result.IsEmpty());
4729 int32_t int32_value = obj->Int32Value();
4731 CheckUncle(&try_catch);
4733 uint32_t uint32_value = obj->Uint32Value();
4735 CheckUncle(&try_catch);
4737 double number_value = obj->NumberValue();
4739 CheckUncle(&try_catch);
4741 int64_t integer_value = obj->IntegerValue();
4742 CHECK_EQ(0.0, static_cast<double>(integer_value));
4743 CheckUncle(&try_catch);
4749 args.
GetIsolate()->ThrowException(v8_str(
"konto"));
4760 Local<Value> result = CompileRun(args[0]->ToString());
4761 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4769 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4770 templ->Set(v8_str(
"ThrowFromC"),
4774 "var thrown = false;"
4780 Local<Value> thrown = context->
Global()->Get(v8_str(
"thrown"));
4781 CHECK(thrown->BooleanValue());
4788 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4789 templ->Set(v8_str(
"ThrowFromC"),
4793 CompileRun(
"ThrowFromC();");
4808 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4809 templ->Set(v8_str(
"CCatcher"),
4812 Local<Value> result = CompileRun(
"try {"
4814 " CCatcher('throw 7;');"
4819 CHECK(result->IsTrue());
4823 static void check_reference_error_message(
4826 const char* reference_error =
"Uncaught ReferenceError: asdf is not defined";
4827 CHECK(message->
Get()->Equals(v8_str(reference_error)));
4840 TEST(APIThrowMessageOverwrittenToString) {
4844 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4847 CompileRun(
"asdf;");
4848 CompileRun(
"var limit = {};"
4849 "limit.valueOf = fail;"
4850 "Error.stackTraceLimit = limit;");
4852 CompileRun(
"Array.prototype.pop = fail;");
4853 CompileRun(
"Object.prototype.hasOwnProperty = fail;");
4854 CompileRun(
"Object.prototype.toString = function f() { return 'Yikes'; }");
4855 CompileRun(
"Number.prototype.toString = function f() { return 'Yikes'; }");
4856 CompileRun(
"String.prototype.toString = function f() { return 'Yikes'; }");
4857 CompileRun(
"ReferenceError.prototype.toString ="
4858 " function() { return 'Whoops' }");
4859 CompileRun(
"asdf;");
4860 CompileRun(
"ReferenceError.prototype.constructor.name = void 0;");
4861 CompileRun(
"asdf;");
4862 CompileRun(
"ReferenceError.prototype.constructor = void 0;");
4863 CompileRun(
"asdf;");
4864 CompileRun(
"ReferenceError.prototype.__proto__ = new Object();");
4865 CompileRun(
"asdf;");
4866 CompileRun(
"ReferenceError.prototype = new Object();");
4867 CompileRun(
"asdf;");
4870 CompileRun(
"ReferenceError.prototype.constructor = new Object();"
4871 "ReferenceError.prototype.constructor.name = 1;"
4872 "Number.prototype.toString = function() { return 'Whoops'; };"
4873 "ReferenceError.prototype.toString = Object.prototype.toString;");
4874 CompileRun(
"asdf;");
4879 static void check_custom_error_tostring(
4882 const char* uncaught_error =
"Uncaught MyError toString";
4883 CHECK(message->
Get()->Equals(v8_str(uncaught_error)));
4892 "function MyError(name, message) { "
4893 " this.name = name; "
4894 " this.message = message; "
4896 "MyError.prototype = Object.create(Error.prototype); "
4897 "MyError.prototype.toString = function() { "
4898 " return 'MyError toString'; "
4900 "throw new MyError('my name', 'my message'); ");
4905 static void check_custom_error_message(
4908 const char* uncaught_error =
"Uncaught MyError: my message";
4910 CHECK(message->
Get()->Equals(v8_str(uncaught_error)));
4921 "function MyError(msg) { "
4922 " this.name = 'MyError'; "
4923 " this.message = msg; "
4925 "MyError.prototype = new Error(); "
4926 "throw new MyError('my message'); ");
4930 "function MyError(msg) { "
4931 " this.name = 'MyError'; "
4932 " this.message = msg; "
4934 "inherits = function(childCtor, parentCtor) { "
4935 " function tempCtor() {}; "
4936 " tempCtor.prototype = parentCtor.prototype; "
4937 " childCtor.superClass_ = parentCtor.prototype; "
4938 " childCtor.prototype = new tempCtor(); "
4939 " childCtor.prototype.constructor = childCtor; "
4941 "inherits(MyError, Error); "
4942 "throw new MyError('my message'); ");
4946 "function MyError(msg) { "
4947 " this.name = 'MyError'; "
4948 " this.message = msg; "
4950 "MyError.prototype = Object.create(Error.prototype); "
4951 "throw new MyError('my message'); ");
4960 message_received =
true;
4965 message_received =
false;
4969 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4970 templ->Set(v8_str(
"ThrowFromC"),
4973 CompileRun(
"ThrowFromC();");
4974 CHECK(message_received);
4979 TEST(APIThrowMessageAndVerboseTryCatch) {
4980 message_received =
false;
4984 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4985 templ->Set(v8_str(
"ThrowFromC"),
4990 Local<Value> result = CompileRun(
"ThrowFromC();");
4992 CHECK(result.IsEmpty());
4993 CHECK(message_received);
4998 TEST(APIStackOverflowAndVerboseTryCatch) {
4999 message_received =
false;
5005 Local<Value> result = CompileRun(
"function foo() { foo(); } foo();");
5007 CHECK(result.IsEmpty());
5008 CHECK(message_received);
5016 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5017 templ->Set(v8_str(
"ThrowFromC"),
5022 Local<Value> result = CompileRun(
"ThrowFromC(); throw 'panama';");
5023 CHECK(result.IsEmpty());
5025 String::Utf8Value exception_value(try_catch.
Exception());
5026 CHECK_EQ(
"konto", *exception_value);
5034 int count = args[0]->Int32Value();
5035 int cInterval = args[2]->Int32Value();
5037 args.
GetIsolate()->ThrowException(v8_str(
"FromC"));
5040 Local<v8::Object> global =
5041 args.
GetIsolate()->GetCurrentContext()->Global();
5042 Local<Value> fun = global->Get(v8_str(
"JSThrowCountDown"));
5047 if (count % cInterval == 0) {
5049 Local<Value> result = fun.As<Function>()->Call(global, 4, argv);
5050 int expected = args[3]->Int32Value();
5053 CHECK(result.IsEmpty());
5061 args.
GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv));
5071 bool equality = args[0]->BooleanValue();
5072 int count = args[1]->Int32Value();
5073 int expected = args[2]->Int32Value();
5086 CompileRun(
"(function() {"
5088 " eval('asldkf (*&^&*^');"
5093 CHECK(!try_catch.HasCaught());
5120 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5122 templ->Set(v8_str(
"CThrowCountDown"),
5126 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
5127 " if (count == 0) throw 'FromJS';"
5128 " if (count % jsInterval == 0) {"
5130 " var value = CThrowCountDown(count - 1,"
5134 " check(false, count, expected);"
5137 " check(true, count, expected);"
5140 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);"
5143 Local<Function> fun =
5144 Local<Function>::Cast(context->
Global()->Get(v8_str(
"JSThrowCountDown")));
5151 fun->Call(fun, argc, a0);
5155 fun->Call(fun, argc, a1);
5159 fun->Call(fun, argc, a2);
5163 fun->Call(fun, argc, a3);
5167 fun->Call(fun, argc, a4);
5171 fun->Call(fun, argc, a5);
5185 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5189 "function Run(obj) {"
5195 " return 'no exception';"
5197 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
5213 CHECK(!try_catch.HasCaught());
5214 CompileRun(
"throw 10");
5215 CHECK(try_catch.HasCaught());
5216 CHECK_EQ(10, try_catch.Exception()->Int32Value());
5218 CHECK(!try_catch.HasCaught());
5219 CompileRun(
"throw 0");
5220 CHECK(try_catch.HasCaught());
5221 CHECK_EQ(0, try_catch.Exception()->Int32Value());
5229 CHECK(!try_catch.HasCaught());
5230 CompileRun(
"var o = {}; with (o) { throw 42; }");
5231 CHECK(try_catch.HasCaught());
5239 CHECK(!try_catch.HasCaught());
5240 CompileRun(
"function f(k) { try { this[k]; } finally { return 0; } };");
5241 CompileRun(
"f({toString: function() { throw 42; }});");
5242 CHECK(!try_catch.HasCaught());
5256 v8_str(
"native_with_try_catch"),
5262 " throw new Error('a');\n"
5264 " native_with_try_catch();\n"
5270 static void TryCatchNestedHelper(
int depth) {
5274 TryCatchNestedHelper(depth - 1);
5288 TryCatchNestedHelper(5);
5289 CHECK(try_catch.HasCaught());
5296 Handle<Message> message = try_catch->
Message();
5297 Handle<Value> resource = message->GetScriptResourceName();
5300 "Uncaught Error: a"));
5301 CHECK_EQ(1, message->GetLineNumber());
5302 CHECK_EQ(6, message->GetStartColumn());
5310 CompileRunWithOrigin(
"throw new Error('a');\n",
"inner", 0, 0);
5327 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5328 templ->Set(v8_str(
"TryCatchMixedNestingHelper"),
5331 CompileRunWithOrigin(
"TryCatchMixedNestingHelper();\n",
"outer", 1, 1);
5341 CHECK(v8_str(
"a")->Equals(v8_str(
"a")));
5342 CHECK(!v8_str(
"a")->Equals(v8_str(
"b")));
5344 CHECK_EQ(v8_str(
"a"), v8_str(
"a"));
5345 CHECK_NE(v8_str(
"a"), v8_str(
"b"));
5351 CHECK(v8_str(
"a")->StrictEquals(v8_str(
"a")));
5352 CHECK(!v8_str(
"a")->StrictEquals(v8_str(
"b")));
5353 CHECK(!v8_str(
"5")->StrictEquals(v8_num(5)));
5354 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
5355 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5356 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5358 CHECK(!not_a_number->StrictEquals(not_a_number));
5367 CHECK(v8_str(
"a")->SameValue(v8_str(
"a")));
5368 CHECK(!v8_str(
"a")->SameValue(v8_str(
"b")));
5369 CHECK(!v8_str(
"5")->SameValue(v8_num(5)));
5370 CHECK(v8_num(1)->SameValue(v8_num(1)));
5371 CHECK(!v8_num(1)->SameValue(v8_num(2)));
5372 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
5373 CHECK(not_a_number->SameValue(not_a_number));
5382 Local<Script> script = v8_compile(
"x");
5383 for (
int i = 0; i < 10; i++)
5388 static void GetXValue(Local<String> name,
5401 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5402 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
5403 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5404 Local<Script> script = v8_compile(
"obj.x");
5405 for (
int i = 0; i < 10; i++) {
5406 Local<Value> result = script->Run();
5416 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5417 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
5418 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5421 Local<Script> script_desc = v8_compile(
5422 "var prop = Object.getOwnPropertyDescriptor( "
5424 "prop.configurable;");
5425 Local<Value> result = script_desc->Run();
5426 CHECK_EQ(result->BooleanValue(),
true);
5429 Local<Script> script_define = v8_compile(
5430 "var desc = { get: function(){return 42; },"
5431 " configurable: true };"
5432 "Object.defineProperty(obj, 'x', desc);"
5434 result = script_define->Run();
5438 result = script_desc->Run();
5439 CHECK_EQ(result->BooleanValue(),
true);
5442 script_define = v8_compile(
5443 "var desc = { get: function(){return 43; },"
5444 " configurable: false };"
5445 "Object.defineProperty(obj, 'x', desc);"
5447 result = script_define->Run();
5449 result = script_desc->Run();
5450 CHECK_EQ(result->BooleanValue(),
false);
5454 result = script_define->Run();
5455 CHECK(try_catch.HasCaught());
5456 String::Utf8Value exception_value(try_catch.Exception());
5457 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
5464 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5465 templ->SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut"));
5467 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5469 Local<Script> script_desc = v8_compile(
5471 "Object.getOwnPropertyDescriptor( "
5473 "prop.configurable;");
5474 Local<Value> result = script_desc->Run();
5475 CHECK_EQ(result->BooleanValue(),
true);
5477 Local<Script> script_define = v8_compile(
5478 "var desc = {get: function(){return 42; },"
5479 " configurable: true };"
5480 "Object.defineProperty(obj, 'x', desc);"
5482 result = script_define->Run();
5486 result = script_desc->Run();
5487 CHECK_EQ(result->BooleanValue(),
true);
5490 script_define = v8_compile(
5491 "var desc = {get: function(){return 43; },"
5492 " configurable: false };"
5493 "Object.defineProperty(obj, 'x', desc);"
5495 result = script_define->Run();
5497 result = script_desc->Run();
5499 CHECK_EQ(result->BooleanValue(),
false);
5502 result = script_define->Run();
5503 CHECK(try_catch.HasCaught());
5504 String::Utf8Value exception_value(try_catch.Exception());
5505 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
5518 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5521 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
5522 CompileRun(
"var obj2 = {};");
5524 CHECK(CompileRun(
"obj1.x")->IsUndefined());
5525 CHECK(CompileRun(
"obj2.x")->IsUndefined());
5527 CHECK(GetGlobalProperty(&context,
"obj1")->
5528 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5530 ExpectString(
"obj1.x",
"x");
5531 CHECK(CompileRun(
"obj2.x")->IsUndefined());
5533 CHECK(GetGlobalProperty(&context,
"obj2")->
5534 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5536 ExpectString(
"obj1.x",
"x");
5537 ExpectString(
"obj2.x",
"x");
5539 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5540 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5542 CompileRun(
"Object.defineProperty(obj1, 'x',"
5543 "{ get: function() { return 'y'; }, configurable: true })");
5545 ExpectString(
"obj1.x",
"y");
5546 ExpectString(
"obj2.x",
"x");
5548 CompileRun(
"Object.defineProperty(obj2, 'x',"
5549 "{ get: function() { return 'y'; }, configurable: true })");
5551 ExpectString(
"obj1.x",
"y");
5552 ExpectString(
"obj2.x",
"y");
5554 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5555 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5557 CHECK(GetGlobalProperty(&context,
"obj1")->
5558 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5559 CHECK(GetGlobalProperty(&context,
"obj2")->
5560 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5562 ExpectString(
"obj1.x",
"x");
5563 ExpectString(
"obj2.x",
"x");
5565 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5566 ExpectTrue(
"Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5569 CompileRun(
"Object.defineProperty(obj1, 'x',"
5570 "{ get: function() { return 'z'; }, configurable: false })");
5571 CompileRun(
"Object.defineProperty(obj2, 'x',"
5572 "{ get: function() { return 'z'; }, configurable: false })");
5574 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5575 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5577 ExpectString(
"obj1.x",
"z");
5578 ExpectString(
"obj2.x",
"z");
5580 CHECK(!GetGlobalProperty(&context,
"obj1")->
5581 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5582 CHECK(!GetGlobalProperty(&context,
"obj2")->
5583 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5585 ExpectString(
"obj1.x",
"z");
5586 ExpectString(
"obj2.x",
"z");
5593 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5596 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
5597 CompileRun(
"var obj2 = {};");
5599 CHECK(GetGlobalProperty(&context,
"obj1")->SetAccessor(
5603 CHECK(GetGlobalProperty(&context,
"obj2")->SetAccessor(
5608 ExpectString(
"obj1.x",
"x");
5609 ExpectString(
"obj2.x",
"x");
5611 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5612 ExpectTrue(
"!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5614 CHECK(!GetGlobalProperty(&context,
"obj1")->
5615 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5616 CHECK(!GetGlobalProperty(&context,
"obj2")->
5617 SetAccessor(v8_str(
"x"), GetXValue,
NULL, v8_str(
"donut")));
5621 CompileRun(
"Object.defineProperty(obj1, 'x',"
5622 "{get: function() { return 'func'; }})");
5624 String::Utf8Value exception_value(try_catch.
Exception());
5625 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
5629 CompileRun(
"Object.defineProperty(obj2, 'x',"
5630 "{get: function() { return 'func'; }})");
5632 String::Utf8Value exception_value(try_catch.
Exception());
5633 CHECK_EQ(*exception_value,
"TypeError: Cannot redefine property: x");
5638 static void Get239Value(Local<String> name,
5650 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5653 context->
Global()->Set(v8_str(
"obj1"), templ->NewInstance());
5654 CompileRun(
"var obj2 = {};");
5656 CHECK(GetGlobalProperty(&context,
"obj1")->SetAccessor(
5660 CHECK(GetGlobalProperty(&context,
"obj2")->SetAccessor(
5665 ExpectString(
"obj1[239]",
"239");
5666 ExpectString(
"obj2[239]",
"239");
5667 ExpectString(
"obj1['239']",
"239");
5668 ExpectString(
"obj2['239']",
"239");
5675 static void SetXValue(Local<String> name,
5689 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5690 templ->SetAccessor(v8_str(
"x"), GetXValue, SetXValue, v8_str(
"donut"));
5692 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5693 Local<Script> script = v8_compile(
"obj.x = 4");
5694 for (
int i = 0; i < 10; i++) {
5706 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5707 templ->SetAccessor(v8_str(
"x"),
NULL, SetXValue, v8_str(
"donut"));
5709 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5710 Local<Script> script = v8_compile(
"obj.x = 4; obj.x");
5711 for (
int i = 0; i < 10; i++) {
5723 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5724 templ->SetAccessor(v8_str(
"x"),
5725 static_cast<v8::AccessorGetterCallback>(
NULL),
5729 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5730 Local<Script> script = v8_compile(
"obj.x = 4; obj.x");
5731 for (
int i = 0; i < 10; i++) {
5737 static void XPropertyGetter(Local<String> property,
5748 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5749 templ->SetNamedPropertyHandler(XPropertyGetter);
5751 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5752 Local<Script> script = v8_compile(
"obj.x");
5753 for (
int i = 0; i < 10; i++) {
5754 Local<Value> result = script->Run();
5763 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5764 templ->SetNamedPropertyHandler(XPropertyGetter);
5767 context->
Global()->Set(v8_str(
"interceptor_obj"), templ->NewInstance());
5768 Local<Script> script = v8_compile(
"interceptor_obj.x");
5769 for (
int i = 0; i < 10; i++) {
5770 Local<Value> result = script->Run();
5778 Local<Value> result =
5779 CompileRun(
"function get_x(o) { return o.x; };"
5780 "var obj = { x : 42, y : 0 };"
5782 "for (var i = 0; i < 10; i++) get_x(obj);"
5783 "interceptor_obj.x = 42;"
5784 "interceptor_obj.y = 10;"
5785 "delete interceptor_obj.y;"
5786 "get_x(interceptor_obj)");
5797 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5798 templ->SetNamedPropertyHandler(XPropertyGetter);
5801 context1->Global()->Set(v8_str(
"interceptor_obj"),
object);
5804 CompileRun(
"interceptor_obj.y = 0;"
5805 "delete interceptor_obj.y;");
5812 context2->
Global()->Set(v8_str(
"interceptor_obj"),
object);
5813 Local<Value> result =
5814 CompileRun(
"function get_x(o) { return o.x; }"
5815 "interceptor_obj.x = 42;"
5816 "for (var i=0; i != 10; i++) {"
5817 " get_x(interceptor_obj);"
5819 "get_x(interceptor_obj)");
5827 CompileRun(
"var obj = { x : 0 }; delete obj.x;");
5832 static void SetXOnPrototypeGetter(
5833 Local<String> property,
5847 Local<v8::FunctionTemplate> function_template =
5849 Local<v8::ObjectTemplate> instance_template
5850 = function_template->InstanceTemplate();
5851 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
5853 context->
Global()->Set(v8_str(
"F"), function_template->GetFunction());
5855 CompileRun(
"var o = new F(); o.x = 23;");
5857 Local<Value> result = CompileRun(
"o = new F(); o.x");
5858 CHECK_EQ(result->Int32Value(), 23);
5862 static void IndexedPropertyGetter(
5872 static void IndexedPropertySetter(
5886 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5887 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
5888 IndexedPropertySetter);
5890 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5891 Local<Script> getter_script = v8_compile(
5892 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];");
5893 Local<Script> setter_script = v8_compile(
5894 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
5897 Local<Script> interceptor_setter_script = v8_compile(
5898 "obj.__defineSetter__(\"39\", function(val){this.foo = \"hit\";});"
5901 Local<Script> interceptor_getter_script = v8_compile(
5903 Local<Value> result = getter_script->Run();
5905 result = setter_script->Run();
5907 result = interceptor_setter_script->Run();
5909 result = interceptor_getter_script->Run();
5914 static void UnboxedDoubleIndexedPropertyGetter(
5924 static void UnboxedDoubleIndexedPropertySetter(
5938 Local<Script> indexed_property_names_script = v8_compile(
5939 "keys = new Array(); keys[125000] = 1;"
5940 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
5941 "keys.length = 25; keys;");
5942 Local<Value> result = indexed_property_names_script->Run();
5952 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5953 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
5954 UnboxedDoubleIndexedPropertySetter,
5959 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
5961 Local<Script> create_unboxed_double_script = v8_compile(
5962 "obj[125000] = 1; for(i = 0; i < 80000; i+=2) { obj[i] = i; } "
5964 "for (x in obj) {key_count++;};"
5966 Local<Value> result = create_unboxed_double_script->Run();
5967 CHECK(result->ToObject()->HasRealIndexedProperty(2000));
5968 Local<Script> key_count_check = v8_compile(
"key_count;");
5969 result = key_count_check->Run();
5977 Local<Script> indexed_property_names_script = v8_compile(
5979 " return arguments;"
5981 "keys = f(0, 1, 2, 3);"
5983 Local<Object> result =
5987 v8::Utils::OpenHandle<Object, i::JSObject>(result);
5993 static void SloppyIndexedPropertyGetter(
6008 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6009 templ->SetIndexedPropertyHandler(SloppyIndexedPropertyGetter,
6015 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
6016 Local<Script> create_args_script = v8_compile(
6017 "var key_count = 0;"
6018 "for (x in obj) {key_count++;} key_count;");
6019 Local<Value> result = create_args_script->Run();
6024 static void IdentityIndexedPropertyGetter(
6034 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6035 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6038 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
6041 const char* fast_case_code =
6042 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
6043 ExpectString(fast_case_code,
"0");
6046 const char* slow_case_code =
6047 "obj.x = 1; delete obj.x;"
6048 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
6049 ExpectString(slow_case_code,
"1");
6056 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6057 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6060 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
6065 " for (var i = 0; i < 100; i++) {"
6067 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
6073 ExpectString(code,
"PASSED");
6080 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6081 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6084 Local<v8::Object> obj = templ->NewInstance();
6085 obj->TurnOnAccessCheck();
6086 context->
Global()->Set(v8_str(
"obj"), obj);
6090 " for (var i = 0; i < 100; i++) {"
6092 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
6098 ExpectString(code,
"PASSED");
6103 i::FLAG_allow_natives_syntax =
true;
6106 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6107 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6110 Local<v8::Object> obj = templ->NewInstance();
6111 context->
Global()->Set(v8_str(
"obj"), obj);
6115 " for (var i = 0; i < 100; i++) {"
6116 " var expected = i;"
6118 " %EnableAccessChecks(obj);"
6119 " expected = undefined;"
6122 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6123 " if (i == 5) %DisableAccessChecks(obj);"
6129 ExpectString(code,
"PASSED");
6136 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6137 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6140 Local<v8::Object> obj = templ->NewInstance();
6141 context->
Global()->Set(v8_str(
"obj"), obj);
6145 " for (var i = 0; i < 100; i++) {"
6147 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
6153 ExpectString(code,
"PASSED");
6160 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6161 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6164 Local<v8::Object> obj = templ->NewInstance();
6165 context->
Global()->Set(v8_str(
"obj"), obj);
6169 " for (var i = 0; i < 100; i++) {"
6170 " var expected = i;"
6174 " expected = undefined;"
6177 " /* probe minimal Smi number on 32-bit platforms */"
6178 " key = -(1 << 30);"
6179 " expected = undefined;"
6182 " /* probe minimal Smi number on 64-bit platforms */"
6184 " expected = undefined;"
6186 " var v = obj[key];"
6187 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6193 ExpectString(code,
"PASSED");
6200 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6201 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6204 Local<v8::Object> obj = templ->NewInstance();
6205 context->
Global()->Set(v8_str(
"obj"), obj);
6209 " for (var i = 0; i < 100; i++) {"
6210 " var expected = i;"
6214 " expected = undefined;"
6216 " var v = obj[key];"
6217 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6223 ExpectString(code,
"PASSED");
6230 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6231 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6234 Local<v8::Object> obj = templ->NewInstance();
6235 context->
Global()->Set(v8_str(
"obj"), obj);
6238 "var original = obj;"
6240 " for (var i = 0; i < 100; i++) {"
6241 " var expected = i;"
6243 " obj = {50: 'foobar'};"
6244 " expected = 'foobar';"
6247 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6248 " if (i == 50) obj = original;"
6254 ExpectString(code,
"PASSED");
6261 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6262 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6265 Local<v8::Object> obj = templ->NewInstance();
6266 context->
Global()->Set(v8_str(
"obj"), obj);
6269 "var original = obj;"
6271 " for (var i = 0; i < 100; i++) {"
6272 " var expected = i;"
6275 " expected = undefined;"
6278 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
6279 " if (i == 5) obj = original;"
6285 ExpectString(code,
"PASSED");
6292 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6293 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
6296 Local<v8::Object> obj = templ->NewInstance();
6297 context->
Global()->Set(v8_str(
"obj"), obj);
6300 "var o = {__proto__: obj};"
6302 " for (var i = 0; i < 100; i++) {"
6304 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
6310 ExpectString(code,
"PASSED");
6321 Local<String> password = v8_str(
"Password");
6327 global0->
Set(v8_str(
"custom"), v8_num(1234));
6328 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
6332 context1->SetSecurityToken(password);
6334 global1->
Set(v8_str(
"custom"), v8_num(1234));
6336 CHECK_EQ(1234, global0->
Get(v8_str(
"custom"))->Int32Value());
6337 CHECK_EQ(1234, global1->
Get(v8_str(
"custom"))->Int32Value());
6341 context2->SetSecurityToken(password);
6344 CHECK_EQ(0, global1->
Get(v8_str(
"custom"))->Int32Value());
6345 CHECK_EQ(0, global2->
Get(v8_str(
"custom"))->Int32Value());
6364 proto0->
Set(v8_str(
"custom"), v8_num(1234));
6375 CHECK(!proto1->Has(v8_str(
"custom")));
6388 Local<String> source = v8_str(
"Object.prototype.obj = 1234;"
6389 "Array.prototype.arr = 4567;"
6393 Local<Script> script0 = v8_compile(source);
6394 CHECK_EQ(8901.0, script0->Run()->NumberValue());
6397 Local<Script> script1 = v8_compile(source);
6398 CHECK_EQ(8901.0, script1->Run()->NumberValue());
6406 Local<v8::FunctionTemplate> desc =
6408 desc->InstanceTemplate()->MarkAsUndetectable();
6410 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6411 env->
Global()->Set(v8_str(
"undetectable"), obj);
6413 ExpectString(
"undetectable.toString()",
"[object Object]");
6414 ExpectString(
"typeof undetectable",
"undefined");
6415 ExpectString(
"typeof(undetectable)",
"undefined");
6416 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
6417 ExpectBoolean(
"typeof undetectable == 'object'",
false);
6418 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
6419 ExpectBoolean(
"!undetectable",
true);
6421 ExpectObject(
"true&&undetectable", obj);
6422 ExpectBoolean(
"false&&undetectable",
false);
6423 ExpectBoolean(
"true||undetectable",
true);
6424 ExpectObject(
"false||undetectable", obj);
6426 ExpectObject(
"undetectable&&true", obj);
6427 ExpectObject(
"undetectable&&false", obj);
6428 ExpectBoolean(
"undetectable||true",
true);
6429 ExpectBoolean(
"undetectable||false",
false);
6431 ExpectBoolean(
"undetectable==null",
true);
6432 ExpectBoolean(
"null==undetectable",
true);
6433 ExpectBoolean(
"undetectable==undefined",
true);
6434 ExpectBoolean(
"undefined==undetectable",
true);
6435 ExpectBoolean(
"undetectable==undetectable",
true);
6438 ExpectBoolean(
"undetectable===null",
false);
6439 ExpectBoolean(
"null===undetectable",
false);
6440 ExpectBoolean(
"undetectable===undefined",
false);
6441 ExpectBoolean(
"undefined===undetectable",
false);
6442 ExpectBoolean(
"undetectable===undetectable",
true);
6452 desc->InstanceTemplate()->MarkAsUndetectable();
6454 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6455 env->
Global()->Set(v8_str(
"undetectable"), obj);
6457 ExpectBoolean(
"undefined == void 0",
true);
6458 ExpectBoolean(
"undetectable == void 0",
true);
6459 ExpectBoolean(
"null == void 0",
true);
6460 ExpectBoolean(
"undefined === void 0",
true);
6461 ExpectBoolean(
"undetectable === void 0",
false);
6462 ExpectBoolean(
"null === void 0",
false);
6464 ExpectBoolean(
"void 0 == undefined",
true);
6465 ExpectBoolean(
"void 0 == undetectable",
true);
6466 ExpectBoolean(
"void 0 == null",
true);
6467 ExpectBoolean(
"void 0 === undefined",
true);
6468 ExpectBoolean(
"void 0 === undetectable",
false);
6469 ExpectBoolean(
"void 0 === null",
false);
6471 ExpectString(
"(function() {"
6473 " return x === void 0;"
6475 " return e.toString();"
6478 "ReferenceError: x is not defined");
6479 ExpectString(
"(function() {"
6481 " return void 0 === x;"
6483 " return e.toString();"
6486 "ReferenceError: x is not defined");
6496 desc->InstanceTemplate()->MarkAsUndetectable();
6498 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6499 env->
Global()->Set(v8_str(
"undetectable"), obj);
6501 Local<String> source = v8_str(
"undetectable.x = 42;"
6504 Local<Script> script = v8_compile(source);
6508 ExpectBoolean(
"Object.isExtensible(undetectable)",
true);
6510 source = v8_str(
"Object.preventExtensions(undetectable);");
6511 script = v8_compile(source);
6513 ExpectBoolean(
"Object.isExtensible(undetectable)",
false);
6515 source = v8_str(
"undetectable.y = 2000;");
6516 script = v8_compile(source);
6518 ExpectBoolean(
"undetectable.y == undefined",
true);
6527 Local<String> obj = String::NewFromUtf8(env->
GetIsolate(),
"foo",
6528 String::kUndetectableString);
6529 env->
Global()->Set(v8_str(
"undetectable"), obj);
6531 ExpectString(
"undetectable",
"foo");
6532 ExpectString(
"typeof undetectable",
"undefined");
6533 ExpectString(
"typeof(undetectable)",
"undefined");
6534 ExpectBoolean(
"typeof undetectable == 'undefined'",
true);
6535 ExpectBoolean(
"typeof undetectable == 'string'",
false);
6536 ExpectBoolean(
"if (undetectable) { true; } else { false; }",
false);
6537 ExpectBoolean(
"!undetectable",
true);
6539 ExpectObject(
"true&&undetectable", obj);
6540 ExpectBoolean(
"false&&undetectable",
false);
6541 ExpectBoolean(
"true||undetectable",
true);
6542 ExpectObject(
"false||undetectable", obj);
6544 ExpectObject(
"undetectable&&true", obj);
6545 ExpectObject(
"undetectable&&false", obj);
6546 ExpectBoolean(
"undetectable||true",
true);
6547 ExpectBoolean(
"undetectable||false",
false);
6549 ExpectBoolean(
"undetectable==null",
true);
6550 ExpectBoolean(
"null==undetectable",
true);
6551 ExpectBoolean(
"undetectable==undefined",
true);
6552 ExpectBoolean(
"undefined==undetectable",
true);
6553 ExpectBoolean(
"undetectable==undetectable",
true);
6556 ExpectBoolean(
"undetectable===null",
false);
6557 ExpectBoolean(
"null===undetectable",
false);
6558 ExpectBoolean(
"undetectable===undefined",
false);
6559 ExpectBoolean(
"undefined===undetectable",
false);
6560 ExpectBoolean(
"undetectable===undetectable",
true);
6565 i::FLAG_allow_natives_syntax =
true;
6569 Local<String> obj = String::NewFromUtf8(env->
GetIsolate(),
"foo",
6570 String::kUndetectableString);
6571 env->
Global()->Set(v8_str(
"undetectable"), obj);
6572 env->
Global()->Set(v8_str(
"detectable"), v8_str(
"bar"));
6575 "function testBranch() {"
6576 " if (!%_IsUndetectableObject(undetectable)) throw 1;"
6577 " if (%_IsUndetectableObject(detectable)) throw 2;"
6579 "function testBool() {"
6580 " var b1 = !%_IsUndetectableObject(undetectable);"
6581 " var b2 = %_IsUndetectableObject(detectable);"
6586 "%OptimizeFunctionOnNextCall(testBranch);"
6587 "%OptimizeFunctionOnNextCall(testBool);"
6588 "for (var i = 0; i < 10; i++) {"
6597 template <
typename T>
static void USE(
T) { }
6606 Local<String> str = v8_str(
"foo");
6609 Local<Script> scr = v8_compile(
"");
6612 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
6618 static void HandleLogDelegator(
6627 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
6628 global_template->Set(v8_str(
"JSNI_Log"),
6631 Context::Scope context_scope(context);
6632 CompileRun(
"JSNI_Log('LOG')");
6636 static const char* kSimpleExtensionSource =
6645 const char* extension_names[] = {
"simpletest" };
6649 Context::Scope lock(context);
6658 const char* extension_names[] = {
"nulltest" };
6662 Context::Scope lock(context);
6668 static const char* kEmbeddedExtensionSource =
6669 "function Ret54321(){return 54321;}~~@@$"
6670 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6671 static const int kEmbeddedExtensionSourceValidLen = 34;
6674 TEST(ExtensionMissingSourceLength) {
6677 kEmbeddedExtensionSource));
6678 const char* extension_names[] = {
"srclentest_fail" };
6687 for (
int source_len = kEmbeddedExtensionSourceValidLen - 1;
6688 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
6693 kEmbeddedExtensionSource, 0, 0,
6695 const char* extension_names[1] = { extension_name.
start() };
6699 if (source_len == kEmbeddedExtensionSourceValidLen) {
6700 Context::Scope lock(context);
6711 static const char* kEvalExtensionSource1 =
6712 "function UseEval1() {"
6714 " return eval('x');"
6718 static const char* kEvalExtensionSource2 =
6722 " return eval('x');"
6724 " this.UseEval2 = e;"
6732 const char* extension_names[] = {
"evaltest1",
"evaltest2" };
6736 Context::Scope lock(context);
6739 result = CompileRun(
"UseEval2()");
6744 static const char* kWithExtensionSource1 =
6745 "function UseWith1() {"
6747 " with({x:87}) { return x; }"
6752 static const char* kWithExtensionSource2 =
6756 " with ({x:87}) { return x; }"
6758 " this.UseWith2 = e;"
6766 const char* extension_names[] = {
"withtest1",
"withtest2" };
6770 Context::Scope lock(context);
6773 result = CompileRun(
"UseWith2()");
6780 Extension* extension =
new Extension(
"autotest", kSimpleExtensionSource);
6781 extension->set_auto_enable(
true);
6785 Context::Scope lock(context);
6791 static const char* kSyntaxErrorInExtensionSource =
6800 kSyntaxErrorInExtensionSource));
6801 const char* extension_names[] = {
"syntaxerror" };
6809 static const char* kExceptionInExtensionSource =
6818 kExceptionInExtensionSource));
6819 const char* extension_names[] = {
"exception" };
6827 static const char* kNativeCallInExtensionSource =
6828 "function call_runtime_last_index_of(x) {"
6829 " return %StringLastIndexOf(x, 'bob', 10);"
6833 static const char* kNativeCallTest =
6834 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
6840 kNativeCallInExtensionSource));
6841 const char* extension_names[] = {
"nativecall" };
6845 Context::Scope lock(context);
6856 : Extension(name, source),
6875 const char* name =
"nativedecl";
6877 "native function foo();"));
6878 const char* extension_names[] = { name };
6882 Context::Scope lock(context);
6888 TEST(NativeFunctionDeclarationError) {
6890 const char* name =
"nativedeclerr";
6893 "native\nfunction foo();"));
6894 const char* extension_names[] = { name };
6902 TEST(NativeFunctionDeclarationErrorEscape) {
6904 const char* name =
"nativedeclerresc";
6909 "nativ\\u0065 function foo();"));
6910 const char* extension_names[] = { name };
6918 static void CheckDependencies(
const char* name,
const char* expected) {
6923 context->
Global()->Get(v8_str(
"loaded")));
6935 static const char* kEDeps[] = {
"D" };
6937 static const char* kDDeps[] = {
"B",
"C" };
6939 static const char* kBCDeps[] = {
"A" };
6943 CheckDependencies(
"A",
"undefinedA");
6944 CheckDependencies(
"B",
"undefinedAB");
6945 CheckDependencies(
"C",
"undefinedAC");
6946 CheckDependencies(
"D",
"undefinedABCD");
6947 CheckDependencies(
"E",
"undefinedABCDE");
6949 static const char* exts[2] = {
"C",
"E" };
6952 CHECK_EQ(v8_str(
"undefinedACBDE"), context->
Global()->Get(v8_str(
"loaded")));
6956 static const char* kExtensionTestScript =
6957 "native function A();"
6958 "native function B();"
6959 "native function C();"
6961 " if (i == 0) return A();"
6962 " if (i == 1) return B();"
6963 " if (i == 2) return C();"
6970 args.
This()->Set(v8_str(
"data"), args.
Data());
6987 static int lookup_count = 0;
6991 if (name->
Equals(v8_str(
"A"))) {
6994 }
else if (name->
Equals(v8_str(
"B"))) {
6997 }
else if (name->
Equals(v8_str(
"C"))) {
7009 static const char* exts[1] = {
"functiontest" };
7014 CompileRun(
"Foo(0)"));
7016 CompileRun(
"Foo(1)"));
7018 CompileRun(
"Foo(2)"));
7025 static const char* exts[1] = {
"functiontest" };
7028 for (
int i = 0; i < 10; i++) {
7032 CompileRun(
"(new A()).data"));
7034 CompileRun(
"(new B()).data"));
7036 CompileRun(
"(new C()).data"));
7041 static const char* last_location;
7042 static const char* last_message;
7044 if (last_location ==
NULL) {
7045 last_location = location;
7056 static const char* aDeps[] = {
"B" };
7058 static const char* bDeps[] = {
"A" };
7060 last_location =
NULL;
7082 CompileRun(
"throw Error()");
7093 static void DisposeAndSetFlag(
7104 Context::Scope context_scope(context);
7114 object_a.
flag =
false;
7115 object_b.
flag =
false;
7128 static void InvokeScavenge() {
7133 static void InvokeMarkSweep() {
7138 static void ForceScavenge(
7146 static void ForceMarkSweep(
7158 Context::Scope context_scope(context);
7160 static const int kNumberOfGCTypes = 2;
7163 Callback gc_forcing_callback[kNumberOfGCTypes] =
7164 {&ForceScavenge, &ForceMarkSweep};
7166 typedef void (*GCInvoker)();
7167 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
7169 for (
int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
7170 for (
int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
7176 object.flag =
false;
7177 object.handle.SetWeak(&
object, gc_forcing_callback[inner_gc]);
7178 object.handle.MarkIndependent();
7179 invoke_gc[outer_gc]();
7186 static void RevivingCallback(
7197 Context::Scope context_scope(context);
7203 object.handle.Reset(isolate, o);
7206 o->
Set(y_str, y_str);
7208 object.flag =
false;
7209 object.handle.SetWeak(&
object, &RevivingCallback);
7210 object.handle.MarkIndependent();
7220 CHECK(o->
Get(y_str)->Equals(y_str));
7228 static void ArgumentsTestCallback(
7247 global->
Set(v8_str(
"f"),
7250 args_fun = context->
Global()->Get(v8_str(
"f")).
As<Function>();
7251 v8_compile(
"f(1, 2, 3)")->Run();
7255 static void NoBlockGetterX(Local<String> name,
7260 static void NoBlockGetterI(uint32_t index,
7265 static void PDeleter(Local<String> name,
7267 if (!name->Equals(v8_str(
"foo"))) {
7275 static void IDeleter(uint32_t index,
7298 CHECK(v8_compile(
"delete k.foo")->Run()->IsFalse());
7299 CHECK(v8_compile(
"delete k.bar")->Run()->IsTrue());
7301 CHECK_EQ(v8_compile(
"k.foo")->Run(), v8_str(
"foo"));
7302 CHECK(v8_compile(
"k.bar")->Run()->IsUndefined());
7304 CHECK(v8_compile(
"delete k[2]")->Run()->IsFalse());
7305 CHECK(v8_compile(
"delete k[4]")->Run()->IsTrue());
7307 CHECK_EQ(v8_compile(
"k[2]")->Run(), v8_num(2));
7308 CHECK(v8_compile(
"k[4]")->Run()->IsUndefined());
7312 static void GetK(Local<String> name,
7315 if (name->Equals(v8_str(
"foo")) ||
7316 name->Equals(v8_str(
"bar")) ||
7317 name->Equals(v8_str(
"baz"))) {
7323 static void IndexedGetK(uint32_t index,
7326 if (index == 0 || index == 1) info.
GetReturnValue().SetUndefined();
7362 "k[4294967295] = 0;"
7364 "k[4294967296] = 0;"
7368 "k[30000000000] = 0;"
7371 "for (var prop in k) {"
7372 " result.push(prop);"
7411 static void PGetter(Local<String> name,
7416 info.
GetIsolate()->GetCurrentContext()->Global();
7418 if (name->Equals(v8_str(
"p1"))) {
7420 }
else if (name->Equals(v8_str(
"p2"))) {
7422 }
else if (name->Equals(v8_str(
"p3"))) {
7424 }
else if (name->Equals(v8_str(
"p4"))) {
7435 "o1.__proto__ = { };"
7436 "var o2 = { __proto__: o1 };"
7437 "var o3 = { __proto__: o2 };"
7438 "var o4 = { __proto__: o3 };"
7439 "for (var i = 0; i < 10; i++) o4.p4;"
7440 "for (var i = 0; i < 10; i++) o3.p3;"
7441 "for (var i = 0; i < 10; i++) o2.p2;"
7442 "for (var i = 0; i < 10; i++) o1.p1;");
7446 static void PGetter2(Local<String> name,
7451 info.
GetIsolate()->GetCurrentContext()->Global();
7453 if (name->Equals(v8_str(
"p1"))) {
7455 }
else if (name->Equals(v8_str(
"p2"))) {
7457 }
else if (name->Equals(v8_str(
"p3"))) {
7459 }
else if (name->Equals(v8_str(
"p4"))) {
7484 p_getter_count2 = 0;
7497 for (
int i = 0; i < 100; i++) {
7501 context->
Global()->Set(v8_str(
"o2"), obj);
7503 CompileRun(
"o.__proto__ === o2.__proto__");
7505 context->
Global()->Set(v8_str(
"o"), obj);
7512 if (*a == 0 && *b == 0)
return 0;
7513 if (*a != *b)
return 0 + *a - *b;
7522 if (n-- == 0)
return 0;
7523 if (*a == 0 && *b == 0)
return 0;
7524 if (*a != *b)
return 0 + *a - *b;
7532 int len = str->Utf8Length();
7536 len = str->Utf8Length();
7551 uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 };
7563 uint16_t pair[2] = { 0xd800, 0xdc00 };
7566 const int kStride = 4;
7569 "for (var i = 0; i < 0xd800; i += 4) {"
7570 " left = left + String.fromCharCode(i);"
7574 "for (var i = 0; i < 0xd800; i += 4) {"
7575 " right = String.fromCharCode(i) + right;"
7578 Handle<String> left_tree = global->
Get(v8_str(
"left")).As<String>();
7579 Handle<String> right_tree = global->
Get(v8_str(
"right")).As<String>();
7582 CHECK_EQ(0xd800 / kStride, left_tree->Length());
7583 CHECK_EQ(0xd800 / kStride, right_tree->Length());
7586 char utf8buf[0xd800 * 3];
7591 memset(utf8buf, 0x1, 1000);
7592 len = str2->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen);
7595 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
7597 memset(utf8buf, 0x1, 1000);
7598 len = str2->WriteUtf8(utf8buf, 8, &charlen);
7601 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203\1", 9));
7603 memset(utf8buf, 0x1, 1000);
7604 len = str2->WriteUtf8(utf8buf, 7, &charlen);
7607 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
7609 memset(utf8buf, 0x1, 1000);
7610 len = str2->WriteUtf8(utf8buf, 6, &charlen);
7613 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
7615 memset(utf8buf, 0x1, 1000);
7616 len = str2->WriteUtf8(utf8buf, 5, &charlen);
7619 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\1", 5));
7621 memset(utf8buf, 0x1, 1000);
7622 len = str2->WriteUtf8(utf8buf, 4, &charlen);
7625 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
7627 memset(utf8buf, 0x1, 1000);
7628 len = str2->WriteUtf8(utf8buf, 3, &charlen);
7631 CHECK_EQ(0, strncmp(utf8buf,
"abc\1", 4));
7633 memset(utf8buf, 0x1, 1000);
7634 len = str2->WriteUtf8(utf8buf, 2, &charlen);
7637 CHECK_EQ(0, strncmp(utf8buf,
"ab\1", 3));
7640 memset(utf8buf, 0x1, 1000);
7641 len = orphans_str->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen);
7644 CHECK_EQ(0, strcmp(utf8buf,
"ab\355\240\200cd\355\260\200ef"));
7647 memset(utf8buf, 0x1, 1000);
7648 len = orphans_str->WriteUtf8(utf8buf,
7651 String::REPLACE_INVALID_UTF8);
7654 CHECK_EQ(0, strcmp(utf8buf,
"ab\357\277\275cd\357\277\275ef"));
7657 memset(utf8buf, 0x1, 1000);
7658 len = lead_str->WriteUtf8(utf8buf,
7661 String::REPLACE_INVALID_UTF8);
7664 CHECK_EQ(0, strcmp(utf8buf,
"\357\277\275"));
7667 memset(utf8buf, 0x1, 1000);
7668 len = trail_str->WriteUtf8(utf8buf,
7671 String::REPLACE_INVALID_UTF8);
7674 CHECK_EQ(0, strcmp(utf8buf,
"\357\277\275"));
7678 memset(utf8buf, 0x1, 1000);
7679 len = pair_str->WriteUtf8(utf8buf,
7682 String::REPLACE_INVALID_UTF8);
7686 memset(utf8buf, 0x1,
sizeof(utf8buf));
7689 (0x80 + (0x800 - 0x80) * 2 + (0xd800 - 0x800) * 3) / kStride;
7691 len = left_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
7693 CHECK_EQ(0xd800 / kStride, charlen);
7694 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[utf8_expected - 3]));
7695 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[utf8_expected - 2]));
7697 static_cast<unsigned char>(utf8buf[utf8_expected - 1]));
7698 CHECK_EQ(1, utf8buf[utf8_expected]);
7700 memset(utf8buf, 0x1,
sizeof(utf8buf));
7703 len = right_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
7705 CHECK_EQ(0xd800 / kStride, charlen);
7706 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[0]));
7707 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[1]));
7708 CHECK_EQ(0xc0 - kStride, static_cast<unsigned char>(utf8buf[2]));
7709 CHECK_EQ(1, utf8buf[utf8_expected]);
7711 memset(buf, 0x1,
sizeof(buf));
7712 memset(wbuf, 0x1,
sizeof(wbuf));
7713 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
7715 len = str->Write(wbuf);
7718 uint16_t answer1[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
7719 CHECK_EQ(0, StrCmp16(answer1, wbuf));
7721 memset(buf, 0x1,
sizeof(buf));
7722 memset(wbuf, 0x1,
sizeof(wbuf));
7723 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 4);
7725 len = str->Write(wbuf, 0, 4);
7727 CHECK_EQ(0, strncmp(
"abcd\1", buf, 5));
7728 uint16_t answer2[] = {
'a',
'b',
'c',
'd', 0x101};
7729 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5));
7731 memset(buf, 0x1,
sizeof(buf));
7732 memset(wbuf, 0x1,
sizeof(wbuf));
7733 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 5);
7735 len = str->Write(wbuf, 0, 5);
7737 CHECK_EQ(0, strncmp(
"abcde\1", buf, 6));
7738 uint16_t answer3[] = {
'a',
'b',
'c',
'd',
'e', 0x101};
7739 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6));
7741 memset(buf, 0x1,
sizeof(buf));
7742 memset(wbuf, 0x1,
sizeof(wbuf));
7743 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 6);
7745 len = str->Write(wbuf, 0, 6);
7748 uint16_t answer4[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
7749 CHECK_EQ(0, StrCmp16(answer4, wbuf));
7751 memset(buf, 0x1,
sizeof(buf));
7752 memset(wbuf, 0x1,
sizeof(wbuf));
7753 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, -1);
7755 len = str->Write(wbuf, 4, -1);
7759 CHECK_EQ(0, StrCmp16(answer5, wbuf));
7761 memset(buf, 0x1,
sizeof(buf));
7762 memset(wbuf, 0x1,
sizeof(wbuf));
7763 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, 6);
7765 len = str->Write(wbuf, 4, 6);
7768 CHECK_EQ(0, StrCmp16(answer5, wbuf));
7770 memset(buf, 0x1,
sizeof(buf));
7771 memset(wbuf, 0x1,
sizeof(wbuf));
7772 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, 1);
7774 len = str->Write(wbuf, 4, 1);
7776 CHECK_EQ(0, strncmp(
"e\1", buf, 2));
7778 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2));
7780 memset(buf, 0x1,
sizeof(buf));
7781 memset(wbuf, 0x1,
sizeof(wbuf));
7782 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 3, 1);
7784 len = str->Write(wbuf, 3, 1);
7786 CHECK_EQ(0, strncmp(
"d\1", buf, 2));
7788 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2));
7790 memset(wbuf, 0x1,
sizeof(wbuf));
7792 len = str->Write(wbuf, 0, 6, String::NO_NULL_TERMINATION);
7795 uint16_t answer8a[] = {
'a',
'b',
'c',
'd',
'e'};
7796 uint16_t answer8b[] = {
'a',
'b',
'c',
'd',
'e',
'\0'};
7797 CHECK_EQ(0, StrNCmp16(answer8a, wbuf, 5));
7798 CHECK_NE(0, StrCmp16(answer8b, wbuf));
7800 CHECK_EQ(0, StrCmp16(answer8b, wbuf));
7802 memset(buf, 0x1,
sizeof(buf));
7804 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf),
7807 String::NO_NULL_TERMINATION);
7810 CHECK_EQ(0, strncmp(
"abcde", buf, 5));
7815 memset(utf8buf, 0x1,
sizeof(utf8buf));
7817 len = str2->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen,
7818 String::NO_NULL_TERMINATION);
7822 CHECK_EQ(0, strncmp(utf8buf,
"abc\303\260\342\230\203", 8));
7823 CHECK_NE(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
7825 CHECK_EQ(0, strcmp(utf8buf,
"abc\303\260\342\230\203"));
7827 memset(utf8buf, 0x1,
sizeof(utf8buf));
7829 len = str->WriteUtf8(utf8buf,
sizeof(utf8buf), &charlen,
7830 String::NO_NULL_TERMINATION);
7835 CHECK_EQ(0, strcmp(utf8buf,
"abcde"));
7837 memset(buf, 0x1,
sizeof(buf));
7838 len = str3->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
7842 CHECK_EQ(0, strcmp(
"def", buf + 4));
7844 CHECK_EQ(0, str->WriteOneByte(
NULL, 0, 0, String::NO_NULL_TERMINATION));
7845 CHECK_EQ(0, str->WriteUtf8(
NULL, 0, 0, String::NO_NULL_TERMINATION));
7846 CHECK_EQ(0, str->Write(
NULL, 0, 0, String::NO_NULL_TERMINATION));
7850 static void Utf16Helper(
7853 const char* lengths_name,
7855 Local<v8::Array> a =
7856 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
7857 Local<v8::Array> alens =
7858 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
7859 for (
int i = 0; i < len; i++) {
7860 Local<v8::String>
string =
7862 Local<v8::Number> expected_len =
7863 Local<v8::Number>::Cast(alens->Get(i));
7865 CHECK_EQ(static_cast<int>(expected_len->Value()), length);
7870 static uint16_t StringGet(Handle<String> str,
int index) {
7873 return istring->Get(index);
7877 static void WriteUtf8Helper(
7880 const char* lengths_name,
7882 Local<v8::Array> b =
7883 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(name)));
7884 Local<v8::Array> alens =
7885 Local<v8::Array>::Cast(context->
Global()->Get(v8_str(lengths_name)));
7888 for (
int i = 0; i < len; i++) {
7889 Local<v8::String>
string =
7891 Local<v8::Number> expected_len =
7892 Local<v8::Number>::Cast(alens->Get(i));
7893 int utf8_length =
static_cast<int>(expected_len->Value());
7894 for (
int j = utf8_length + 1; j >= 0; j--) {
7895 memset(reinterpret_cast<void*>(&buffer), 42,
sizeof(buffer));
7896 memset(reinterpret_cast<void*>(&buffer2), 42,
sizeof(buffer2));
7899 string->WriteUtf8(buffer, j, &nchars, String::NO_OPTIONS);
7901 string->WriteUtf8(buffer2, j, &nchars, String::NO_NULL_TERMINATION);
7902 CHECK_GE(utf8_length + 1, utf8_written);
7903 CHECK_GE(utf8_length, utf8_written2);
7904 for (
int k = 0; k < utf8_written2; k++) {
7907 CHECK(nchars * 3 >= utf8_written - 1);
7908 CHECK(nchars <= utf8_written);
7909 if (j == utf8_length + 1) {
7910 CHECK_EQ(utf8_written2, utf8_length);
7911 CHECK_EQ(utf8_written2 + 1, utf8_written);
7913 CHECK_EQ(buffer[utf8_written], 42);
7914 if (j > utf8_length) {
7915 if (utf8_written != 0)
CHECK_EQ(buffer[utf8_written - 1], 0);
7916 if (utf8_written > 1)
CHECK_NE(buffer[utf8_written - 2], 42);
7917 Handle<String> roundtrip = v8_str(buffer);
7918 CHECK(roundtrip->Equals(
string));
7920 if (utf8_written != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
7922 if (utf8_written2 != 0)
CHECK_NE(buffer[utf8_written - 1], 42);
7924 uint16_t trail = StringGet(
string, nchars - 1);
7925 uint16_t lead = StringGet(
string, nchars - 2);
7926 if (((lead & 0xfc00) == 0xd800) &&
7927 ((trail & 0xfc00) == 0xdc00)) {
7928 unsigned char u1 = buffer2[utf8_written2 - 4];
7929 unsigned char u2 = buffer2[utf8_written2 - 3];
7930 unsigned char u3 = buffer2[utf8_written2 - 2];
7931 unsigned char u4 = buffer2[utf8_written2 - 1];
7936 uint32_t c = 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
7938 CHECK_EQ((u3 & 0x3f), ((c >> 6) & 0x3f));
7939 CHECK_EQ((u2 & 0x3f), ((c >> 12) & 0x3f));
7952 "var pad = '01234567890123456789';"
7954 "var plens = [20, 3, 3];"
7955 "p.push('01234567890123456789');"
7956 "var lead = 0xd800;"
7957 "var trail = 0xdc00;"
7958 "p.push(String.fromCharCode(0xd800));"
7959 "p.push(String.fromCharCode(0xdc00));"
7964 "for (var i = 0; i < 3; i++) {"
7965 " p[1] = String.fromCharCode(lead++);"
7966 " for (var j = 0; j < 3; j++) {"
7967 " p[2] = String.fromCharCode(trail++);"
7968 " a.push(p[i] + p[j]);"
7969 " b.push(p[i] + p[j]);"
7970 " c.push(p[i] + p[j]);"
7971 " alens.push(plens[i] + plens[j]);"
7979 "for (var m = 0; m < 9; m++) {"
7980 " for (var n = 0; n < 9; n++) {"
7981 " a2.push(a[m] + a[n]);"
7982 " b2.push(b[m] + b[n]);"
7983 " var newc = 'x' + c[m] + c[n] + 'y';"
7984 " c2.push(newc.substring(1, newc.length - 1));"
7985 " var utf = alens[m] + alens[n];"
7988 " if ((m % 3) == 1 && n >= 6) utf -= 2;"
7989 " a2lens.push(utf);"
7992 Utf16Helper(context,
"a",
"alens", 9);
7993 Utf16Helper(context,
"a2",
"a2lens", 81);
7994 WriteUtf8Helper(context,
"b",
"alens", 9);
7995 WriteUtf8Helper(context,
"b2",
"a2lens", 81);
7996 WriteUtf8Helper(context,
"c2",
"a2lens", 81);
8000 static bool SameSymbol(Handle<String>
s1, Handle<String>
s2) {
8003 return *is1 == *is2;
8006 static void SameSymbolHelper(
v8::Isolate* isolate,
const char* a,
8008 Handle<String> symbol1 =
8010 Handle<String> symbol2 =
8012 CHECK(SameSymbol(symbol1, symbol2));
8024 CHECK(SameSymbol(symbol1, symbol2));
8028 "\355\240\201\355\260\205");
8030 "\355\240\201\355\260\206",
8031 "\360\220\220\206");
8033 "x\360\220\220\205",
8034 "x\355\240\201\355\260\205");
8036 "x\355\240\201\355\260\206",
8037 "x\360\220\220\206");
8039 "var sym0 = 'benedictus';"
8040 "var sym0b = 'S\303\270ren';"
8041 "var sym1 = '\355\240\201\355\260\207';"
8042 "var sym2 = '\360\220\220\210';"
8043 "var sym3 = 'x\355\240\201\355\260\207';"
8044 "var sym4 = 'x\360\220\220\210';"
8045 "if (sym1.length != 2) throw sym1;"
8046 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
8047 "if (sym2.length != 2) throw sym2;"
8048 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);"
8049 "if (sym3.length != 3) throw sym3;"
8050 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);"
8051 "if (sym4.length != 3) throw sym4;"
8052 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);");
8057 Handle<String> sym1 =
8060 Handle<String> sym2 =
8064 context->
GetIsolate(),
"x\355\240\201\355\260\207",
8066 Handle<String> sym4 =
8070 Local<Value>
s0 = global->Get(v8_str(
"sym0"));
8071 Local<Value> s0b = global->Get(v8_str(
"sym0b"));
8072 Local<Value> s1 = global->Get(v8_str(
"sym1"));
8073 Local<Value> s2 = global->Get(v8_str(
"sym2"));
8074 Local<Value>
s3 = global->Get(v8_str(
"sym3"));
8075 Local<Value>
s4 = global->Get(v8_str(
"sym4"));
8076 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0)));
8077 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b)));
8078 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1)));
8079 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2)));
8080 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3)));
8081 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4)));
8094 str = v8_str(
"42asdf");
8097 str = v8_str(
"-42");
8100 str = v8_str(
"4294967295");
8127 CHECK(reference_error->IsObject());
8130 CHECK(syntax_error->IsObject());
8133 CHECK(type_error->IsObject());
8136 CHECK(error->IsObject());
8141 static void YGetter(Local<String> name,
8148 static void YSetter(Local<String> name,
8151 if (info.
This()->Has(name)) {
8152 info.
This()->Delete(name);
8154 info.
This()->Set(name, value);
8165 context->
Global()->Set(v8_str(
"holder"), holder);
8167 "holder.y = 11; holder.y = 12; holder.y");
8185 for (
int i = 0; i < 10; i++) {
8199 static bool g_security_callback_result =
false;
8200 static bool NamedSecurityTestCallback(Local<v8::Object> global,
8203 Local<Value> data) {
8209 return g_security_callback_result;
8213 static bool IndexedSecurityTestCallback(Local<v8::Object> global,
8216 Local<Value> data) {
8222 return g_security_callback_result;
8226 static int trouble_nesting = 0;
8232 Local<v8::Object> arg_this =
8233 args.
GetIsolate()->GetCurrentContext()->Global();
8234 Local<Value> trouble_callee = (trouble_nesting == 3) ?
8235 arg_this->Get(v8_str(
"trouble_callee")) :
8236 arg_this->Get(v8_str(
"trouble_caller"));
8237 CHECK(trouble_callee->IsFunction());
8239 Function::Cast(*trouble_callee)->Call(arg_this, 0,
NULL));
8243 static int report_count = 0;
8259 Local<v8::FunctionTemplate> fun =
8262 global->
Set(v8_str(
"trouble"), fun->GetFunction());
8265 "function trouble_callee() {"
8269 "function trouble_caller() {"
8272 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
8273 CHECK(trouble->IsFunction());
8274 Local<Value> trouble_callee = global->
Get(v8_str(
"trouble_callee"));
8275 CHECK(trouble_callee->IsFunction());
8276 Local<Value> trouble_caller = global->
Get(v8_str(
"trouble_caller"));
8277 CHECK(trouble_caller->IsFunction());
8278 Function::Cast(*trouble_caller)->Call(global, 0,
NULL);
8283 static const char* script_resource_name =
"ExceptionInNativeScript.js";
8289 CHECK_EQ(script_resource_name, *name);
8292 CHECK_EQ(
" new o.foo();", *source_line);
8302 Local<v8::FunctionTemplate> fun =
8305 global->
Set(v8_str(
"trouble"), fun->GetFunction());
8307 CompileRunWithOrigin(
8308 "function trouble() {\n"
8312 script_resource_name);
8313 Local<Value> trouble = global->
Get(v8_str(
"trouble"));
8314 CHECK(trouble->IsFunction());
8315 Function::Cast(*trouble)->Call(global, 0,
NULL);
8320 TEST(CompilationErrorUsingTryCatchHandler) {
8324 v8_compile(
"This doesn't &*&@#$&*^ compile.");
8326 CHECK(try_catch.HasCaught());
8330 TEST(TryCatchFinallyUsingTryCatchHandler) {
8334 CompileRun(
"try { throw ''; } catch (e) {}");
8335 CHECK(!try_catch.HasCaught());
8336 CompileRun(
"try { throw ''; } finally {}");
8337 CHECK(try_catch.HasCaught());
8341 "try { throw ''; } finally { return; }"
8343 CHECK(!try_catch.HasCaught());
8346 " { try { throw ''; } finally { throw 0; }"
8348 CHECK(try_catch.HasCaught());
8359 IndexedSecurityTestCallback);
8367 global0->
Set(v8_str(
"0"), v8_num(999));
8377 Context::New(isolate,
NULL, global_template);
8381 global1->
Set(v8_str(
"othercontext"), global0);
8384 v8_compile(
"othercontext.foo = 222; othercontext[0] = 888;");
8394 { g_security_callback_result =
true;
8398 global2->
Set(v8_str(
"othercontext"), global0);
8400 v8_compile(
"othercontext.foo = 333; othercontext[0] = 888;");
8418 Local<Value>
foo = v8_str(
"foo");
8419 Local<Value>
bar = v8_str(
"bar");
8425 CompileRun(
"spy=function(){return spy;}");
8426 Local<Value> spy = env1->
Global()->Get(v8_str(
"spy"));
8427 CHECK(spy->IsFunction());
8430 CompileRun(
"spy2=function(){return new this.Array();}");
8431 Local<Value> spy2 = env1->
Global()->Get(v8_str(
"spy2"));
8432 CHECK(spy2->IsFunction());
8436 env2->SetSecurityToken(foo);
8438 Context::Scope scope_env2(env2);
8439 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0,
NULL);
8440 CHECK(result->IsFunction());
8444 env2->SetSecurityToken(bar);
8445 Context::Scope scope_env2(env2);
8449 Function::Cast(*spy2)->Call(env2->Global(), 0,
NULL);
8464 { Context::Scope scope(other);
8465 other_object = other->Global()->Get(v8_str(
"Object"));
8466 other->Global()->Set(v8_num(42), v8_num(87));
8469 current->
Global()->Set(v8_str(
"other"), other->Global());
8470 CHECK(v8_compile(
"other")->Run()->Equals(other->Global()));
8477 for (
int i = 0; i < 5; i++) {
8478 CHECK(!access_other0->Run()->Equals(other_object));
8479 CHECK(access_other0->Run()->IsUndefined());
8480 CHECK(!access_other1->Run()->Equals(v8_num(87)));
8481 CHECK(access_other1->Run()->IsUndefined());
8487 v8_compile(
"function F() { };"
8488 "F.prototype = other;"
8489 "var f = new F();")->Run();
8492 for (
int j = 0; j < 5; j++) {
8493 CHECK(!access_f0->Run()->Equals(other_object));
8494 CHECK(access_f0->Run()->IsUndefined());
8495 CHECK(!access_f1->Run()->Equals(v8_num(87)));
8496 CHECK(access_f1->Run()->IsUndefined());
8502 { Context::Scope scope(other);
8503 other->Global()->Set(v8_str(
"__proto__"), current->
Global());
8508 current->
Global()->Set(v8_str(
"foo"), v8_num(100));
8509 current->
Global()->Set(v8_num(99), v8_num(101));
8512 Local<Script> access_f2 = v8_compile(
"f.foo");
8513 Local<Script> access_f3 = v8_compile(
"f[99]");
8514 for (
int k = 0; k < 5; k++) {
8515 CHECK(!access_f2->Run()->Equals(v8_num(100)));
8516 CHECK(access_f2->Run()->IsUndefined());
8517 CHECK(!access_f3->Run()->Equals(v8_num(101)));
8518 CHECK(access_f3->Run()->IsUndefined());
8528 Local<Value>
foo = v8_str(
"foo");
8529 Local<Value>
bar = v8_str(
"bar");
8533 env2->SetSecurityToken(foo);
8535 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
8536 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
8539 env2->SetSecurityToken(bar);
8541 Context::Scope scope_env2(env2);
8542 Local<Value> result =
8543 CompileRun(
"delete env1.prop");
8544 CHECK(result->IsFalse());
8548 Local<Value> v = env1->
Global()->Get(v8_str(
"prop"));
8549 CHECK(v->IsNumber());
8559 Local<Value>
foo = v8_str(
"foo");
8560 Local<Value>
bar = v8_str(
"bar");
8564 env2->SetSecurityToken(foo);
8566 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
8567 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
8570 Local<String> test = v8_str(
"propertyIsEnumerable.call(env1, 'prop')");
8572 Context::Scope scope_env2(env2);
8573 Local<Value> result = CompileRun(test);
8574 CHECK(result->IsTrue());
8578 env2->SetSecurityToken(bar);
8580 Context::Scope scope_env2(env2);
8581 Local<Value> result = CompileRun(test);
8582 CHECK(result->IsFalse());
8592 Local<Value>
foo = v8_str(
"foo");
8593 Local<Value>
bar = v8_str(
"bar");
8597 env2->SetSecurityToken(foo);
8599 env1->
Global()->Set(v8_str(
"prop"), v8_num(3));
8600 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
8606 env2->SetSecurityToken(bar);
8608 Context::Scope scope_env2(env2);
8609 Local<Value> result =
8610 CompileRun(
"(function(){var obj = {'__proto__':env1};"
8611 "for (var p in obj)"
8612 " if (p == 'prop') return false;"
8613 "return true;})()");
8614 CHECK(result->IsTrue());
8624 Local<v8::Object> global1 = env1->
Global();
8626 Local<Value>
foo = v8_str(
"foo");
8630 env2->SetSecurityToken(foo);
8636 Local<v8::Object> global2 = env2->Global();
8638 CompileRun(
"function getProp() {return prop;}");
8640 env1->
Global()->Set(v8_str(
"getProp"),
8641 global2->Get(v8_str(
"getProp")));
8645 env2->DetachGlobal();
8654 Local<v8::Object> global3 = env3->
Global();
8656 CHECK(global3->Get(v8_str(
"prop"))->IsUndefined());
8657 CHECK(global3->Get(v8_str(
"getProp"))->IsUndefined());
8664 Local<Value> get_prop = global1->Get(v8_str(
"getProp"));
8665 CHECK(get_prop->IsFunction());
8667 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0,
NULL);
8668 CHECK(!try_catch.HasCaught());
8674 Local<Value> r = global3->Get(v8_str(
"prop2"));
8675 CHECK(r->IsUndefined());
8687 Local<Value>
foo = v8_str(
"foo");
8691 env2->SetSecurityToken(foo);
8696 env2->Global()->Set(v8_str(
"p"),
v8::Integer::New(env2->GetIsolate(), 42));
8700 env1->
Global()->Set(v8_str(
"other"), env2->Global());
8703 Local<Value> result = CompileRun(
"other.p");
8704 CHECK(result->IsInt32());
8705 CHECK_EQ(42, result->Int32Value());
8708 Local<v8::Object> global2 = env2->Global();
8709 env2->DetachGlobal();
8713 result = CompileRun(
"other.p");
8714 CHECK(result->IsUndefined());
8724 env3->SetSecurityToken(foo);
8729 env3->Global()->Set(v8_str(
"p"),
v8::Integer::New(env3->GetIsolate(), 24));
8733 result = CompileRun(
"other.p");
8734 CHECK(result->IsInt32());
8735 CHECK_EQ(24, result->Int32Value());
8738 env3->SetSecurityToken(v8_str(
"bar"));
8743 result = CompileRun(
"other.p");
8744 CHECK(result->IsUndefined());
8750 info.
GetIsolate()->GetCurrentContext()->Global()->Get(v8_str(
"x")));
8759 Local<ObjectTemplate> inner_global_template =
8760 FunctionTemplate::New(env1->
GetIsolate())->InstanceTemplate();
8761 inner_global_template ->SetAccessorProperty(
8766 Local<Value>
foo = v8_str(
"foo");
8770 env2->SetSecurityToken(foo);
8772 env1->
Global()->Set(v8_str(
"x"), v8_str(
"env1_x"));
8776 env2->Global()->Set(v8_str(
"x"), v8_str(
"env2_x"));
8778 "function bound_x() { return x; }"
8779 "function get_x() { return this.x; }"
8780 "function get_x_w() { return (function() {return this.x;})(); }");
8781 env1->
Global()->Set(v8_str(
"bound_x"), CompileRun(
"bound_x"));
8782 env1->
Global()->Set(v8_str(
"get_x"), CompileRun(
"get_x"));
8783 env1->
Global()->Set(v8_str(
"get_x_w"), CompileRun(
"get_x_w"));
8786 CompileRun(
"Object.getOwnPropertyDescriptor(this, 'this_x').get"));
8789 Local<Object> env2_global = env2->Global();
8790 env2_global->TurnOnAccessCheck();
8791 env2->DetachGlobal();
8793 Local<Value> result;
8794 result = CompileRun(
"bound_x()");
8795 CHECK_EQ(v8_str(
"env2_x"), result);
8796 result = CompileRun(
"get_x()");
8797 CHECK(result->IsUndefined());
8798 result = CompileRun(
"get_x_w()");
8799 CHECK(result->IsUndefined());
8800 result = CompileRun(
"this_x()");
8801 CHECK_EQ(v8_str(
"env2_x"), result);
8808 env2->SetSecurityToken(foo);
8811 env2->Global()->Set(v8_str(
"x"), v8_str(
"env3_x"));
8812 env2->Global()->Set(v8_str(
"env1"), env1->
Global());
8813 result = CompileRun(
8815 "for (var i = 0; i < 4; i++ ) {"
8816 " results.push(env1.bound_x());"
8817 " results.push(env1.get_x());"
8818 " results.push(env1.get_x_w());"
8819 " results.push(env1.this_x());"
8822 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8824 for (
int i = 0; i < 16; i += 4) {
8825 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 0));
8826 CHECK_EQ(v8_str(
"env1_x"), results->Get(i + 1));
8827 CHECK_EQ(v8_str(
"env3_x"), results->Get(i + 2));
8828 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 3));
8832 result = CompileRun(
8834 "for (var i = 0; i < 4; i++ ) {"
8835 " results.push(bound_x());"
8836 " results.push(get_x());"
8837 " results.push(get_x_w());"
8838 " results.push(this_x());"
8841 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8843 for (
int i = 0; i < 16; i += 4) {
8844 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 0));
8845 CHECK_EQ(v8_str(
"env3_x"), results->Get(i + 1));
8846 CHECK_EQ(v8_str(
"env3_x"), results->Get(i + 2));
8847 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 3));
8850 result = CompileRun(
8852 "for (var i = 0; i < 4; i++ ) {"
8853 " results.push(this.bound_x());"
8854 " results.push(this.get_x());"
8855 " results.push(this.get_x_w());"
8856 " results.push(this.this_x());"
8859 results = Local<v8::Array>::Cast(result);
8861 for (
int i = 0; i < 16; i += 4) {
8862 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 0));
8863 CHECK_EQ(v8_str(
"env1_x"), results->Get(i + 1));
8864 CHECK_EQ(v8_str(
"env3_x"), results->Get(i + 2));
8865 CHECK_EQ(v8_str(
"env2_x"), results->Get(i + 3));
8871 static bool NamedAccessBlocker(Local<v8::Object> global,
8874 Local<Value> data) {
8876 allowed_access_type[type];
8880 static bool IndexedAccessBlocker(Local<v8::Object> global,
8883 Local<Value> data) {
8885 allowed_access_type[type];
8889 static int g_echo_value_1 = -1;
8890 static int g_echo_value_2 = -1;
8893 static void EchoGetter(
8905 static void EchoSetter(Local<String> name,
8908 if (value->IsNumber())
8909 g_echo_value_1 = value->Int32Value();
8920 static void UnreachableGetter(
8927 static void UnreachableSetter(Local<String>,
8934 static void UnreachableFunction(
8947 IndexedAccessBlocker);
8951 v8_str(
"accessible_prop"),
8952 EchoGetter, EchoSetter,
8958 v8_str(
"accessible_js_prop"),
8965 global_template->
SetAccessor(v8_str(
"blocked_prop"),
8966 UnreachableGetter, UnreachableSetter,
8971 v8_str(
"blocked_js_prop"),
8985 "function getter() { return 'getter'; };\n"
8986 "function setter() { return 'setter'; }\n"
8987 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
8989 Local<Value> getter = global0->
Get(v8_str(
"getter"));
8990 Local<Value> setter = global0->
Get(v8_str(
"setter"));
8993 global0->
Set(239, v8_str(
"239"));
8997 "function el_getter() { return 'el_getter'; };\n"
8998 "function el_setter() { return 'el_setter'; };\n"
8999 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
9001 Local<Value> el_getter = global0->
Get(v8_str(
"el_getter"));
9002 Local<Value> el_setter = global0->
Get(v8_str(
"el_setter"));
9010 global1->
Set(v8_str(
"other"), global0);
9013 CompileRun(
"other.blocked_prop = 1");
9015 ExpectUndefined(
"other.blocked_prop");
9017 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
9018 ExpectFalse(
"propertyIsEnumerable.call(other, 'blocked_prop')");
9022 ExpectUndefined(
"other.blocked_prop");
9025 "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
9027 ExpectTrue(
"propertyIsEnumerable.call(other, 'blocked_prop')");
9031 CompileRun(
"other[239] = 1");
9033 ExpectUndefined(
"other[239]");
9034 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239')");
9035 ExpectFalse(
"propertyIsEnumerable.call(other, '239')");
9039 ExpectUndefined(
"other[239]");
9041 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '239').value");
9043 ExpectTrue(
"propertyIsEnumerable.call(other, '239')");
9047 CompileRun(
"other.js_accessor_p = 2");
9049 ExpectUndefined(
"other.js_accessor_p");
9051 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
9055 ExpectUndefined(
"other.js_accessor_p");
9057 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
9059 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
9061 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
9068 ExpectString(
"other.js_accessor_p",
"getter");
9070 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
9072 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
9074 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
9083 ExpectUndefined(
"other.js_accessor_p");
9085 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
9087 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
9089 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
9099 ExpectString(
"other.js_accessor_p",
"getter");
9101 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
9103 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
9105 "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
9112 CompileRun(
"other[42] = 2");
9114 ExpectUndefined(
"other[42]");
9115 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42')");
9119 ExpectUndefined(
"other[42]");
9120 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
9121 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
9122 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
9129 ExpectString(
"other[42]",
"el_getter");
9130 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
9131 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').set");
9132 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
9141 ExpectUndefined(
"other[42]");
9142 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').get");
9143 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
9144 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
9154 ExpectString(
"other[42]",
"el_getter");
9155 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
9156 ExpectObject(
"Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
9157 ExpectUndefined(
"Object.getOwnPropertyDescriptor(other, '42').value");
9166 value = CompileRun(
"other.accessible_prop = 3");
9172 value = CompileRun(
"other.accessible_js_prop = 3");
9177 value = CompileRun(
"other.accessible_prop");
9181 value = CompileRun(
"other.accessible_js_prop");
9182 CHECK(value->IsNumber());
9186 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
9187 CHECK(value->IsNumber());
9191 "Object.getOwnPropertyDescriptor(other, 'accessible_js_prop').get()");
9192 CHECK(value->IsNumber());
9195 value = CompileRun(
"propertyIsEnumerable.call(other, 'accessible_prop')");
9196 CHECK(value->IsTrue());
9198 value = CompileRun(
"propertyIsEnumerable.call(other, 'accessible_js_prop')");
9199 CHECK(value->IsTrue());
9204 CompileRun(
"(function(){var obj = {'__proto__':other};"
9205 "for (var p in obj)"
9206 " if (p == 'accessible_prop' ||"
9207 " p == 'accessible_js_prop' ||"
9208 " p == 'blocked_js_prop' ||"
9209 " p == 'blocked_js_prop') {"
9212 "return true;})()");
9213 CHECK(value->IsTrue());
9227 IndexedAccessBlocker);
9231 v8_str(
"accessible_prop"),
9232 EchoGetter, EchoSetter,
9238 global_template->
SetAccessor(v8_str(
"blocked_prop"),
9239 UnreachableGetter, UnreachableSetter,
9252 global1->
Set(v8_str(
"other"), global0);
9255 ExpectTrue(
"Object.keys(other).indexOf('blocked_prop') == -1");
9257 ExpectUndefined(
"other.blocked_prop");
9260 CompileRun(
"Object.defineProperty(\n"
9261 " other, 'blocked_prop', {configurable: false})");
9262 ExpectUndefined(
"other.blocked_prop");
9264 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
9267 ExpectTrue(
"Object.isExtensible(other)");
9268 CompileRun(
"Object.preventExtensions(other)");
9269 ExpectTrue(
"Object.isExtensible(other)");
9272 CompileRun(
"Object.freeze(other)");
9273 ExpectTrue(
"Object.isExtensible(other)");
9275 CompileRun(
"Object.seal(other)");
9276 ExpectTrue(
"Object.isExtensible(other)");
9281 CompileRun(
"other.accessible_prop = 42");
9286 CompileRun(
"Object.defineProperty(other, 'accessible_prop', {value: -1})");
9287 value = CompileRun(
"other.accessible_prop == 42");
9292 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
9295 Local<Value> data) {
9300 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
9303 Local<Value> data) {
9316 GetOwnPropertyNamesIndexedBlocker);
9330 global1->
Set(v8_str(
"other"), global0);
9340 value = CompileRun(
"Object.getOwnPropertyNames(other).length == 0");
9343 value = CompileRun(
"Object.getOwnPropertyNames(object).length == 0");
9344 CHECK(value->IsTrue());
9351 static void IndexedPropertyEnumerator(
9360 static void NamedPropertyEnumerator(
9363 result->
Set(0, v8_str(
"x"));
9378 IndexedPropertyEnumerator);
9380 NamedPropertyEnumerator);
9387 CompileRun(
"Object.getOwnPropertyNames(object)");
9390 CHECK_EQ(3, result_array->Length());
9391 CHECK(result_array->Get(0)->IsString());
9392 CHECK(result_array->Get(1)->IsString());
9393 CHECK(result_array->Get(2)->IsString());
9394 CHECK_EQ(v8_str(
"7"), result_array->Get(0));
9395 CHECK_EQ(v8_str(
"[object Object]"), result_array->Get(1));
9396 CHECK_EQ(v8_str(
"x"), result_array->Get(2));
9400 static void ConstTenGetter(Local<String> name,
9426 global_template->
SetAccessor(v8_str(
"unreachable"),
9427 UnreachableGetter, 0,
9434 Local<v8::Object> global = context0->Global();
9436 global->Set(v8_str(
"accessible"), v8_num(11));
9444 global1->
Set(v8_str(
"other"), global);
9451 value = v8_compile(
"other.unreachable")->Run();
9452 CHECK(value->IsUndefined());
9459 static int named_access_count = 0;
9460 static int indexed_access_count = 0;
9462 static bool NamedAccessCounter(Local<v8::Object> global,
9465 Local<Value> data) {
9466 named_access_count++;
9471 static bool IndexedAccessCounter(Local<v8::Object> global,
9474 Local<Value> data) {
9475 indexed_access_count++;
9482 named_access_count = 0;
9483 indexed_access_count = 0;
9497 IndexedAccessCounter);
9498 Local<v8::Object>
object = object_template->
NewInstance();
9508 global1->
Set(v8_str(
"obj"),
object);
9513 CompileRun(
"function testProp(obj) {"
9514 " for (var i = 0; i < 10; i++) obj.prop = 1;"
9515 " for (var j = 0; j < 10; j++) obj.prop;"
9518 value = CompileRun(
"testProp(obj)");
9524 CompileRun(
"var p = 'prop';"
9525 "function testKeyed(obj) {"
9526 " for (var i = 0; i < 10; i++) obj[p] = 1;"
9527 " for (var j = 0; j < 10; j++) obj[p];"
9532 value = CompileRun(
"testKeyed(obj)");
9537 CompileRun(
"testKeyed({ a: 0 })");
9538 CompileRun(
"testKeyed({ b: 0 })");
9539 value = CompileRun(
"testKeyed(obj)");
9545 CompileRun(
"function testIndexed(obj) {"
9546 " for (var i = 0; i < 10; i++) obj[0] = 1;"
9547 " for (var j = 0; j < 10; j++) obj[0];"
9550 value = CompileRun(
"testIndexed(obj)");
9553 CHECK_EQ(21, indexed_access_count);
9555 CompileRun(
"testIndexed(new Array(1))");
9557 value = CompileRun(
"testIndexed(obj)");
9560 CHECK_EQ(42, indexed_access_count);
9564 CompileRun(
"obj.f = function() {}");
9565 CompileRun(
"function testCallNormal(obj) {"
9566 " for (var i = 0; i < 10; i++) obj.f();"
9568 CompileRun(
"testCallNormal(obj)");
9572 value = CompileRun(
"delete obj.prop");
9575 CompileRun(
"var o = { x: 0 }; delete o.x; testProp(o);");
9577 value = CompileRun(
"testProp(obj);");
9583 CompileRun(
"o.f = function() {}; testCallNormal(o)");
9586 value = CompileRun(
"testCallNormal(obj)");
9594 static bool NamedAccessFlatten(Local<v8::Object> global,
9597 Local<Value> data) {
9601 CHECK(name->IsString());
9603 memset(buf, 0x1,
sizeof(buf));
9604 len = name.As<String>()->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
9609 memset(buf, 0x1,
sizeof(buf));
9610 len = name.As<String>()->Write(buf2);
9617 static bool IndexedAccessFlatten(Local<v8::Object> global,
9620 Local<Value> data) {
9631 named_access_count = 0;
9632 indexed_access_count = 0;
9646 IndexedAccessFlatten);
9647 Local<v8::Object>
object = object_template->
NewInstance();
9657 global1->
Set(v8_str(
"obj"),
object);
9661 value = v8_compile(
"var p = 'as' + 'df';")->Run();
9662 value = v8_compile(
"obj[p];")->Run();
9669 static void AccessControlNamedGetter(
9676 static void AccessControlNamedSetter(
9684 static void AccessControlIndexedGetter(
9691 static void AccessControlIndexedSetter(
9700 named_access_count = 0;
9701 indexed_access_count = 0;
9716 IndexedAccessCounter);
9718 AccessControlNamedSetter);
9720 AccessControlIndexedSetter);
9721 Local<v8::Object>
object = object_template->
NewInstance();
9731 global1->
Set(v8_str(
"obj"),
object);
9737 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x = 1;")->Run();
9738 value = v8_compile(
"for (var i = 0; i < 10; i++) obj.x;"
9744 value = v8_compile(
"var p = 'x';")->Run();
9745 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p] = 1;")->Run();
9746 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[p];"
9754 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0] = 1;")->Run();
9755 value = v8_compile(
"for (var i = 0; i < 10; i++) obj[0];"
9759 CHECK_EQ(21, indexed_access_count);
9771 static void InstanceFunctionCallback(
9784 Local<ObjectTemplate> instance = t->InstanceTemplate();
9786 instance->Set(v8_str(
"x"), v8_num(42));
9787 instance->Set(v8_str(
"f"),
9790 Local<Value> o = t->GetFunction()->NewInstance();
9792 context->
Global()->Set(v8_str(
"i"), o);
9793 Local<Value> value = CompileRun(
"i.x");
9796 value = CompileRun(
"i.f()");
9801 static void GlobalObjectInstancePropertiesGet(
9812 Local<Value> global_object;
9815 t->InstanceTemplate()->SetNamedPropertyHandler(
9816 GlobalObjectInstancePropertiesGet);
9817 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9818 instance_template->Set(v8_str(
"x"), v8_num(42));
9819 instance_template->Set(v8_str(
"f"),
9821 InstanceFunctionCallback));
9825 const char* script =
9826 "function wrapper(call) {"
9827 " var x = 0, y = 1;"
9828 " for (var i = 0; i < 1000; i++) {"
9834 "for (var i = 0; i < 17; i++) wrapper(false);"
9836 "try { wrapper(true); } catch (e) { thrown = 1; };"
9843 global_object = env->
Global();
9845 Local<Value> value = CompileRun(
"x");
9847 value = CompileRun(
"f()");
9849 value = CompileRun(script);
9856 Local<Value> value = CompileRun(
"x");
9858 value = CompileRun(
"f()");
9860 value = CompileRun(script);
9870 Local<Value> global_object;
9873 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9881 const char* script =
9882 "function bar(x, y) { try { } finally { } }"
9883 "function baz(x) { try { } finally { } }"
9884 "function bom(x) { try { } finally { } }"
9885 "function foo(x) { bar([x], bom(2)); }"
9886 "for (var i = 0; i < 10000; i++) foo(1);"
9894 global_object = env->
Global();
9895 foo = CompileRun(script);
9901 env->
Global()->Set(v8_str(
"foo"), foo);
9902 CompileRun(
"foo()");
9907 static void ShadowFunctionCallback(
9914 static int shadow_y;
9915 static int shadow_y_setter_call_count;
9916 static int shadow_y_getter_call_count;
9919 static void ShadowYSetter(Local<String>,
9922 shadow_y_setter_call_count++;
9927 static void ShadowYGetter(Local<String> name,
9930 shadow_y_getter_call_count++;
9935 static void ShadowIndexedGet(uint32_t index,
9940 static void ShadowNamedGet(Local<String> key,
9946 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
9954 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
9955 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
9956 Local<ObjectTemplate> proto = t->PrototypeTemplate();
9957 Local<ObjectTemplate> instance = t->InstanceTemplate();
9959 proto->Set(v8_str(
"f"),
9961 ShadowFunctionCallback,
9963 proto->Set(v8_str(
"x"), v8_num(12));
9965 instance->SetAccessor(v8_str(
"y"), ShadowYGetter, ShadowYSetter);
9967 Local<Value> o = t->GetFunction()->NewInstance();
9968 context->
Global()->Set(v8_str(
"__proto__"), o);
9970 Local<Value> value =
9971 CompileRun(
"this.propertyIsEnumerable(0)");
9972 CHECK(value->IsBoolean());
9973 CHECK(!value->BooleanValue());
9975 value = CompileRun(
"x");
9978 value = CompileRun(
"f()");
9981 CompileRun(
"y = 43");
9982 CHECK_EQ(1, shadow_y_setter_call_count);
9983 value = CompileRun(
"y");
9984 CHECK_EQ(1, shadow_y_getter_call_count);
9995 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
9997 t1->SetHiddenPrototype(
true);
9998 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
10000 t2->SetHiddenPrototype(
true);
10001 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
10003 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
10005 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
10006 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10007 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10008 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
10011 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10012 o0->Set(v8_str(
"__proto__"), o1);
10013 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10014 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10015 o0->Set(v8_str(
"__proto__"), o2);
10016 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10017 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10018 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
10019 o0->Set(v8_str(
"__proto__"), o3);
10020 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10021 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10022 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
10023 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
10028 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
10029 CHECK(proto->IsObject());
10041 ht->SetHiddenPrototype(
true);
10043 ht->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
10045 Local<v8::Object> o = ot->GetFunction()->NewInstance();
10046 Local<v8::Object> h = ht->GetFunction()->NewInstance();
10047 Local<v8::Object> p = pt->GetFunction()->NewInstance();
10048 o->Set(v8_str(
"__proto__"), h);
10049 h->Set(v8_str(
"__proto__"), p);
10052 o->Set(v8_str(
"x"), v8_num(7));
10053 CHECK_EQ(7, o->Get(v8_str(
"x"))->Int32Value());
10054 CHECK_EQ(7, h->Get(v8_str(
"x"))->Int32Value());
10055 CHECK(p->Get(v8_str(
"x"))->IsUndefined());
10058 o->Set(v8_str(
"y"), v8_num(6));
10059 CHECK_EQ(6, o->Get(v8_str(
"y"))->Int32Value());
10060 CHECK(h->Get(v8_str(
"y"))->IsUndefined());
10061 CHECK(p->Get(v8_str(
"y"))->IsUndefined());
10065 p->Set(v8_str(
"z"), v8_num(8));
10066 CHECK_EQ(8, o->Get(v8_str(
"z"))->Int32Value());
10067 CHECK_EQ(8, h->Get(v8_str(
"z"))->Int32Value());
10068 CHECK_EQ(8, p->Get(v8_str(
"z"))->Int32Value());
10069 o->Set(v8_str(
"z"), v8_num(9));
10070 CHECK_EQ(9, o->Get(v8_str(
"z"))->Int32Value());
10071 CHECK_EQ(8, h->Get(v8_str(
"z"))->Int32Value());
10072 CHECK_EQ(8, p->Get(v8_str(
"z"))->Int32Value());
10081 Handle<FunctionTemplate> t = FunctionTemplate::New(context->
GetIsolate());
10082 t->SetHiddenPrototype(
true);
10083 t->InstanceTemplate()->Set(v8_str(
"foo"), v8_num(75));
10084 Handle<Object> p = t->GetFunction()->NewInstance();
10085 Handle<Object> o = Object::New(context->
GetIsolate());
10086 o->SetPrototype(p);
10088 int hash = o->GetIdentityHash();
10090 o->Set(v8_str(
"foo"), v8_num(42));
10101 t0->InstanceTemplate()->Set(v8_str(
"x"), v8_num(0));
10103 t1->SetHiddenPrototype(
true);
10104 t1->InstanceTemplate()->Set(v8_str(
"y"), v8_num(1));
10106 t2->SetHiddenPrototype(
true);
10107 t2->InstanceTemplate()->Set(v8_str(
"z"), v8_num(2));
10109 t3->InstanceTemplate()->Set(v8_str(
"u"), v8_num(3));
10111 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
10112 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10113 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10114 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
10117 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10118 CHECK(o0->SetPrototype(o1));
10119 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10120 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10121 CHECK(o1->SetPrototype(o2));
10122 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10123 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10124 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
10125 CHECK(o2->SetPrototype(o3));
10126 CHECK_EQ(0, o0->Get(v8_str(
"x"))->Int32Value());
10127 CHECK_EQ(1, o0->Get(v8_str(
"y"))->Int32Value());
10128 CHECK_EQ(2, o0->Get(v8_str(
"z"))->Int32Value());
10129 CHECK_EQ(3, o0->Get(v8_str(
"u"))->Int32Value());
10134 Local<Value> proto = o0->Get(v8_str(
"__proto__"));
10135 CHECK(proto->IsObject());
10139 Local<Value> proto0 = o0->GetPrototype();
10140 CHECK(proto0->IsObject());
10143 Local<Value> proto1 = o1->GetPrototype();
10144 CHECK(proto1->IsObject());
10147 Local<Value> proto2 = o2->GetPrototype();
10148 CHECK(proto2->IsObject());
10157 i::FLAG_allow_natives_syntax =
true;
10163 t1->SetHiddenPrototype(
true);
10164 t1->InstanceTemplate()->Set(v8_str(
"foo"), v8_num(1));
10166 t2->SetHiddenPrototype(
true);
10167 t2->InstanceTemplate()->Set(v8_str(
"fuz1"), v8_num(2));
10168 t2->InstanceTemplate()->Set(v8_str(
"objects"),
v8::Object::New(isolate));
10169 t2->InstanceTemplate()->Set(v8_str(
"fuz2"), v8_num(2));
10171 t3->SetHiddenPrototype(
true);
10172 t3->InstanceTemplate()->Set(v8_str(
"boo"), v8_num(3));
10174 t4->InstanceTemplate()->Set(v8_str(
"baz"), v8_num(4));
10178 for (
int i = 1; i <= 1000; i++) {
10180 t2->InstanceTemplate()->Set(v8_str(name_buf.
start()), v8_num(2));
10183 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10184 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10185 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
10186 Local<v8::Object> o4 = t4->GetFunction()->NewInstance();
10189 CHECK(o4->SetPrototype(o3));
10190 CHECK(o3->SetPrototype(o2));
10191 CHECK(o2->SetPrototype(o1));
10195 context->
Global()->Set(v8_str(
"obj"), o4);
10197 CompileRun(
"var names = %GetLocalPropertyNames(obj, 0);");
10199 ExpectInt32(
"names.length", 1006);
10200 ExpectTrue(
"names.indexOf(\"baz\") >= 0");
10201 ExpectTrue(
"names.indexOf(\"boo\") >= 0");
10202 ExpectTrue(
"names.indexOf(\"foo\") >= 0");
10203 ExpectTrue(
"names.indexOf(\"fuz1\") >= 0");
10204 ExpectTrue(
"names.indexOf(\"fuz2\") >= 0");
10205 ExpectFalse(
"names[1005] == undefined");
10212 i::FLAG_allow_natives_syntax =
true;
10216 Local<v8::FunctionTemplate> t1 =
10218 t1->SetHiddenPrototype(
true);
10220 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate();
10221 i1->SetAccessor(v8_str(
"foo"),
10223 i1->SetAccessor(v8_str(
"bar"),
10225 i1->SetAccessor(v8_str(
"baz"),
10227 i1->Set(v8_str(
"n1"), v8_num(1));
10228 i1->Set(v8_str(
"n2"), v8_num(2));
10230 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
10231 Local<v8::FunctionTemplate> t2 =
10233 t2->SetHiddenPrototype(
true);
10237 t2->InstanceTemplate()->Set(v8_str(
"mine"), v8_num(4));
10239 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
10240 CHECK(o2->SetPrototype(o1));
10244 o1->Set(sym, v8_num(3));
10245 o1->SetHiddenValue(
10250 context->
Global()->Set(v8_str(
"obj"), o2);
10251 context->
Global()->Set(v8_str(
"sym"), sym);
10253 CompileRun(
"var names = %GetLocalPropertyNames(obj, 0);");
10255 ExpectInt32(
"names.length", 7);
10256 ExpectTrue(
"names.indexOf(\"foo\") >= 0");
10257 ExpectTrue(
"names.indexOf(\"bar\") >= 0");
10258 ExpectTrue(
"names.indexOf(\"baz\") >= 0");
10259 ExpectTrue(
"names.indexOf(\"n1\") >= 0");
10260 ExpectTrue(
"names.indexOf(\"n2\") >= 0");
10261 ExpectTrue(
"names.indexOf(sym) >= 0");
10262 ExpectTrue(
"names.indexOf(\"mine\") >= 0");
10273 t1->ReadOnlyPrototype();
10274 context->
Global()->Set(v8_str(
"func1"), t1->GetFunction());
10278 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
10279 " return (descriptor['writable'] == false);"
10280 "})()")->BooleanValue());
10281 CHECK_EQ(42, CompileRun(
"func1.prototype.x")->Int32Value());
10283 CompileRun(
"func1.prototype = {}; func1.prototype.x")->Int32Value());
10287 context->
Global()->Set(v8_str(
"func2"), t2->GetFunction());
10291 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
10292 " return (descriptor['writable'] == true);"
10293 "})()")->BooleanValue());
10294 CHECK_EQ(42, CompileRun(
"func2.prototype.x")->Int32Value());
10305 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
10306 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
10308 CHECK(o0->SetPrototype(o1));
10312 CHECK(!o1->SetPrototype(o0));
10313 CHECK(!try_catch.HasCaught());
10316 CHECK_EQ(42, CompileRun(
"function f() { return 42; }; f()")->Int32Value());
10326 t1->RemovePrototype();
10327 Local<v8::Function> fun = t1->GetFunction();
10328 context->
Global()->Set(v8_str(
"fun"), fun);
10329 CHECK(!CompileRun(
"'prototype' in fun")->BooleanValue());
10332 CompileRun(
"new fun()");
10336 fun->NewInstance();
10346 "function Foo() { };"
10347 "function Throw() { throw 5; };"
10349 "x.__defineSetter__('set', Throw);"
10350 "x.__defineGetter__('get', Throw);");
10351 Local<v8::Object> x =
10352 Local<v8::Object>::Cast(context->
Global()->Get(v8_str(
"x")));
10355 x->Get(v8_str(
"get"));
10357 x->Get(v8_str(
"get"));
10359 x->Get(v8_str(
"get"));
10361 x->Get(v8_str(
"get"));
10370 templ->SetClassName(v8_str(
"Fun"));
10371 Local<Function> cons = templ->GetFunction();
10372 context->
Global()->Set(v8_str(
"Fun"), cons);
10373 Local<v8::Object> inst = cons->NewInstance();
10375 CHECK(obj->IsJSObject());
10376 Local<Value> value = CompileRun(
"(new Fun()).constructor === Fun");
10377 CHECK(value->BooleanValue());
10381 static void ConstructorCallback(
10384 Local<Object> This;
10387 Local<Object> Holder = args.
Holder();
10389 Local<Value> proto = Holder->GetPrototype();
10390 if (proto->IsObject()) {
10391 This->SetPrototype(proto);
10394 This = args.
This();
10397 This->Set(v8_str(
"a"), args[0]);
10402 static void FakeConstructorCallback(
10414 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10415 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
10416 Local<Object> instance = instance_template->NewInstance();
10417 context->
Global()->Set(v8_str(
"obj"), instance);
10419 Local<Value> value;
10423 value = CompileRun(
"(function() { var o = new obj(28); return o.a; })()");
10425 CHECK(value->IsInt32());
10426 CHECK_EQ(28, value->Int32Value());
10428 Local<Value> args1[] = { v8_num(28) };
10429 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1);
10430 CHECK(value_obj1->IsObject());
10432 value = object1->Get(v8_str(
"a"));
10433 CHECK(value->IsInt32());
10435 CHECK_EQ(28, value->Int32Value());
10438 value = CompileRun(
10439 "(function() { var o = new obj('tipli'); return o.a; })()");
10441 CHECK(value->IsString());
10442 String::Utf8Value string_value1(value->ToString());
10443 CHECK_EQ(
"tipli", *string_value1);
10445 Local<Value> args2[] = { v8_str(
"tipli") };
10446 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2);
10447 CHECK(value_obj2->IsObject());
10449 value = object2->Get(v8_str(
"a"));
10451 CHECK(value->IsString());
10452 String::Utf8Value string_value2(value->ToString());
10453 CHECK_EQ(
"tipli", *string_value2);
10456 value = CompileRun(
"(function() { var o = new obj(true); return o.a; })()");
10458 CHECK(value->IsBoolean());
10459 CHECK_EQ(
true, value->BooleanValue());
10461 Handle<Value> args3[] = {
v8::True(isolate) };
10462 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3);
10463 CHECK(value_obj3->IsObject());
10465 value = object3->Get(v8_str(
"a"));
10467 CHECK(value->IsBoolean());
10468 CHECK_EQ(
true, value->BooleanValue());
10472 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4);
10473 CHECK(value_obj4->IsObject());
10475 value = object4->Get(v8_str(
"a"));
10477 CHECK(value->IsUndefined());
10480 Handle<Value> args5[] = {
v8::Null(isolate) };
10481 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5);
10482 CHECK(value_obj5->IsObject());
10484 value = object5->Get(v8_str(
"a"));
10486 CHECK(value->IsNull());
10490 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10491 Local<Object> instance = instance_template->NewInstance();
10492 context->
Global()->Set(v8_str(
"obj2"), instance);
10494 Local<Value> value;
10497 value = CompileRun(
"new obj2(28)");
10499 String::Utf8Value exception_value1(try_catch.
Exception());
10500 CHECK_EQ(
"TypeError: object is not a function", *exception_value1);
10503 Local<Value> args[] = { v8_num(29) };
10504 value = instance->CallAsConstructor(1, args);
10506 String::Utf8Value exception_value2(try_catch.
Exception());
10507 CHECK_EQ(
"TypeError: #<Object> is not a function", *exception_value2);
10512 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10513 instance_template->SetCallAsFunctionHandler(
ThrowValue);
10514 Local<Object> instance = instance_template->NewInstance();
10515 context->
Global()->Set(v8_str(
"obj3"), instance);
10517 Local<Value> value;
10520 value = CompileRun(
"new obj3(22)");
10522 String::Utf8Value exception_value1(try_catch.
Exception());
10523 CHECK_EQ(
"22", *exception_value1);
10526 Local<Value> args[] = { v8_num(23) };
10527 value = instance->CallAsConstructor(1, args);
10529 String::Utf8Value exception_value2(try_catch.
Exception());
10530 CHECK_EQ(
"23", *exception_value2);
10535 { Local<FunctionTemplate> function_template =
10536 FunctionTemplate::New(isolate, FakeConstructorCallback);
10537 Local<Function>
function = function_template->GetFunction();
10538 Local<Object> instance1 =
function;
10539 context->
Global()->Set(v8_str(
"obj4"), instance1);
10541 Local<Value> value;
10544 CHECK(instance1->IsObject());
10545 CHECK(instance1->IsFunction());
10547 value = CompileRun(
"new obj4(28)");
10549 CHECK(value->IsObject());
10551 Local<Value> args1[] = { v8_num(28) };
10552 value = instance1->CallAsConstructor(1, args1);
10554 CHECK(value->IsObject());
10556 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10557 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
10558 Local<Object> instance2 = instance_template->NewInstance();
10559 context->
Global()->Set(v8_str(
"obj5"), instance2);
10562 CHECK(instance2->IsObject());
10563 CHECK(!instance2->IsFunction());
10565 value = CompileRun(
"new obj5(28)");
10567 CHECK(!value->IsObject());
10569 Local<Value> args2[] = { v8_num(28) };
10570 value = instance2->CallAsConstructor(1, args2);
10572 CHECK(!value->IsObject());
10582 templ->SetClassName(v8_str(
"Fun"));
10583 Local<Function> cons = templ->GetFunction();
10584 context->
Global()->Set(v8_str(
"Fun"), cons);
10585 Local<Value> value = CompileRun(
10586 "function test() {"
10588 " (new Fun()).blah()"
10590 " var str = String(e);"
10608 Local<Script> script = v8_compile(
10611 " with (x) { return eval('foo'); }"
10614 "result1 = f(new Object());"
10615 "result2 = f(this);"
10616 "var x = new Object();"
10617 "x.eval = function(x) { return 1; };"
10618 "result3 = f(x);");
10620 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result1"))->Int32Value());
10621 CHECK_EQ(0, current->
Global()->Get(v8_str(
"result2"))->Int32Value());
10622 CHECK_EQ(1, current->
Global()->Get(v8_str(
"result3"))->Int32Value());
10625 script = v8_compile(
10628 " with (x) { return eval('bar'); }"
10630 "result4 = f(this)");
10632 CHECK(!try_catch.HasCaught());
10633 CHECK_EQ(2, current->
Global()->Get(v8_str(
"result4"))->Int32Value());
10644 Local<String> token = v8_str(
"<security token>");
10649 current->
Global()->Set(v8_str(
"other"), other->
Global());
10652 Local<Script> script = v8_compile(
"other.eval('var foo = 1234')");
10654 Local<Value>
foo = other->
Global()->Get(v8_str(
"foo"));
10655 CHECK_EQ(1234, foo->Int32Value());
10660 script = v8_compile(
"other.eval('na = 1234')");
10662 CHECK_EQ(1234, other->
Global()->Get(v8_str(
"na"))->Int32Value());
10668 script = v8_compile(
"var bar = 42; other.eval('bar');");
10669 Local<Value> result = script->Run();
10670 CHECK(try_catch.HasCaught());
10675 script = v8_compile(
10678 " return other.eval('baz');"
10680 result = script->Run();
10681 CHECK(try_catch.HasCaught());
10686 other->
Global()->Set(v8_str(
"bis"), v8_num(1234));
10687 script = v8_compile(
"other.eval('bis')");
10688 CHECK_EQ(1234, script->Run()->Int32Value());
10689 CHECK(!try_catch.HasCaught());
10694 script = v8_compile(
"other.eval('this == t')");
10695 result = script->Run();
10696 CHECK(result->IsTrue());
10697 CHECK(!try_catch.HasCaught());
10701 script = v8_compile(
"with({x:2}){other.eval('x')}");
10702 result = script->Run();
10703 CHECK(try_catch.HasCaught());
10708 script = v8_compile(
"other.y = 1; eval.call(other, 'y')");
10709 result = script->Run();
10710 CHECK(try_catch.HasCaught());
10727 CompileRun(
"var x = 42;"
10730 " return function(s) { return e(s); }"
10738 context1->Global()->Set(v8_str(
"fun"), fun);
10741 context0->DetachGlobal();
10743 x_value = CompileRun(
"fun('x')");
10755 Local<String> token = v8_str(
"<security token>");
10760 current->
Global()->Set(v8_str(
"other"), other->
Global());
10763 Local<Script> script = v8_compile(
"other.eval('new Date(42)')");
10764 Local<Value> value = script->Run();
10765 CHECK_EQ(42.0, value->NumberValue());
10772 if (args[0]->IsInt32()) {
10796 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10797 instance_template->SetCallAsFunctionHandler(call_as_function);
10798 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10799 context->
Global()->Set(v8_str(
"obj"), instance);
10801 Local<Value> value;
10804 value = CompileRun(
"obj(42)");
10806 CHECK_EQ(42, value->Int32Value());
10808 value = CompileRun(
"(function(o){return o(49)})(obj)");
10810 CHECK_EQ(49, value->Int32Value());
10813 value = CompileRun(
"[obj]['0'](45)");
10815 CHECK_EQ(45, value->Int32Value());
10817 value = CompileRun(
"obj.call = Function.prototype.call;"
10818 "obj.call(null, 87)");
10820 CHECK_EQ(87, value->Int32Value());
10824 const char* apply_99 =
"Function.prototype.call.apply(obj, [this, 99])";
10825 value = CompileRun(apply_99);
10827 CHECK_EQ(99, value->Int32Value());
10829 const char* call_17 =
"Function.prototype.call.call(obj, this, 17)";
10830 value = CompileRun(call_17);
10832 CHECK_EQ(17, value->Int32Value());
10836 value = CompileRun(
"new obj(43)");
10838 CHECK_EQ(-43, value->Int32Value());
10843 value = instance->CallAsFunction(instance, 1, args);
10845 CHECK_EQ(28, value->Int32Value());
10849 Local<ObjectTemplate> instance_template(t->InstanceTemplate());
10850 USE(instance_template);
10851 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10852 context->
Global()->Set(v8_str(
"obj2"), instance);
10854 Local<Value> value;
10858 value = CompileRun(
"obj2(28)");
10859 CHECK(value.IsEmpty());
10861 String::Utf8Value exception_value1(try_catch.
Exception());
10863 CHECK_EQ(
"TypeError: object is not a function",
10864 *exception_value1);
10868 value = CompileRun(
"obj2(28)");
10870 value = instance->CallAsFunction(instance, 1, args);
10871 CHECK(value.IsEmpty());
10873 String::Utf8Value exception_value2(try_catch.
Exception());
10874 CHECK_EQ(
"TypeError: [object Object] is not a function", *exception_value2);
10879 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10880 instance_template->SetCallAsFunctionHandler(
ThrowValue);
10881 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10882 context->
Global()->Set(v8_str(
"obj3"), instance);
10884 Local<Value> value;
10888 value = CompileRun(
"obj3(22)");
10890 String::Utf8Value exception_value1(try_catch.
Exception());
10891 CHECK_EQ(
"22", *exception_value1);
10895 value = instance->CallAsFunction(instance, 1, args);
10897 String::Utf8Value exception_value2(try_catch.
Exception());
10898 CHECK_EQ(
"23", *exception_value2);
10903 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10904 instance_template->SetCallAsFunctionHandler(ReturnThis);
10905 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10907 Local<v8::Value> a1 =
10909 CHECK(a1->StrictEquals(instance));
10910 Local<v8::Value> a2 =
10912 CHECK(a2->StrictEquals(instance));
10913 Local<v8::Value> a3 =
10914 instance->CallAsFunction(v8_num(42), 0,
NULL);
10915 CHECK(a3->StrictEquals(instance));
10916 Local<v8::Value> a4 =
10917 instance->CallAsFunction(v8_str(
"hello"), 0,
NULL);
10918 CHECK(a4->StrictEquals(instance));
10919 Local<v8::Value> a5 =
10921 CHECK(a5->StrictEquals(instance));
10925 "function ReturnThisSloppy() {"
10928 "function ReturnThisStrict() {"
10932 Local<Function> ReturnThisSloppy =
10933 Local<Function>::Cast(
10934 context->
Global()->Get(v8_str(
"ReturnThisSloppy")));
10935 Local<Function> ReturnThisStrict =
10936 Local<Function>::Cast(
10937 context->
Global()->Get(v8_str(
"ReturnThisStrict")));
10939 Local<v8::Value> a1 =
10942 Local<v8::Value> a2 =
10943 ReturnThisSloppy->CallAsFunction(
v8::Null(isolate), 0,
NULL);
10945 Local<v8::Value> a3 =
10946 ReturnThisSloppy->CallAsFunction(v8_num(42), 0,
NULL);
10947 CHECK(a3->IsNumberObject());
10949 Local<v8::Value> a4 =
10950 ReturnThisSloppy->CallAsFunction(v8_str(
"hello"), 0,
NULL);
10951 CHECK(a4->IsStringObject());
10953 Local<v8::Value> a5 =
10954 ReturnThisSloppy->CallAsFunction(
v8::True(isolate), 0,
NULL);
10955 CHECK(a5->IsBooleanObject());
10958 Local<v8::Value> a6 =
10960 CHECK(a6->IsUndefined());
10961 Local<v8::Value> a7 =
10962 ReturnThisStrict->CallAsFunction(
v8::Null(isolate), 0,
NULL);
10963 CHECK(a7->IsNull());
10964 Local<v8::Value> a8 =
10965 ReturnThisStrict->CallAsFunction(v8_num(42), 0,
NULL);
10966 CHECK(a8->StrictEquals(v8_num(42)));
10967 Local<v8::Value> a9 =
10968 ReturnThisStrict->CallAsFunction(v8_str(
"hello"), 0,
NULL);
10969 CHECK(a9->StrictEquals(v8_str(
"hello")));
10970 Local<v8::Value> a10 =
10971 ReturnThisStrict->CallAsFunction(
v8::True(isolate), 0,
NULL);
10983 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10984 instance_template->SetCallAsFunctionHandler(call_as_function);
10985 Local<Object> instance = instance_template->NewInstance();
10988 CHECK(instance->IsCallable());
10992 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10993 Local<Object> instance = instance_template->NewInstance();
10996 CHECK(!instance->IsCallable());
11000 { Local<FunctionTemplate> function_template =
11001 FunctionTemplate::New(isolate, call_as_function);
11002 Local<Function>
function = function_template->GetFunction();
11003 Local<Object> instance =
function;
11006 CHECK(instance->IsCallable());
11010 { Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate);
11011 Local<Function>
function = function_template->GetFunction();
11012 Local<Object> instance =
function;
11015 CHECK(instance->IsCallable());
11021 static int Recurse(
v8::Isolate* isolate,
int depth,
int iterations) {
11024 for (
int i = 0; i < iterations; i++) {
11027 return Recurse(isolate, depth - 1, iterations);
11032 static const int kIterations = 500;
11033 static const int kNesting = 200;
11041 for (
int i = 0; i < kIterations; i++) {
11049 for (
int j = 0; j < kIterations; j++) {
11058 CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations));
11062 static void InterceptorHasOwnPropertyGetter(
11063 Local<String> name,
11074 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
11075 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
11076 Local<Function>
function = fun_templ->GetFunction();
11077 context->
Global()->Set(v8_str(
"constructor"),
function);
11079 "var o = new constructor();"
11080 "o.hasOwnProperty('ostehaps');");
11082 value = CompileRun(
11084 "o.hasOwnProperty('ostehaps');");
11085 CHECK_EQ(
true, value->BooleanValue());
11086 value = CompileRun(
11087 "var p = new constructor();"
11088 "p.hasOwnProperty('ostehaps');");
11089 CHECK_EQ(
false, value->BooleanValue());
11093 static void InterceptorHasOwnPropertyGetterGC(
11094 Local<String> name,
11106 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
11107 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
11108 Local<Function>
function = fun_templ->GetFunction();
11109 context->
Global()->Set(v8_str(
"constructor"),
function);
11112 "function makestr(size) {"
11114 " case 1: return 'f';"
11115 " case 2: return 'fo';"
11116 " case 3: return 'foo';"
11118 " return makestr(size >> 1) + makestr((size + 1) >> 1);"
11120 "var x = makestr(12345);"
11121 "x = makestr(31415);"
11122 "x = makestr(23456);");
11124 "var o = new constructor();"
11125 "o.__proto__ = new String(x);"
11126 "o.hasOwnProperty('ostehaps');");
11132 Local<String> property,
11137 const char* source,
11150 static void InterceptorLoadICGetter(
11151 Local<String> name,
11164 CheckInterceptorLoadIC(InterceptorLoadICGetter,
11166 "for (var i = 0; i < 1000; i++) {"
11177 static void InterceptorLoadXICGetter(
11178 Local<String> name,
11182 v8_str(
"x")->Equals(name) ?
11189 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11192 "for (var i = 0; i < 1000; i++) {"
11200 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11202 "o.__proto__ = { 'y': 239 };"
11203 "for (var i = 0; i < 1000; i++) {"
11204 " result = o.y + o.x;"
11211 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11213 "o.__proto__.y = 239;"
11214 "for (var i = 0; i < 1000; i++) {"
11215 " result = o.y + o.x;"
11222 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11224 "for (var i = 0; i < 1000; i++) {"
11225 " result = (o.y == undefined) ? 239 : 42;"
11232 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11233 "fst = new Object(); fst.__proto__ = o;"
11234 "snd = new Object(); snd.__proto__ = fst;"
11236 "for (var i = 0; i < 1000; i++) {"
11237 " result1 = snd.x;"
11241 "for (var i = 0; i < 1000; i++) {"
11244 "result + result1",
11252 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11253 "proto = new Object();"
11254 "o.__proto__ = proto;"
11256 "for (var i = 0; i < 1000; i++) {"
11261 "for (var i = 0; i < 1000; i++) {"
11272 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11273 "proto1 = new Object();"
11274 "proto2 = new Object();"
11275 "o.__proto__ = proto1;"
11276 "proto1.__proto__ = proto2;"
11278 "for (var i = 0; i < 1000; i++) {"
11284 "for (var i = 0; i < 1000; i++) {"
11292 static int interceptor_load_not_handled_calls = 0;
11293 static void InterceptorLoadNotHandled(
11294 Local<String> name,
11296 ++interceptor_load_not_handled_calls;
11303 interceptor_load_not_handled_calls = 0;
11304 CheckInterceptorLoadIC(InterceptorLoadNotHandled,
11305 "receiver = new Object();"
11306 "receiver.__proto__ = o;"
11307 "proto = new Object();"
11308 "/* Make proto a slow-case object. */"
11309 "for (var i = 0; i < 1000; i++) {"
11310 " proto[\"xxxxxxxx\" + i] = [];"
11313 "o.__proto__ = proto;"
11315 "for (var i = 0; i < 1000; i++) {"
11316 " result += receiver.x;"
11320 CHECK_EQ(1000, interceptor_load_not_handled_calls);
11328 CheckInterceptorLoadIC(InterceptorLoadXICGetter,
11329 "o.__proto__ = this;"
11330 "this.__proto__.y = 239;"
11331 "for (var i = 0; i < 10; i++) {"
11332 " if (o.y != 239) throw 'oops: ' + o.y;"
11337 "for (var i = 0; i < 10; i++) {"
11345 static void SetOnThis(Local<String> name,
11346 Local<Value> value,
11348 info.
This()->ForceSet(name, value);
11357 templ->
SetAccessor(v8_str(
"y"), Return239Callback);
11365 "for (var i = 0; i < 7; i++) {"
11372 value = CompileRun(
11373 "r = { __proto__: o };"
11375 "for (var i = 0; i < 7; i++) {"
11378 CHECK_EQ(239, value->Int32Value());
11388 templ_p->
SetAccessor(v8_str(
"y"), Return239Callback);
11399 "for (var i = 0; i < 7; i++) {"
11400 " result = o.x + o.y;"
11406 value = CompileRun(
11407 "r = { __proto__: o };"
11409 "for (var i = 0; i < 7; i++) {"
11410 " result = r.x + r.y;"
11412 CHECK_EQ(239 + 42, value->Int32Value());
11421 templ->
SetAccessor(v8_str(
"y"), Return239Callback);
11427 "fst = new Object(); fst.__proto__ = o;"
11428 "snd = new Object(); snd.__proto__ = fst;"
11430 "for (var i = 0; i < 7; i++) {"
11431 " result1 = snd.x;"
11435 "for (var i = 0; i < 7; i++) {"
11438 "result + result1");
11451 templ_p->
SetAccessor(v8_str(
"y"), Return239Callback);
11459 "for (var i = 0; i < 7; i++) {"
11464 "for (var i = 0; i < 7; i++) {"
11480 templ_p->
SetAccessor(v8_str(
"y"), Return239Callback, SetOnThis);
11487 "inbetween = new Object();"
11488 "o.__proto__ = inbetween;"
11489 "inbetween.__proto__ = p;"
11490 "for (var i = 0; i < 10; i++) {"
11494 "inbetween.y = 42;"
11496 "for (var i = 0; i < 10; i++) {"
11513 templ_p->
SetAccessor(v8_str(
"y"), Return239Callback, SetOnThis);
11520 "o.__proto__ = this;"
11521 "this.__proto__ = p;"
11522 "for (var i = 0; i < 10; i++) {"
11523 " if (o.y != 239) throw 'oops: ' + o.y;"
11528 "for (var i = 0; i < 10; i++) {"
11536 static void InterceptorLoadICGetter0(
11537 Local<String> name,
11540 CHECK(v8_str(
"x")->Equals(name));
11546 CheckInterceptorLoadIC(InterceptorLoadICGetter0,
11547 "o.x == undefined ? 1 : 0",
11552 static void InterceptorStoreICSetter(
11554 Local<Value> value,
11556 CHECK(v8_str(
"x")->Equals(key));
11557 CHECK_EQ(42, value->Int32Value());
11568 InterceptorStoreICSetter,
11569 0, 0, 0, v8_str(
"data"));
11573 "for (var i = 0; i < 1000; i++) {"
11587 "for (var i = 0; i < 1000; i++) {"
11601 static void InterceptorCallICGetter(
11602 Local<String> name,
11605 CHECK(v8_str(
"x")->Equals(name));
11619 v8_compile(
"function f(x) { return x + 1; }; f")->Run();
11622 "for (var i = 0; i < 1000; i++) {"
11623 " result = o.x(41);"
11639 "o.x = function f(x) { return x + 1; };"
11641 "for (var i = 0; i < 7; i++) {"
11642 " result = o.x(41);"
11649 static void InterceptorCallICGetter4(
11650 Local<String> name,
11653 CHECK(v8_str(
"x")->Equals(name));
11668 call_ic_function4 =
11669 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
11671 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };"
11673 "for (var i = 0; i < 1000; i++) {"
11674 " result = o.x(42);"
11690 "proto1 = new Object();"
11691 "proto2 = new Object();"
11692 "o.__proto__ = proto1;"
11693 "proto1.__proto__ = proto2;"
11694 "proto2.y = function(x) { return x + 1; };"
11696 "for (var i = 0; i < 7; i++) {"
11699 "proto1.y = function(x) { return x - 1; };"
11701 "for (var i = 0; i < 7; i++) {"
11702 " result += o.y(42);"
11718 "function inc(x) { return x + 1; };"
11722 "for (var i = 0; i < 1000; i++) {"
11723 " result = o.x(42);"
11730 static void InterceptorCallICGetter5(
11731 Local<String> name,
11734 if (v8_str(
"x")->Equals(name))
11749 call_ic_function5 =
11750 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
11752 "function inc(x) { return x + 1; };"
11756 "for (var i = 0; i < 1000; i++) {"
11757 " result = o.x(42);"
11764 static void InterceptorCallICGetter6(
11765 Local<String> name,
11768 if (v8_str(
"x")->Equals(name))
11776 i::FLAG_allow_natives_syntax =
true;
11783 call_ic_function6 =
11784 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
11786 "function inc(x) { return x + 1; };"
11789 "function test() {"
11791 " for (var i = 0; i < 1000; i++) {"
11792 " result = o.x(42);"
11799 "%OptimizeFunctionOnNextCall(test);"
11815 "function inc(x) { return x + 1; };"
11817 "proto1 = new Object();"
11818 "proto2 = new Object();"
11819 "o.__proto__ = proto1;"
11820 "proto1.__proto__ = proto2;"
11823 "for (var i = 0; i < 7; i++) {"
11826 "proto1.y = function(x) { return x - 1; };"
11828 "for (var i = 0; i < 7; i++) {"
11829 " result += o.y(42);"
11846 "function inc(x) { return x + 1; };"
11848 "o.__proto__ = this;"
11849 "this.__proto__.y = inc;"
11851 "for (var i = 0; i < 7; i++) {"
11852 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
11854 "this.y = function(x) { return x - 1; };"
11856 "for (var i = 0; i < 7; i++) {"
11857 " result += o.y(42);"
11875 " o.__proto__ = this;"
11876 " for (var i = 0; i < 10; i++) {"
11877 " var v = o.parseFloat('239');"
11878 " if (v != 239) throw v;"
11882 " for (var i = 0; i < 10; i++) {"
11883 " result += o.parseFloat('239');"
11892 static void InterceptorCallICFastApi(
11893 Local<String> name,
11896 CheckReturnValue(info,
FUNCTION_ADDR(InterceptorCallICFastApi));
11900 if ((*call_count) % 20 == 0) {
11905 static void FastApiCallback_TrivialSignature(
11908 CheckReturnValue(args,
FUNCTION_ADDR(FastApiCallback_TrivialSignature));
11912 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
11916 static void FastApiCallback_SimpleSignature(
11919 CheckReturnValue(args,
FUNCTION_ADDR(FastApiCallback_SimpleSignature));
11923 CHECK(args.
Data()->Equals(v8_str(
"method_data")));
11926 CHECK(args.
Holder()->HasRealNamedProperty(v8_str(
"foo")));
11932 static void GenerateSomeGarbage() {
11935 "for (var i = 0; i < 1000; i++) {"
11936 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
11938 "garbage = undefined;");
11943 static int count = 0;
11944 if (count++ % 3 == 0) {
11947 GenerateSomeGarbage();
11958 nativeobject_templ->
Set(isolate,
"callback",
11962 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
11966 " for (var i = 1; i <= 30; i++) {"
11967 " nativeobject.callback();"
11976 args.
GetIsolate()->ThrowException(v8_str(
"g"));
11986 nativeobject_templ->
Set(isolate,
"callback",
11990 context->
Global()->Set(v8_str(
"nativeobject"), nativeobject_obj);
11995 " for (var i = 1; i <= 5; i++) {"
11996 " try { nativeobject.callback(); } catch (e) { result += e; }"
12000 CHECK_EQ(v8_str(
"ggggg"), result);
12004 static Handle<Value> DoDirectGetter() {
12005 if (++p_getter_count % 3 == 0) {
12007 GenerateSomeGarbage();
12009 return v8_str(
"Direct Getter Result");
12012 static void DirectGetterCallback(
12013 Local<String> name,
12015 CheckReturnValue(info,
FUNCTION_ADDR(DirectGetterCallback));
12020 template<
typename Accessor>
12021 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
12028 p_getter_count = 0;
12031 " for (var i = 0; i < 30; i++) o1.p1;"
12035 CHECK_EQ(v8_str(
"Direct Getter Result"), result);
12041 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
12046 Local<String> name,
12048 info.
GetIsolate()->ThrowException(v8_str(
"g"));
12061 "for (var i = 0; i < 5; i++) {"
12062 " try { o1.p1; } catch (e) { result += e; }"
12065 CHECK_EQ(v8_str(
"ggggg"), result);
12070 int interceptor_call_count = 0;
12077 FastApiCallback_TrivialSignature,
12078 v8_str(
"method_data"),
12081 proto_templ->
Set(v8_str(
"method"), method_templ);
12088 GenerateSomeGarbage();
12092 "for (var i = 0; i < 100; i++) {"
12093 " result = o.method(41);"
12095 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12096 CHECK_EQ(100, interceptor_call_count);
12101 int interceptor_call_count = 0;
12107 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12110 proto_templ->
Set(v8_str(
"method"), method_templ);
12118 GenerateSomeGarbage();
12122 "var receiver = {};"
12123 "receiver.__proto__ = o;"
12125 "for (var i = 0; i < 100; i++) {"
12126 " result = receiver.method(41);"
12128 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12129 CHECK_EQ(100, interceptor_call_count);
12134 int interceptor_call_count = 0;
12140 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12143 proto_templ->
Set(v8_str(
"method"), method_templ);
12151 GenerateSomeGarbage();
12155 "var receiver = {};"
12156 "receiver.__proto__ = o;"
12158 "var saved_result = 0;"
12159 "for (var i = 0; i < 100; i++) {"
12160 " result = receiver.method(41);"
12162 " saved_result = result;"
12163 " receiver = {method: function(x) { return x - 1 }};"
12166 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12167 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
12168 CHECK_GE(interceptor_call_count, 50);
12173 int interceptor_call_count = 0;
12179 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12182 proto_templ->
Set(v8_str(
"method"), method_templ);
12190 GenerateSomeGarbage();
12194 "var receiver = {};"
12195 "receiver.__proto__ = o;"
12197 "var saved_result = 0;"
12198 "for (var i = 0; i < 100; i++) {"
12199 " result = receiver.method(41);"
12201 " saved_result = result;"
12202 " o.method = function(x) { return x - 1 };"
12205 CHECK_EQ(40, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12206 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
12207 CHECK_GE(interceptor_call_count, 50);
12212 int interceptor_call_count = 0;
12218 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12221 proto_templ->
Set(v8_str(
"method"), method_templ);
12229 GenerateSomeGarbage();
12234 "var receiver = {};"
12235 "receiver.__proto__ = o;"
12237 "var saved_result = 0;"
12238 "for (var i = 0; i < 100; i++) {"
12239 " result = receiver.method(41);"
12241 " saved_result = result;"
12247 CHECK_EQ(v8_str(
"TypeError: undefined is not a function"),
12249 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
12250 CHECK_GE(interceptor_call_count, 50);
12255 int interceptor_call_count = 0;
12261 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12264 proto_templ->
Set(v8_str(
"method"), method_templ);
12272 GenerateSomeGarbage();
12277 "var receiver = {};"
12278 "receiver.__proto__ = o;"
12280 "var saved_result = 0;"
12281 "for (var i = 0; i < 100; i++) {"
12282 " result = receiver.method(41);"
12284 " saved_result = result;"
12285 " receiver = {method: receiver.method};"
12289 CHECK_EQ(v8_str(
"TypeError: Illegal invocation"),
12291 CHECK_EQ(42, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
12292 CHECK_GE(interceptor_call_count, 50);
12303 FastApiCallback_TrivialSignature,
12304 v8_str(
"method_data"),
12307 proto_templ->
Set(v8_str(
"method"), method_templ);
12312 GenerateSomeGarbage();
12316 "for (var i = 0; i < 100; i++) {"
12317 " result = o.method(41);"
12320 CHECK_EQ(42, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12330 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12333 proto_templ->
Set(v8_str(
"method"), method_templ);
12336 CHECK(!templ.IsEmpty());
12339 GenerateSomeGarbage();
12343 "var receiver = {};"
12344 "receiver.__proto__ = o;"
12346 "for (var i = 0; i < 100; i++) {"
12347 " result = receiver.method(41);"
12350 CHECK_EQ(42, context->Global()->Get(v8_str(
"result"))->Int32Value());
12360 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12363 proto_templ->
Set(v8_str(
"method"), method_templ);
12366 CHECK(!templ.IsEmpty());
12369 GenerateSomeGarbage();
12373 "var receiver = {};"
12374 "receiver.__proto__ = o;"
12376 "var saved_result = 0;"
12377 "for (var i = 0; i < 100; i++) {"
12378 " result = receiver.method(41);"
12380 " saved_result = result;"
12381 " receiver = {method: function(x) { return x - 1 }};"
12384 CHECK_EQ(40, context->Global()->Get(v8_str(
"result"))->Int32Value());
12385 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
12395 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12398 proto_templ->
Set(v8_str(
"method"), method_templ);
12401 CHECK(!templ.IsEmpty());
12404 GenerateSomeGarbage();
12409 "var receiver = {};"
12410 "receiver.__proto__ = o;"
12412 "var saved_result = 0;"
12413 "for (var i = 0; i < 100; i++) {"
12414 " result = receiver.method(41);"
12416 " saved_result = result;"
12422 CHECK_EQ(v8_str(
"TypeError: undefined is not a function"),
12424 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
12434 isolate, FastApiCallback_SimpleSignature, v8_str(
"method_data"),
12437 proto_templ->
Set(v8_str(
"method"), method_templ);
12440 CHECK(!templ.IsEmpty());
12443 GenerateSomeGarbage();
12448 "var receiver = {};"
12449 "receiver.__proto__ = o;"
12451 "var saved_result = 0;"
12452 "for (var i = 0; i < 100; i++) {"
12453 " result = receiver.method(41);"
12455 " saved_result = result;"
12456 " receiver = Object.create(receiver);"
12460 CHECK_EQ(v8_str(
"TypeError: Illegal invocation"),
12462 CHECK_EQ(42, context->Global()->Get(v8_str(
"saved_result"))->Int32Value());
12468 static void InterceptorKeyedCallICGetter(
12469 Local<String> name,
12472 if (v8_str(
"x")->Equals(name)) {
12488 "proto = new Object();"
12489 "proto.y = function(x) { return x + 1; };"
12490 "proto.z = function(x) { return x - 1; };"
12491 "o.__proto__ = proto;"
12493 "var method = 'y';"
12494 "for (var i = 0; i < 10; i++) {"
12495 " if (i == 5) { method = 'z'; };"
12496 " result += o[method](41);"
12498 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12512 keyed_call_ic_function =
12513 v8_compile(
"function f(x) { return x - 1; }; f")->Run();
12515 "o = new Object();"
12516 "proto2 = new Object();"
12517 "o.y = function(x) { return x + 1; };"
12518 "proto2.y = function(x) { return x + 2; };"
12519 "o.__proto__ = proto1;"
12520 "proto1.__proto__ = proto2;"
12522 "var method = 'x';"
12523 "for (var i = 0; i < 10; i++) {"
12524 " if (i == 5) { method = 'y'; };"
12525 " result += o[method](41);"
12527 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12541 "function inc(x) { return x + 1; };"
12543 "function dec(x) { return x - 1; };"
12545 "o.__proto__ = this;"
12546 "this.__proto__.x = inc;"
12547 "this.__proto__.y = dec;"
12549 "var method = 'x';"
12550 "for (var i = 0; i < 10; i++) {"
12551 " if (i == 5) { method = 'y'; };"
12552 " result += o[method](41);"
12554 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12568 "function len(x) { return x.length; };"
12569 "o.__proto__ = this;"
12570 "var m = 'parseFloat';"
12572 "for (var i = 0; i < 10; i++) {"
12575 " saved_result = result;"
12577 " result = o[m]('239');"
12579 CHECK_EQ(3, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12580 CHECK_EQ(239, context->
Global()->Get(v8_str(
"saved_result"))->Int32Value());
12594 "var o = new Object();"
12595 "o.__proto__ = proto;"
12596 "o.method = function(x) { return x + 1; };"
12597 "var m = 'method';"
12599 "for (var i = 0; i < 10; i++) {"
12600 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
12601 " result += o[m](41);"
12603 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12617 "var proto = new Object();"
12618 "o.__proto__ = proto;"
12619 "proto.method = function(x) { return x + 1; };"
12620 "var m = 'method';"
12622 "for (var i = 0; i < 10; i++) {"
12623 " if (i == 5) { proto.method = function(x) { return x - 1; }; };"
12624 " result += o[m](41);"
12626 CHECK_EQ(42*5 + 40*5, context->
Global()->Get(v8_str(
"result"))->Int32Value());
12630 static int interceptor_call_count = 0;
12632 static void InterceptorICRefErrorGetter(
12633 Local<String> name,
12636 if (v8_str(
"x")->Equals(name) && interceptor_call_count++ < 20) {
12651 call_ic_function2 = v8_compile(
"function h(x) { return x; }; h")->Run();
12654 " for (var i = 0; i < 1000; i++) {"
12655 " try { x; } catch(e) { return true; }"
12661 interceptor_call_count = 0;
12662 value = CompileRun(
12664 " for (var i = 0; i < 1000; i++) {"
12665 " try { x(42); } catch(e) { return true; }"
12674 static int interceptor_ic_exception_get_count = 0;
12676 static void InterceptorICExceptionGetter(
12677 Local<String> name,
12680 if (v8_str(
"x")->Equals(name) && ++interceptor_ic_exception_get_count < 20) {
12683 if (interceptor_ic_exception_get_count == 20) {
12684 info.
GetIsolate()->ThrowException(v8_num(42));
12693 interceptor_ic_exception_get_count = 0;
12699 call_ic_function3 = v8_compile(
"function h(x) { return x; }; h")->Run();
12702 " for (var i = 0; i < 100; i++) {"
12703 " try { x; } catch(e) { return true; }"
12709 interceptor_ic_exception_get_count = 0;
12710 value = CompileRun(
12712 " for (var i = 0; i < 100; i++) {"
12713 " try { x(42); } catch(e) { return true; }"
12722 static int interceptor_ic_exception_set_count = 0;
12724 static void InterceptorICExceptionSetter(
12726 Local<Value> value,
12729 if (++interceptor_ic_exception_set_count > 20) {
12730 info.
GetIsolate()->ThrowException(v8_num(42));
12738 interceptor_ic_exception_set_count = 0;
12746 " for (var i = 0; i < 100; i++) {"
12747 " try { x = 42; } catch(e) { return true; }"
12762 static_cast<v8::NamedPropertyGetterCallback>(0));
12766 context->
Global()->Set(v8_str(
"obj"), obj);
12779 static_cast<v8::IndexedPropertyGetterCallback>(0));
12783 context->
Global()->Set(v8_str(
"obj"), obj);
12794 templ->
InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
12796 env->
Global()->Set(v8_str(
"obj"),
12798 ExpectTrue(
"obj.x === 42");
12799 ExpectTrue(
"!obj.propertyIsEnumerable('x')");
12803 static void ThrowingGetter(Local<String> name,
12806 info.
GetIsolate()->ThrowException(Handle<Value>());
12815 Local<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
12816 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
12817 instance_templ->SetAccessor(v8_str(
"f"), ThrowingGetter);
12819 Local<Object> instance = templ->GetFunction()->NewInstance();
12821 Local<Object> another = Object::New(context->
GetIsolate());
12822 another->SetPrototype(instance);
12824 Local<Object> with_js_getter = CompileRun(
12826 "o.__defineGetter__('f', function() { throw undefined; });\n"
12828 CHECK(!with_js_getter.IsEmpty());
12830 TryCatch try_catch;
12832 Local<Value> result = instance->GetRealNamedProperty(v8_str(
"f"));
12833 CHECK(try_catch.HasCaught());
12835 CHECK(result.IsEmpty());
12837 result = another->GetRealNamedProperty(v8_str(
"f"));
12838 CHECK(try_catch.HasCaught());
12840 CHECK(result.IsEmpty());
12842 result = another->GetRealNamedPropertyInPrototypeChain(v8_str(
"f"));
12843 CHECK(try_catch.HasCaught());
12845 CHECK(result.IsEmpty());
12847 result = another->Get(v8_str(
"f"));
12848 CHECK(try_catch.HasCaught());
12850 CHECK(result.IsEmpty());
12852 result = with_js_getter->GetRealNamedProperty(v8_str(
"f"));
12853 CHECK(try_catch.HasCaught());
12855 CHECK(result.IsEmpty());
12857 result = with_js_getter->Get(v8_str(
"f"));
12858 CHECK(try_catch.HasCaught());
12860 CHECK(result.IsEmpty());
12864 static void ThrowingCallbackWithTryCatch(
12866 TryCatch try_catch;
12870 CompileRun(
"throw 'from JS';");
12871 CHECK(try_catch.HasCaught());
12877 static int call_depth;
12880 static void WithTryCatch(Handle<Message> message, Handle<Value> data) {
12881 TryCatch try_catch;
12885 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) {
12886 if (--call_depth) CompileRun(
"throw 'ThrowInJS';");
12890 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) {
12895 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
12896 Handle<String> errorMessageString = message->Get();
12897 CHECK(!errorMessageString.IsEmpty());
12898 message->GetStackTrace();
12899 message->GetScriptResourceName();
12906 HandleScope scope(isolate);
12908 Local<Function> func =
12909 FunctionTemplate::New(isolate,
12910 ThrowingCallbackWithTryCatch)->GetFunction();
12911 context->
Global()->Set(v8_str(
"func"), func);
12915 for (
unsigned i = 0; i <
sizeof(callbacks)/
sizeof(callbacks[0]); i++) {
12917 if (callback !=
NULL) {
12918 V8::AddMessageListener(callback);
12924 "var thrown = false;\n"
12925 "try { func(); } catch(e) { thrown = true; }\n"
12927 if (callback !=
NULL) {
12928 V8::RemoveMessageListeners(callback);
12934 static void ParentGetter(Local<String> name,
12941 static void ChildGetter(Local<String> name,
12955 Local<ObjectTemplate> parent_instance_templ =
12956 parent_templ->InstanceTemplate();
12957 parent_instance_templ->SetAccessor(v8_str(
"f"), ParentGetter);
12961 Local<ObjectTemplate> child_instance_templ =
12962 child_templ->InstanceTemplate();
12963 child_templ->Inherit(parent_templ);
12966 child_instance_templ->SetAccessor(v8_str(
"f"), ChildGetter);
12968 child_instance_templ->SetAccessor(v8_str(
"g"), ParentGetter);
12969 child_instance_templ->SetAccessor(v8_str(
"g"), ChildGetter);
12973 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate();
12974 child_proto_templ->SetAccessor(v8_str(
"h"), ParentGetter, 0,
12980 child_instance_templ->SetAccessor(v8_str(
"i"), ChildGetter, 0,
12986 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance();
12989 context->
Global()->Set(v8_str(
"o"), instance);
12990 Local<Value> value = v8_compile(
"o.f")->Run();
12992 CHECK_EQ(42, value->Int32Value());
12993 value = v8_compile(
"o.g")->Run();
12994 CHECK_EQ(42, value->Int32Value());
12997 value = v8_compile(
"o.h = 3; o.h")->Run();
13001 value = v8_compile(
"o.i = 3; o.i")->Run();
13002 CHECK_EQ(42, value->Int32Value());
13006 static void IsConstructHandler(
13019 templ->SetCallHandler(IsConstructHandler);
13023 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
13024 Local<Value> value = v8_compile(
"f()")->Run();
13025 CHECK(!value->BooleanValue());
13026 value = v8_compile(
"new f()")->Run();
13027 CHECK(value->BooleanValue());
13035 templ->SetClassName(v8_str(
"MyClass"));
13039 Local<String> customized_tostring = v8_str(
"customized toString");
13042 v8_compile(
"Object.prototype.toString = function() {"
13043 " return 'customized toString';"
13047 Local<v8::Object> instance = templ->GetFunction()->NewInstance();
13048 Local<String> value = instance->ToString();
13049 CHECK(value->IsString() && value->Equals(customized_tostring));
13052 value = instance->ObjectProtoToString();
13053 CHECK(value->IsString() && value->Equals(v8_str(
"[object MyClass]")));
13056 value = context->
Global()->ObjectProtoToString();
13057 CHECK(value->IsString() && value->Equals(v8_str(
"[object global]")));
13060 Local<Value>
object = v8_compile(
"new Object()")->Run();
13061 value =
object.As<
v8::Object>()->ObjectProtoToString();
13062 CHECK(value->IsString() && value->Equals(v8_str(
"[object Object]")));
13069 v8_compile(
"function Parent() {};"
13070 "function Child() {};"
13071 "Child.prototype = new Parent();"
13072 "var outer = { inner: function() { } };"
13073 "var p = new Parent();"
13074 "var c = new Child();"
13075 "var x = new outer.inner();")->Run();
13077 Local<v8::Value> p = context->
Global()->Get(v8_str(
"p"));
13078 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals(
13079 v8_str(
"Parent")));
13081 Local<v8::Value> c = context->
Global()->Get(v8_str(
"c"));
13082 CHECK(c->IsObject() && c->ToObject()->GetConstructorName()->Equals(
13085 Local<v8::Value> x = context->
Global()->Get(v8_str(
"x"));
13086 CHECK(x->IsObject() && x->ToObject()->GetConstructorName()->Equals(
13087 v8_str(
"outer.inner")));
13091 bool ApiTestFuzzer::fuzzing_ =
false;
13092 i::Semaphore ApiTestFuzzer::all_tests_done_(0);
13093 int ApiTestFuzzer::active_tests_;
13094 int ApiTestFuzzer::tests_being_run_;
13095 int ApiTestFuzzer::current_;
13101 if (!fuzzing_)
return;
13103 test->ContextSwitch();
13109 bool ApiTestFuzzer::NextThread() {
13110 int test_position = GetNextTestNumber();
13112 if (test_position == current_) {
13114 printf(
"Stay with %s\n", test_name);
13117 if (kLogThreading) {
13118 printf(
"Switch from %s to %s\n",
13122 current_ = test_position;
13140 if (active_tests_ == 0) {
13141 all_tests_done_.Signal();
13149 static unsigned linear_congruential_generator;
13153 linear_congruential_generator = i::FLAG_testing_prng_seed;
13156 int start = count * part / (
LAST_PART + 1);
13157 int end = (count * (part + 1) / (
LAST_PART + 1)) - 1;
13158 active_tests_ = tests_being_run_ = end - start + 1;
13159 for (
int i = 0; i < tests_being_run_; i++) {
13162 for (
int i = 0; i < active_tests_; i++) {
13168 static void CallTestNumber(
int test_number) {
13178 all_tests_done_.Wait();
13182 int ApiTestFuzzer::GetNextTestNumber() {
13185 next_test = (linear_congruential_generator >> 16) % tests_being_run_;
13186 linear_congruential_generator *= 1664525u;
13187 linear_congruential_generator += 1013904223u;
13193 void ApiTestFuzzer::ContextSwitch() {
13195 if (NextThread()) {
13209 if (fuzzer !=
NULL) fuzzer->
Join();
13246 printf(
"Start test %d\n", test_number_);
13247 CallTestNumber(test_number_);
13249 printf(
"End test %d\n", test_number_);
13258 const char* code =
"throw 7;";
13270 exception = Local<Value>::New(isolate, try_catch.
Exception());
13272 args.
GetIsolate()->ThrowException(exception);
13281 const char* code =
"throw 7;";
13286 CHECK(value.IsEmpty());
13300 Local<v8::FunctionTemplate> fun_templ =
13302 Local<Function> fun = fun_templ->GetFunction();
13303 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
13304 Local<Script> script = v8_compile(
"(function () {"
13312 CHECK_EQ(91, script->Run()->Int32Value());
13322 Local<v8::FunctionTemplate> fun_templ =
13324 Local<Function> fun = fun_templ->GetFunction();
13325 env->
Global()->Set(v8_str(
"throw_in_js"), fun);
13326 Local<Script> script = v8_compile(
"(function () {"
13334 CHECK_EQ(91, script->Run()->Int32Value());
13358 Local<v8::FunctionTemplate> fun_templ =
13360 Local<Function> fun = fun_templ->GetFunction();
13361 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
13362 Local<Script> script = v8_compile(
"(function () {"
13363 " unlock_for_a_moment();"
13366 CHECK_EQ(42, script->Run()->Int32Value());
13372 Local<v8::FunctionTemplate> fun_templ =
13374 Local<Function> fun = fun_templ->GetFunction();
13375 env->
Global()->Set(v8_str(
"unlock_for_a_moment"), fun);
13376 Local<Script> script = v8_compile(
"(function () {"
13377 " unlock_for_a_moment();"
13380 CHECK_EQ(42, script->Run()->Int32Value());
13385 static int GetGlobalObjectsCount() {
13390 if (object->IsJSGlobalObject()) count++;
13395 static void CheckSurvivingGlobalObjectsCount(
int expected) {
13403 int count = GetGlobalObjectsCount();
13405 if (count != expected)
CcTest::heap()->TracePathToGlobal();
13414 i::FLAG_expose_gc =
true;
13417 for (
int i = 0; i < 5; i++) {
13422 CheckSurvivingGlobalObjectsCount(0);
13426 v8_compile(
"Date")->Run();
13429 CheckSurvivingGlobalObjectsCount(0);
13433 v8_compile(
"/aaa/")->Run();
13436 CheckSurvivingGlobalObjectsCount(0);
13439 const char* extension_list[] = {
"v8/gc" };
13442 v8_compile(
"gc();")->Run();
13445 CheckSurvivingGlobalObjectsCount(0);
13454 reinterpret_cast<i::Isolate*
>(isolate)->global_handles();
13459 CopyableObject handle1;
13465 CopyableObject handle2;
13467 CHECK(handle1 == handle2);
13469 CopyableObject handle3(handle2);
13470 CHECK(handle1 == handle3);
13478 static void WeakApiCallback(
13480 Local<Value> value = data.GetValue()->Get(v8_str(
"key"));
13481 CHECK_EQ(231, static_cast<int32_t>(Local<v8::Integer>::Cast(value)->Value()));
13482 data.GetParameter()->Reset();
13483 delete data.GetParameter();
13491 reinterpret_cast<i::Isolate*
>(isolate)->global_handles();
13502 reinterpret_cast<i::Isolate*
>(isolate)->heap()->
13516 data.GetParameter()->Reset();
13545 to_be_disposed.
Reset();
13547 data.GetParameter()->Reset();
13562 to_be_disposed.
Reset(isolate, handle2);
13568 data.GetParameter()->Reset();
13576 data.GetParameter()->Reset();
13601 const char* sources[nof] = {
13602 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
13606 for (
int i = 0; i < nof; i++) {
13607 const char* source = sources[i];
13610 CompileRun(source);
13614 CompileRun(source);
13637 CHECK(!str.IsEmpty());
13642 static bool MatchPointers(
void* key1,
void* key2) {
13643 return key1 == key2;
13677 uintptr_t return_addr_location);
13679 uintptr_t return_addr_location) {
13698 const char* function_name);
13717 if (start <= addr && start + len > addr)
13726 SymbolLocationMap::iterator it =
13730 SymbolLocationMap::iterator left = it;
13732 if (!Overlaps(left->first, left->second->size, addr))
13739 SymbolLocationMap::iterator right = it;
13743 if (!Overlaps(addr, symbol->
size, right->first))
13751 switch (event->
type) {
13756 size_t symbol_id =
symbols_.size();
13760 info.
id = symbol_id;
13761 info.
size =
event->code_len;
13777 SymbolLocationMap::iterator it(
13779 reinterpret_cast<i::Address>(event->
code_start)));
13794 uintptr_t
function, uintptr_t return_addr_location) {
13797 reinterpret_cast<i::Address>(
function));
13807 ++
invocations_[std::make_pair(caller_symbol, function_symbol)];
13811 SymbolLocationMap::iterator it(
13818 SymbolLocationMap::iterator it(
13829 if (it->first == addr)
13838 size_t offs = addr - it->first;
13839 if (offs < it->second->size)
13847 const char* caller_name,
const char* function_name) {
13849 int invocations = 0;
13855 if (function_name !=
NULL) {
13856 if (function->name.find(function_name) == std::string::npos)
13861 if (caller_name !=
NULL) {
13862 if (caller ==
NULL)
13864 if (caller->
name.find(caller_name) == std::string::npos)
13869 invocations += it->second;
13872 return invocations;
13881 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
13883 env->Global()->Set(v8_str(
"obj"), t->NewInstance());
13885 const char* script =
13886 "function bar() {\n"
13888 " for (i = 0; i < 100; ++i)\n"
13892 "function foo(i) { return i * i; }\n"
13893 "// Invoke on the runtime function.\n"
13895 CompileRun(script);
13903 ASSERT(!foo_func_.is_null());
13906 CHECK(value->IsNumber());
13910 value = CompileRun(
"%OptimizeFunctionOnNextCall(foo);"
13912 CHECK(value->IsNumber());
13974 i::FLAG_allow_natives_syntax =
true;
13975 i::FLAG_use_inlining =
false;
13984 static int saw_bar = 0;
13985 static int move_events = 0;
13988 static bool FunctionNameIs(
const char* expected,
13993 static const char kPreamble[] =
"LazyCompile:";
13994 static size_t kPreambleLen =
sizeof(kPreamble) - 1;
13996 if (event->
name.
len <
sizeof(kPreamble) - 1 ||
13997 strncmp(kPreamble, event->
name.
str, kPreambleLen) != 0) {
14001 const char* tail =
event->name.str + kPreambleLen;
14002 size_t tail_len =
event->name.len - kPreambleLen;
14003 size_t expected_len = strlen(expected);
14004 if (tail_len > 1 && (*tail ==
'*' || *tail ==
'~')) {
14010 if (tail_len > expected_len + 2 &&
14011 tail[expected_len] ==
' ' &&
14012 tail[expected_len + 1] ==
':' &&
14013 tail[expected_len + 2] &&
14014 !strncmp(tail, expected, expected_len)) {
14018 if (tail_len != expected_len)
14021 return strncmp(tail, expected, expected_len) == 0;
14030 class DummyJitCodeLineInfo {
14033 switch (event->
type) {
14038 i::HashMap::Entry* entry =
14042 entry->value =
reinterpret_cast<void*
>(
event->code_len);
14044 if (FunctionNameIs(
"bar", event)) {
14059 i::HashMap::Entry* entry =
14061 if (entry !=
NULL) {
14071 entry->value =
reinterpret_cast<void*
>(
event->code_len);
14085 DummyJitCodeLineInfo* line_info =
new DummyJitCodeLineInfo();
14088 i::HashMap::Entry* entry =
14089 jitcode_line_info->
Lookup(line_info,
14092 entry->value =
reinterpret_cast<void*
>(line_info);
14101 i::HashMap::Entry* entry =
14104 delete reinterpret_cast<DummyJitCodeLineInfo*
>(
event->user_data);
14111 i::HashMap::Entry* entry =
14126 i::FLAG_stress_compaction =
true;
14127 i::FLAG_incremental_marking =
false;
14128 const char* script =
14131 " for (i = 0; i < 100; ++i)"
14135 "function foo(i) { return i * i; };"
14151 jitcode_line_info = &lineinfo;
14160 const int kIterations = 10;
14161 for (
int i = 0; i < kIterations; ++i) {
14165 CompileRun(script);
14174 reinterpret_cast<i::Isolate*
>(isolate)->compilation_cache()->Clear();
14186 jitcode_line_info =
NULL;
14201 CompileRun(script);
14208 jitcode_line_info = &lineinfo;
14213 jitcode_line_info =
NULL;
14233 const int64_t kSize = 1024*1024;
14279 const char* resource_name,
14287 CHECK(!message.IsEmpty());
14288 CHECK_EQ(10 + line_offset, message->GetLineNumber());
14289 CHECK_EQ(91, message->GetStartPosition());
14290 CHECK_EQ(92, message->GetEndPosition());
14291 CHECK_EQ(2, message->GetStartColumn());
14292 CHECK_EQ(3, message->GetEndColumn());
14294 CHECK_EQ(
" throw 'nirk';", *line);
14304 "function Foo() {\n"
14308 "function Bar() {\n"
14312 "function Baz() {\n"
14318 const char* resource_name;
14320 resource_name =
"test.js";
14321 script = CompileWithOrigin(source, resource_name);
14322 CheckTryCatchSourceInfo(script, resource_name, 0);
14324 resource_name =
"test1.js";
14328 CheckTryCatchSourceInfo(script, resource_name, 0);
14330 resource_name =
"test2.js";
14335 CheckTryCatchSourceInfo(script, resource_name, 7);
14350 CHECK_EQ(1234, script0->Run()->Int32Value());
14356 static void FunctionNameCallback(
14367 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
14368 t->Set(v8_str(
"asdf"),
14370 context->
Global()->Set(v8_str(
"obj"), t->NewInstance());
14383 CHECK(date->IsDate());
14391 const char* elmv[]) {
14395 for (
int i = 0; i < elmc; i++) {
14405 const char* elmv[]) {
14409 for (
int i = 0; i < elmc; i++) {
14423 "result[1] = {a: 1, b: 2};"
14424 "result[2] = [1, 2, 3];"
14425 "var proto = {x: 1, y: 2, z: 3};"
14426 "var x = { __proto__: proto, w: 0, z: 1 };"
14432 const char** elmv0 =
NULL;
14438 const char* elmv1[] = {
"a",
"b"};
14444 const char* elmv2[] = {
"0",
"1",
"2"};
14450 const char* elmv3[] = {
"w",
"z",
"x",
"y"};
14454 const char* elmv4[] = {
"w",
"z"};
14467 "result[1] = {a: 1, b: 2};"
14468 "result[2] = [1, 2, 3];"
14469 "var proto = {x: 1, y: 2, z: 3};"
14470 "var x = { __proto__: proto, w: 0, z: 1 };"
14476 const char** elmv0 =
NULL;
14483 for (uint32_t i = 0; i < props->
Length(); i++) {
14484 printf(
"p[%d]\n", i);
14488 static bool NamedSetAccessBlocker(Local<v8::Object> obj,
14491 Local<Value> data) {
14496 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
14499 Local<Value> data) {
14508 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
14509 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
14510 IndexedSetAccessBlocker);
14511 templ->Set(v8_str(
"x"),
v8::True(isolate));
14512 Local<v8::Object> instance = templ->NewInstance();
14513 context->
Global()->Set(v8_str(
"obj"), instance);
14514 Local<Value> value = CompileRun(
"obj.x");
14515 CHECK(value->BooleanValue());
14519 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
14522 Local<Value> data) {
14527 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
14530 Local<Value> data) {
14540 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
14541 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
14542 IndexedGetAccessBlocker);
14543 templ->Set(v8_str(
"a"), v8_str(
"a"));
14548 for (
char i =
'0'; i <=
'9' ; i++) {
14550 for (
char j =
'0'; j <=
'9'; j++) {
14552 for (
char k =
'0'; k <=
'9'; k++) {
14560 Local<v8::Object> instance_1 = templ->NewInstance();
14561 context->
Global()->Set(v8_str(
"obj_1"), instance_1);
14563 Local<Value> value_1 = CompileRun(
"obj_1.a");
14564 CHECK(value_1->IsUndefined());
14566 Local<v8::Object> instance_2 = templ->NewInstance();
14567 context->
Global()->Set(v8_str(
"obj_2"), instance_2);
14569 Local<Value> value_2 = CompileRun(
"obj_2.a");
14570 CHECK(value_2->IsUndefined());
14582 IndexedSetAccessBlocker);
14585 CHECK(!internal_template->constructor()->IsUndefined());
14588 CHECK(!constructor->access_check_info()->IsUndefined());
14590 CHECK(!context0.IsEmpty());
14591 CHECK(!constructor->access_check_info()->IsUndefined());
14604 IndexedGetAccessBlocker,
14608 Context::Scope context_scope(context);
14611 context->Global()->Set(v8_str(
"a"), v8_num(1));
14612 CompileRun(
"function f1() {return a;}"
14613 "function f2() {return a;}"
14614 "function g1() {return h();}"
14615 "function g2() {return h();}"
14616 "function h() {return 1;}");
14617 Local<Function>
f1 =
14618 Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
14619 Local<Function>
f2 =
14620 Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
14621 Local<Function> g1 =
14622 Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
14623 Local<Function> g2 =
14624 Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
14625 Local<Function> h =
14626 Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
14634 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
14635 for (
int i = 0; i < 4; i++) {
14636 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
14640 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
14641 for (
int i = 0; i < 4; i++) {
14642 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
14647 context->Global()->GetPrototype());
14648 context->DetachGlobal();
14649 hidden_global->TurnOnAccessCheck();
14652 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
14653 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
14656 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
14657 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
14660 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
14664 static const char* kPropertyA =
"a";
14665 static const char* kPropertyH =
"h";
14667 static bool NamedGetAccessBlockAandH(Local<v8::Object> obj,
14670 Local<Value> data) {
14671 if (!name->IsString())
return false;
14674 return !name_handle->IsUtf8EqualTo(
i::CStrVector(kPropertyA))
14689 IndexedGetAccessBlocker,
14693 Context::Scope context_scope(context);
14696 context->Global()->Set(v8_str(
"a"), v8_num(1));
14697 static const char* source =
"function f1() {return a;}"
14698 "function f2() {return a;}"
14699 "function g1() {return h();}"
14700 "function g2() {return h();}"
14701 "function h() {return 1;}";
14703 CompileRun(source);
14704 Local<Function>
f1;
14705 Local<Function>
f2;
14706 Local<Function> g1;
14707 Local<Function> g2;
14709 f1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f1")));
14710 f2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"f2")));
14711 g1 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g1")));
14712 g2 = Local<Function>::Cast(context->Global()->Get(v8_str(
"g2")));
14713 h = Local<Function>::Cast(context->Global()->Get(v8_str(
"h")));
14721 CHECK(f1->Call(global, 0,
NULL)->Equals(v8_num(1)));
14722 for (
int i = 0; i < 4; i++) {
14723 CHECK(f2->Call(global, 0,
NULL)->Equals(v8_num(1)));
14727 CHECK(g1->Call(global, 0,
NULL)->Equals(v8_num(1)));
14728 for (
int i = 0; i < 4; i++) {
14729 CHECK(g2->Call(global, 0,
NULL)->Equals(v8_num(1)));
14735 context->Global()->GetPrototype());
14736 context->DetachGlobal();
14737 hidden_global->TurnOnAccessCheck();
14740 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
14741 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
14744 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
14745 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
14748 CHECK(h->Call(global, 0,
NULL)->Equals(v8_num(1)));
14752 CompileRun(source);
14753 f1 = Local<Function>::Cast(hidden_global->Get(v8_str(
"f1")));
14754 f2 = Local<Function>::Cast(hidden_global->Get(v8_str(
"f2")));
14755 g1 = Local<Function>::Cast(hidden_global->Get(v8_str(
"g1")));
14756 g2 = Local<Function>::Cast(hidden_global->Get(v8_str(
"g2")));
14757 CHECK(hidden_global->Get(v8_str(
"h"))->IsUndefined());
14760 CHECK(f1->Call(global, 0,
NULL)->IsUndefined());
14761 CHECK(f2->Call(global, 0,
NULL)->IsUndefined());
14764 CHECK(g1->Call(global, 0,
NULL).IsEmpty());
14765 CHECK(g2->Call(global, 0,
NULL).IsEmpty());
14777 HandleScope handle_scope(isolate);
14778 const char* script =
"function foo(a) { return a+1; }";
14791 HandleScope handle_scope(isolate);
14792 const char* script =
"function foo(a) { return 1 * * 2; }";
14803 HandleScope handle_scope(isolate);
14804 const char* script =
" The Definintive Guide";
14816 HandleScope handle_scope(isolate);
14817 const char* script =
"function foo(a) { return a+1; }";
14822 int serialized_data_length = sd->
Length();
14836 delete deserialized_sd;
14844 const char* data =
"DONT CARE";
14845 int invalid_size = 3;
14855 TEST(PreCompileInvalidPreparseDataError) {
14861 const char* script =
"function foo(){ return 5;}\n"
14862 "function bar(){ return 6 + 7;} foo();";
14868 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14869 const int kFunctionEntryStartOffset = 0;
14870 const int kFunctionEntryEndOffset = 1;
14871 unsigned* sd_data =
14872 reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
14875 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14879 String::NewFromUtf8(isolate, script),
14881 reinterpret_cast<const uint8_t*>(sd->
Data()), sd->
Length()));
14882 Local<v8::UnboundScript> compiled_script =
14886 String::Utf8Value exception_value(try_catch.
Message()->Get());
14887 CHECK_EQ(
"Uncaught SyntaxError: Invalid preparser data for function bar",
14898 sd_data =
reinterpret_cast<unsigned*
>(
const_cast<char*
>(sd->
Data()));
14899 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14902 String::NewFromUtf8(isolate, script),
14904 reinterpret_cast<const uint8_t*>(sd->
Data()), sd->
Length()));
14921 for (
int i = 0; i < 2; i++) {
14924 context->
Global()->Delete(v8_str(
"tmp"));
14925 CompileRun(
"for (var j = 0; j < 10; j++) new RegExp('');");
14928 for (
int i = 0; i < 2; i++) {
14931 context->
Global()->Delete(v8_str(
"tmp"));
14932 CompileRun(
"for (var j = 0; j < 10; j++) RegExp('')");
14946 Local<String> token = v8_str(
"<security token>");
14947 context0->SetSecurityToken(token);
14948 context1->SetSecurityToken(token);
14953 CompileRun(
"Object.prototype.x = 42; function C() {};");
14959 context1->Global()->Set(v8_str(
"other"), context0->Global());
14960 Local<Value> value = CompileRun(
"var instance = new other.C(); instance.x");
14961 CHECK(value->IsInt32());
14962 CHECK_EQ(42, value->Int32Value());
14975 "rv.alpha = 'hello';" \
14980 Local<Value> val = CompileRun(sample);
14981 CHECK(val->IsObject());
14982 Local<v8::Object> obj = val.As<
v8::Object>();
14983 obj->
Set(v8_str(
"gamma"), v8_str(
"cloneme"));
14985 CHECK_EQ(v8_str(
"hello"), obj->Get(v8_str(
"alpha")));
14987 CHECK_EQ(v8_str(
"cloneme"), obj->Get(v8_str(
"gamma")));
14990 Local<v8::Object> clone = obj->Clone();
14991 CHECK_EQ(v8_str(
"hello"), clone->Get(v8_str(
"alpha")));
14993 CHECK_EQ(v8_str(
"cloneme"), clone->Get(v8_str(
"gamma")));
15026 static void MorphAString(
i::String*
string,
15029 CHECK(i::StringShape(
string).IsExternal());
15034 string->set_map(
CcTest::heap()->external_string_map());
15042 string->set_map(
CcTest::heap()->external_ascii_string_map());
15053 char utf_buffer[129];
15054 const char* c_string =
"Now is the time for all good men"
15055 " to come to the aid of the party";
15056 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
15072 env->
Global()->Set(v8_str(
"lhs"), lhs);
15073 env->
Global()->Set(v8_str(
"rhs"), rhs);
15076 "var cons = lhs + rhs;"
15077 "var slice = lhs.substring(1, lhs.length - 1);"
15078 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);");
15080 CHECK(lhs->IsOneByte());
15081 CHECK(rhs->IsOneByte());
15087 Handle<String> cons = v8_compile(
"cons")->Run().As<String>();
15088 CHECK_EQ(128, cons->Utf8Length());
15090 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars));
15094 "Now is the time for all good men to come to the aid of the party"
15095 "Now is the time for all good men to come to the aid of the party"));
15099 "/[^a-z]/.test(cons);"
15100 "/[^a-z]/.test(slice);"
15101 "/[^a-z]/.test(slice_on_cons);");
15102 const char* expected_cons =
15103 "Now is the time for all good men to come to the aid of the party"
15104 "Now is the time for all good men to come to the aid of the party";
15105 const char* expected_slice =
15106 "ow is the time for all good men to come to the aid of the part";
15107 const char* expected_slice_on_cons =
15108 "ow is the time for all good men to come to the aid of the party"
15109 "Now is the time for all good men to come to the aid of the part";
15111 env->
Global()->Get(v8_str(
"cons")));
15113 env->
Global()->Get(v8_str(
"slice")));
15115 env->
Global()->Get(v8_str(
"slice_on_cons")));
15127 const char* ascii_sources[] = {
15135 for (
int i = 0; ascii_sources[i] !=
NULL; i++) {
15136 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]);
15145 #ifndef V8_INTERPRETED_REGEXP
15157 :
Thread(
"TimeoutThread"), isolate_(isolate) {}
15164 reinterpret_cast<i::Isolate*
>(isolate_)->stack_guard()->RequestGC();
15195 static const char* ascii_content =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
15196 i::uc16* uc16_content = AsciiToTwoByteString(ascii_content);
15205 timeout_thread.
Start();
15207 CompileRun(
"/((a*)*)*b/.exec(a)");
15210 timeout_thread.
Join();
15216 #endif // V8_INTERPRETED_REGEXP
15233 CompileRun(
"function f() { x = 42; return x; }; f()");
15236 res = CompileRun(
"function f() { eval('1'); y = 43; return y; }; f()");
15239 res = CompileRun(
"function f() { with (this) { y = 44 }; return y; }; f()");
15243 static int force_set_set_count = 0;
15244 static int force_set_get_count = 0;
15249 force_set_get_count++;
15259 force_set_set_count++;
15262 static void ForceSetInterceptSetter(
15266 force_set_set_count++;
15272 force_set_get_count = 0;
15273 force_set_set_count = 0;
15274 pass_on_get =
false;
15281 templ->
SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
15289 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
15292 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
15295 CHECK_EQ(6, global->
Get(simple_property)->Int32Value());
15300 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
15304 CHECK_EQ(3, global->
Get(access_property)->Int32Value());
15310 CHECK_EQ(8, global->
Get(access_property)->Int32Value());
15317 force_set_get_count = 0;
15318 force_set_set_count = 0;
15319 pass_on_get =
false;
15332 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
15336 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
15342 pass_on_get =
true;
15343 CHECK(global->
Get(some_property)->IsUndefined());
15349 CHECK_EQ(8, global->
Get(some_property)->Int32Value());
15354 pass_on_get =
false;
15355 CHECK_EQ(3, global->
Get(some_property)->Int32Value());
15377 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
15380 CHECK_EQ(4, global->
Get(simple_property)->Int32Value());
15383 CHECK(global->
Get(simple_property)->IsUndefined());
15387 static int force_delete_interceptor_count = 0;
15388 static bool pass_on_delete =
false;
15391 static void ForceDeleteDeleter(
15394 force_delete_interceptor_count++;
15395 if (pass_on_delete)
return;
15401 force_delete_interceptor_count = 0;
15402 pass_on_delete =
false;
15417 CHECK_EQ(0, force_delete_interceptor_count);
15419 CHECK_EQ(1, force_delete_interceptor_count);
15420 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
15423 pass_on_delete =
true;
15425 CHECK_EQ(2, force_delete_interceptor_count);
15426 CHECK_EQ(42, global->
Get(some_property)->Int32Value());
15430 CHECK(global->
Get(some_property)->IsUndefined());
15431 CHECK_EQ(2, force_delete_interceptor_count);
15441 CompileRun(
"this.__proto__ = { foo: 'horse' };"
15442 "var foo = 'fish';"
15443 "function f() { return foo.length; }");
15445 CompileRun(
"for (var i = 0; i < 4; i++) f();");
15447 CHECK_EQ(4, CompileRun(
"f()")->Int32Value());
15449 CHECK(context->
Global()->ForceDelete(v8_str(
"foo")));
15453 CHECK_EQ(5, CompileRun(
"f()")->Int32Value());
15458 i::FLAG_allow_natives_syntax =
true;
15467 CompileRun(
"var G = 42; function foo() { return G; }");
15470 ctx2->
Global()->Set(v8_str(
"o"), foo);
15472 "function f() { return o(); }"
15473 "for (var i = 0; i < 10; ++i) f();"
15474 "%OptimizeFunctionOnNextCall(f);"
15487 " return e.toString();"
15490 "ReferenceError: G is not defined");
15505 static void GetCallingContextCallback(
15531 Local<Context> calling_context0(Context::New(isolate));
15532 Local<Context> calling_context1(Context::New(isolate));
15533 Local<Context> calling_context2(Context::New(isolate));
15534 ::calling_context0 = calling_context0;
15535 ::calling_context1 = calling_context1;
15536 ::calling_context2 = calling_context2;
15539 Local<String> token = v8_str(
"<security token>");
15540 calling_context0->SetSecurityToken(token);
15541 calling_context1->SetSecurityToken(token);
15542 calling_context2->SetSecurityToken(token);
15545 calling_context0->Enter();
15546 Local<v8::FunctionTemplate> callback_templ =
15548 calling_context0->Global()->Set(v8_str(
"callback"),
15549 callback_templ->GetFunction());
15550 calling_context0->Exit();
15554 calling_context1->Enter();
15555 calling_context1->Global()->Set(v8_str(
"context0"),
15556 calling_context0->Global());
15557 CompileRun(
"function f() { context0.callback() }");
15558 calling_context1->Exit();
15562 calling_context2->Enter();
15563 calling_context2->Global()->Set(v8_str(
"context1"),
15564 calling_context1->Global());
15565 CompileRun(
"context1.f()");
15566 calling_context2->Exit();
15567 ::calling_context0.Clear();
15568 ::calling_context1.Clear();
15569 ::calling_context2.Clear();
15579 CompileRun(
"__proto__.x = 42");
15602 obj_clone->
Set(foo_string,
15604 CHECK(!obj->
Get(foo_string)->IsUndefined());
15608 static void CheckElementValue(
i::Isolate* isolate,
15622 const int kElementCount = 260;
15623 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
15631 for (
int i = 0; i < kElementCount; i++) {
15632 pixels->set(i, i % 256);
15636 for (
int i = 0; i < kElementCount; i++) {
15637 CHECK_EQ(i % 256, pixels->get_scalar(i));
15646 CheckElementValue(isolate, 1, jsobj, 1);
15648 context->
Global()->Set(v8_str(
"pixels"), obj);
15651 result = CompileRun(
"pixels[1]");
15652 CHECK_EQ(1, result->Int32Value());
15654 result = CompileRun(
"var sum = 0;"
15655 "for (var i = 0; i < 8; i++) {"
15656 " sum += pixels[i] = pixels[i] = -i;"
15659 CHECK_EQ(-28, result->Int32Value());
15661 result = CompileRun(
"var sum = 0;"
15662 "for (var i = 0; i < 8; i++) {"
15663 " sum += pixels[i] = pixels[i] = 0;"
15666 CHECK_EQ(0, result->Int32Value());
15668 result = CompileRun(
"var sum = 0;"
15669 "for (var i = 0; i < 8; i++) {"
15670 " sum += pixels[i] = pixels[i] = 255;"
15673 CHECK_EQ(8 * 255, result->Int32Value());
15675 result = CompileRun(
"var sum = 0;"
15676 "for (var i = 0; i < 8; i++) {"
15677 " sum += pixels[i] = pixels[i] = 256 + i;"
15680 CHECK_EQ(2076, result->Int32Value());
15682 result = CompileRun(
"var sum = 0;"
15683 "for (var i = 0; i < 8; i++) {"
15684 " sum += pixels[i] = pixels[i] = i;"
15687 CHECK_EQ(28, result->Int32Value());
15689 result = CompileRun(
"var sum = 0;"
15690 "for (var i = 0; i < 8; i++) {"
15691 " sum += pixels[i];"
15694 CHECK_EQ(28, result->Int32Value());
15697 reinterpret_cast<i::Isolate*>(context->
GetIsolate()));
15701 i::USE(no_failure);
15702 CheckElementValue(isolate, 2, jsobj, 1);
15706 i::USE(no_failure);
15707 CheckElementValue(isolate, 255, jsobj, 1);
15711 i::USE(no_failure);
15712 CheckElementValue(isolate, 0, jsobj, 1);
15714 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15715 " pixels[i] = (i * 65) - 109;"
15717 "pixels[1] + pixels[6];");
15718 CHECK_EQ(255, result->Int32Value());
15719 CheckElementValue(isolate, 0, jsobj, 0);
15720 CheckElementValue(isolate, 0, jsobj, 1);
15721 CheckElementValue(isolate, 21, jsobj, 2);
15722 CheckElementValue(isolate, 86, jsobj, 3);
15723 CheckElementValue(isolate, 151, jsobj, 4);
15724 CheckElementValue(isolate, 216, jsobj, 5);
15725 CheckElementValue(isolate, 255, jsobj, 6);
15726 CheckElementValue(isolate, 255, jsobj, 7);
15727 result = CompileRun(
"var sum = 0;"
15728 "for (var i = 0; i < 8; i++) {"
15729 " sum += pixels[i];"
15732 CHECK_EQ(984, result->Int32Value());
15734 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15735 " pixels[i] = (i * 1.1);"
15737 "pixels[1] + pixels[6];");
15738 CHECK_EQ(8, result->Int32Value());
15739 CheckElementValue(isolate, 0, jsobj, 0);
15740 CheckElementValue(isolate, 1, jsobj, 1);
15741 CheckElementValue(isolate, 2, jsobj, 2);
15742 CheckElementValue(isolate, 3, jsobj, 3);
15743 CheckElementValue(isolate, 4, jsobj, 4);
15744 CheckElementValue(isolate, 6, jsobj, 5);
15745 CheckElementValue(isolate, 7, jsobj, 6);
15746 CheckElementValue(isolate, 8, jsobj, 7);
15748 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15749 " pixels[7] = undefined;"
15752 CHECK_EQ(0, result->Int32Value());
15753 CheckElementValue(isolate, 0, jsobj, 7);
15755 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15756 " pixels[6] = '2.3';"
15759 CHECK_EQ(2, result->Int32Value());
15760 CheckElementValue(isolate, 2, jsobj, 6);
15762 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15763 " pixels[5] = NaN;"
15766 CHECK_EQ(0, result->Int32Value());
15767 CheckElementValue(isolate, 0, jsobj, 5);
15769 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15770 " pixels[8] = Infinity;"
15773 CHECK_EQ(255, result->Int32Value());
15774 CheckElementValue(isolate, 255, jsobj, 8);
15776 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
15777 " pixels[9] = -Infinity;"
15780 CHECK_EQ(0, result->Int32Value());
15781 CheckElementValue(isolate, 0, jsobj, 9);
15783 result = CompileRun(
"pixels[3] = 33;"
15784 "delete pixels[3];"
15786 CHECK_EQ(33, result->Int32Value());
15788 result = CompileRun(
"pixels[0] = 10; pixels[1] = 11;"
15789 "pixels[2] = 12; pixels[3] = 13;"
15790 "pixels.__defineGetter__('2',"
15791 "function() { return 120; });"
15793 CHECK_EQ(12, result->Int32Value());
15795 result = CompileRun(
"var js_array = new Array(40);"
15796 "js_array[0] = 77;"
15800 result = CompileRun(
"pixels[1] = 23;"
15801 "pixels.__proto__ = [];"
15802 "js_array.__proto__ = pixels;"
15803 "js_array.concat(pixels);");
15807 result = CompileRun(
"pixels[1] = 23;");
15808 CHECK_EQ(23, result->Int32Value());
15812 result = CompileRun(
"pixels[256] = 255;");
15813 CHECK_EQ(255, result->Int32Value());
15814 result = CompileRun(
"var i = 0;"
15815 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
15817 CHECK_EQ(255, result->Int32Value());
15821 result = CompileRun(
"function pa_load(p) {"
15823 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
15826 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15827 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
15828 "just_ints = new Object();"
15829 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
15830 "for (var i = 0; i < 10; ++i) {"
15831 " result = pa_load(just_ints);"
15834 CHECK_EQ(32640, result->Int32Value());
15837 result = CompileRun(
"function pa_load(p, start) {"
15839 " for (var j = start; j < 256; j++) { sum += p[j]; }"
15842 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15843 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
15844 "for (var i = 0; i < 10; ++i) {"
15845 " result = pa_load(pixels,-10);"
15848 CHECK_EQ(0, result->Int32Value());
15851 result = CompileRun(
"function pa_load(p) {"
15853 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
15856 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15857 "just_ints = new Object();"
15858 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
15859 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
15860 "for (var i = 0; i < 10; ++i) {"
15861 " result = pa_load(pixels);"
15864 CHECK_EQ(32640, result->Int32Value());
15868 result = CompileRun(
"function pa_load(p, start) {"
15870 " for (var j = start; j < 256; j++) { sum += p[j]; }"
15873 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15874 "just_ints = new Object();"
15875 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
15876 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
15877 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
15878 "for (var i = 0; i < 10; ++i) {"
15879 " result = pa_load(pixels,-10);"
15882 CHECK_EQ(0, result->Int32Value());
15887 result = CompileRun(
"function pa_load(p) {"
15889 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
15892 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15893 "just_ints = new Object();"
15894 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
15895 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
15896 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
15897 "sparse_array = new Object();"
15898 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
15899 "sparse_array[1000000] = 3;"
15900 "for (var i = 0; i < 10; ++i) {"
15901 " result = pa_load(sparse_array);"
15904 CHECK_EQ(32640, result->Int32Value());
15907 result = CompileRun(
"function pa_store(p) {"
15908 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
15910 "pa_store(pixels);"
15912 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
15914 CHECK_EQ(48896, result->Int32Value());
15918 result = CompileRun(
"function pa_store(p,start) {"
15919 " for (var j = 0; j < 256; j++) {"
15920 " p[j+start] = j * 2;"
15923 "pa_store(pixels,0);"
15924 "pa_store(pixels,-128);"
15926 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
15928 CHECK_EQ(65280, result->Int32Value());
15932 result = CompileRun(
"function pa_store(p,start) {"
15933 " for (var j = 0; j < 256; j++) {"
15934 " p[j+start] = j * 2;"
15937 "pa_store(pixels,0);"
15938 "just_ints = new Object();"
15939 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
15940 "pa_store(just_ints, 0);"
15941 "pa_store(pixels,-128);"
15943 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
15945 CHECK_EQ(65280, result->Int32Value());
15949 result = CompileRun(
"function pa_store(p) {"
15950 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
15952 "pa_store(pixels);"
15953 "just_ints = new Object();"
15954 "pa_store(just_ints);"
15955 "pa_store(pixels);"
15957 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
15959 CHECK_EQ(48896, result->Int32Value());
15962 result = CompileRun(
"function pa_load(p) {"
15964 " for (var i=0; i<256; ++i) {"
15969 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
15970 "for (var i = 0; i < 5000; ++i) {"
15971 " result = pa_load(pixels);"
15974 CHECK_EQ(32640, result->Int32Value());
15977 result = CompileRun(
"function pa_init(p) {"
15978 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
15980 "function pa_load(p) {"
15982 " for (var i=0; i<256; ++i) {"
15987 "for (var i = 0; i < 5000; ++i) {"
15988 " pa_init(pixels);"
15990 "result = pa_load(pixels);"
15992 CHECK_EQ(32640, result->Int32Value());
16002 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(
size));
16013 static void NotHandledIndexedPropertyGetter(
16020 static void NotHandledIndexedPropertySetter(
16022 Local<Value> value,
16033 const int kElementCount = 260;
16034 uint8_t* pixel_data =
reinterpret_cast<uint8_t*
>(malloc(kElementCount));
16040 for (
int i = 0; i < kElementCount; i++) {
16041 pixels->set(i, i % 256);
16046 NotHandledIndexedPropertySetter);
16049 context->
Global()->Set(v8_str(
"pixels"), obj);
16052 result = CompileRun(
"var sum = 0;"
16053 "for (var i = 0; i < 8; i++) {"
16054 " sum += pixels[i] = pixels[i] = -i;"
16057 CHECK_EQ(-28, result->Int32Value());
16058 result = CompileRun(
"pixels.hasOwnProperty('1')");
16059 CHECK(result->BooleanValue());
16065 switch (array_type) {
16092 template <
class ExternalArrayClass,
class ElementType>
16093 static void ObjectWithExternalArrayTestHelper(
16094 Handle<Context> context,
16098 int64_t low, int64_t high) {
16101 obj->
Set(v8_str(
"field"),
16103 context->Global()->Set(v8_str(
"ext_array"), obj);
16106 result = CompileRun(
"ext_array[1]");
16107 CHECK_EQ(1, result->Int32Value());
16110 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16111 " ext_array[i] = i;"
16114 "for (var i = 0; i < 8; i++) {"
16115 " sum += ext_array[i];"
16119 CHECK_EQ(28, result->Int32Value());
16121 result = CompileRun(
"var sum = 0;"
16122 "for (var i = 0; i < 8; i++) {"
16123 " sum += ext_array[i] = ext_array[i] = -i;"
16126 CHECK_EQ(-28, result->Int32Value());
16130 result = CompileRun(
"for (var i = 8; --i >= 0; ) {"
16131 " ext_array[i] = i;"
16134 "for (var i = 0; i < 8; i++) {"
16135 " sum += ext_array[i];"
16138 CHECK_EQ(28, result->Int32Value());
16141 result = CompileRun(
"var sum = 0;"
16142 "for (var i = 0; i < 16; i+=2) {"
16143 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);"
16146 CHECK_EQ(-28, result->Int32Value());
16149 result = CompileRun(
"for (var i = 0; i < 16; i+=2) {"
16150 " ext_array[i] = (i * 0.5);"
16153 "for (var i = 0; i < 16; i+=2) {"
16154 " sum += ext_array[i];"
16157 CHECK_EQ(28, result->Int32Value());
16160 result = CompileRun(
"for (var i = 14; i >= 0; i-=2) {"
16161 " ext_array[i] = (i * 0.5);"
16164 "for (var i = 0; i < 16; i+=2) {"
16165 " sum += ext_array[i];"
16168 CHECK_EQ(28, result->Int32Value());
16174 const char* boundary_program =
16176 "for (var i = 0; i < 16; i++) {"
16177 " ext_array[i] = %lld;"
16179 " res = ext_array[i];"
16186 result = CompileRun(test_buf.start());
16187 CHECK_EQ(low, result->IntegerValue());
16192 result = CompileRun(test_buf.start());
16193 CHECK_EQ(high, result->IntegerValue());
16196 result = CompileRun(
"var tmp_array = ext_array;"
16198 "for (var i = 0; i < 8; i++) {"
16199 " tmp_array[i] = i;"
16200 " sum += tmp_array[i];"
16208 CHECK_EQ(28, result->Int32Value());
16212 "var caught_exception = false;"
16216 " caught_exception = true;"
16218 "caught_exception;",
16220 result = CompileRun(test_buf.start());
16221 CHECK_EQ(
false, result->BooleanValue());
16225 "var caught_exception = false;"
16227 " ext_array[%d] = 1;"
16229 " caught_exception = true;"
16231 "caught_exception;",
16233 result = CompileRun(test_buf.start());
16234 CHECK_EQ(
false, result->BooleanValue());
16237 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16238 " ext_array[7] = undefined;"
16241 CHECK_EQ(0, result->Int32Value());
16248 CheckElementValue(isolate, 0, jsobj, 7);
16251 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16252 " ext_array[6] = '2.3';"
16255 CHECK_EQ(2, result->Int32Value());
16264 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16265 " ext_array[i] = 5;"
16267 "for (var i = 0; i < 8; i++) {"
16268 " ext_array[i] = NaN;"
16271 CHECK_EQ(0, result->Int32Value());
16272 CheckElementValue(isolate, 0, jsobj, 5);
16274 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16275 " ext_array[i] = 5;"
16277 "for (var i = 0; i < 8; i++) {"
16278 " ext_array[i] = Infinity;"
16281 int expected_value =
16283 CHECK_EQ(expected_value, result->Int32Value());
16284 CheckElementValue(isolate, expected_value, jsobj, 5);
16286 result = CompileRun(
"for (var i = 0; i < 8; i++) {"
16287 " ext_array[i] = 5;"
16289 "for (var i = 0; i < 8; i++) {"
16290 " ext_array[i] = -Infinity;"
16293 CHECK_EQ(0, result->Int32Value());
16294 CheckElementValue(isolate, 0, jsobj, 5);
16297 const char* unsigned_data =
16298 "var source_data = [0.6, 10.6];"
16299 "var expected_results = [0, 10];";
16300 const char* signed_data =
16301 "var source_data = [0.6, 10.6, -0.6, -10.6];"
16302 "var expected_results = [0, 10, 0, -10];";
16303 const char* pixel_data =
16304 "var source_data = [0.6, 10.6];"
16305 "var expected_results = [1, 11];";
16314 "var all_passed = true;"
16315 "for (var i = 0; i < source_data.length; i++) {"
16316 " for (var j = 0; j < 8; j++) {"
16317 " ext_array[j] = source_data[i];"
16319 " all_passed = all_passed &&"
16320 " (ext_array[5] == expected_results[i]);"
16325 (is_pixel_data ? pixel_data : signed_data)));
16326 result = CompileRun(test_buf.start());
16327 CHECK_EQ(
true, result->BooleanValue());
16331 ExternalArrayClass::cast(jsobj->elements()));
16332 for (
int i = 0; i < element_count; i++) {
16333 array->set(i, static_cast<ElementType>(i));
16337 result = CompileRun(
"function ee_op_test_complex_func(sum) {"
16338 " for (var i = 0; i < 40; ++i) {"
16339 " sum += (ext_array[i] += 1);"
16340 " sum += (ext_array[i] -= 1);"
16345 "for (var i=0;i<10000;++i) {"
16346 " sum=ee_op_test_complex_func(sum);"
16349 CHECK_EQ(16000000, result->Int32Value());
16352 result = CompileRun(
"function ee_op_test_count_func(sum) {"
16353 " for (var i = 0; i < 40; ++i) {"
16354 " sum += (++ext_array[i]);"
16355 " sum += (--ext_array[i]);"
16360 "for (var i=0;i<10000;++i) {"
16361 " sum=ee_op_test_count_func(sum);"
16364 CHECK_EQ(16000000, result->Int32Value());
16366 result = CompileRun(
"ext_array[3] = 33;"
16367 "delete ext_array[3];"
16369 CHECK_EQ(33, result->Int32Value());
16371 result = CompileRun(
"ext_array[0] = 10; ext_array[1] = 11;"
16372 "ext_array[2] = 12; ext_array[3] = 13;"
16373 "ext_array.__defineGetter__('2',"
16374 "function() { return 120; });"
16376 CHECK_EQ(12, result->Int32Value());
16378 result = CompileRun(
"var js_array = new Array(40);"
16379 "js_array[0] = 77;"
16383 result = CompileRun(
"ext_array[1] = 23;"
16384 "ext_array.__proto__ = [];"
16385 "js_array.__proto__ = ext_array;"
16386 "js_array.concat(ext_array);");
16390 result = CompileRun(
"ext_array[1] = 23;");
16391 CHECK_EQ(23, result->Int32Value());
16395 template <
class FixedTypedArrayClass,
16398 static void FixedTypedArrayTestHelper(
16401 ElementType high) {
16402 i::FLAG_allow_natives_syntax =
true;
16407 const int kElementCount = 260;
16411 CHECK_EQ(FixedTypedArrayClass::kInstanceType,
16412 fixed_array->map()->instance_type());
16413 CHECK_EQ(kElementCount, fixed_array->length());
16415 for (
int i = 0; i < kElementCount; i++) {
16416 fixed_array->set(i, static_cast<ElementType>(i));
16420 for (
int i = 0; i < kElementCount; i++) {
16421 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)),
16422 static_cast<int64_t>(fixed_array->get_scalar(i)));
16428 jsobj->set_map(*fixed_array_map);
16429 jsobj->set_elements(*fixed_array);
16431 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>(
16432 context.
local(),
obj, kElementCount, array_type,
16433 static_cast<int64_t
>(low),
16434 static_cast<int64_t>(high));
16439 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>(
16446 FixedTypedArrayTestHelper<i::FixedUint8ClampedArray,
16454 FixedTypedArrayTestHelper<i::FixedInt8Array, i::INT8_ELEMENTS, int8_t>(
16461 FixedTypedArrayTestHelper<i::FixedUint16Array, i::UINT16_ELEMENTS, uint16_t>(
16468 FixedTypedArrayTestHelper<i::FixedInt16Array, i::INT16_ELEMENTS, int16_t>(
16475 FixedTypedArrayTestHelper<i::FixedUint32Array, i::UINT32_ELEMENTS, uint32_t>(
16482 FixedTypedArrayTestHelper<i::FixedInt32Array, i::INT32_ELEMENTS, int32_t>(
16489 FixedTypedArrayTestHelper<i::FixedFloat32Array, i::FLOAT32_ELEMENTS, float>(
16496 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>(
16502 template <
class ExternalArrayClass,
class ElementType>
16510 const int kElementCount = 40;
16511 int element_size = ExternalArrayElementSize(array_type);
16512 ElementType* array_data =
16513 static_cast<ElementType*
>(malloc(kElementCount * element_size));
16519 for (
int i = 0; i < kElementCount; i++) {
16520 array->set(i, static_cast<ElementType>(i));
16524 for (
int i = 0; i < kElementCount; i++) {
16526 static_cast<int64_t>(array->get_scalar(i)));
16527 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
16540 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
16541 context.
local(),
obj, kElementCount, array_type, low, high);
16550 const int kXSize = 300;
16551 const int kYSize = 300;
16552 const int kLargeElementCount = kXSize * kYSize * 4;
16553 ElementType* large_array_data =
16554 static_cast<ElementType*
>(malloc(kLargeElementCount * element_size));
16559 kLargeElementCount);
16560 context->
Global()->Set(v8_str(
"large_array"), large_obj);
16562 for (
int x = 0; x < 300; x++) {
16564 int offset = row * 300 * 4;
16565 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
16566 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
16567 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
16568 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
16570 offset = row * 300 * 4;
16571 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
16572 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
16573 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
16574 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
16576 offset = row * 300 * 4;
16577 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
16578 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
16579 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
16580 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
16586 result = CompileRun(
"var failed = false;"
16588 "for (var i = 0; i < 300; i++) {"
16589 " if (large_array[4 * i] != 127 ||"
16590 " large_array[4 * i + 1] != 0 ||"
16591 " large_array[4 * i + 2] != 0 ||"
16592 " large_array[4 * i + 3] != 127) {"
16596 "offset = 150 * 300 * 4;"
16597 "for (var i = 0; i < 300; i++) {"
16598 " if (large_array[offset + 4 * i] != 127 ||"
16599 " large_array[offset + 4 * i + 1] != 0 ||"
16600 " large_array[offset + 4 * i + 2] != 0 ||"
16601 " large_array[offset + 4 * i + 3] != 127) {"
16605 "offset = 298 * 300 * 4;"
16606 "for (var i = 0; i < 300; i++) {"
16607 " if (large_array[offset + 4 * i] != 127 ||"
16608 " large_array[offset + 4 * i + 1] != 0 ||"
16609 " large_array[offset + 4 * i + 2] != 0 ||"
16610 " large_array[offset + 4 * i + 3] != 127) {"
16615 CHECK_EQ(
true, result->BooleanValue());
16616 free(large_array_data);
16623 result = CompileRun(
"ext_array[''] = 23; ext_array['']");
16624 CHECK_EQ(23, result->Int32Value());
16629 obj2->
Set(v8_str(
"ee_test_field"),
16636 context->
Global()->Set(v8_str(
"ext_array"), obj2);
16637 result = CompileRun(
"ext_array['']");
16638 CHECK_EQ(1503, result->Int32Value());
16644 obj2->
Set(v8_str(
"ee_test_field_2"),
16651 context->
Global()->Set(v8_str(
"ext_array"), obj2);
16652 result = CompileRun(
"ext_array['']");
16653 CHECK_EQ(1503, result->Int32Value());
16659 obj2->
Set(v8_str(
"ee_test_field_2"),
16666 context->
Global()->Set(v8_str(
"ext_array"), obj2);
16667 result = CompileRun(
"ext_array['']");
16675 obj2->
Set(v8_str(
"ee_test_field3"),
16679 context->
Global()->Set(v8_str(
"ext_array"), obj2);
16680 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
16681 "ext_array['']();");
16686 obj3->
Set(v8_str(
"ee_test_field3"),
16691 context->
Global()->Set(v8_str(
"ext_array"), obj3);
16699 obj3->
Set(v8_str(
"ee_test_field4"),
16708 obj2->
Set(v8_str(
"ee_test_field4"),
16710 context->
Global()->Set(v8_str(
"ext_array"), obj2);
16711 result = CompileRun(
"ext_array[''] = function() {return 1503;};"
16712 "ext_array['']();");
16720 ExternalArrayTestHelper<i::ExternalInt8Array, int8_t>(
16728 ExternalArrayTestHelper<i::ExternalUint8Array, uint8_t>(
16736 ExternalArrayTestHelper<i::ExternalUint8ClampedArray, uint8_t>(
16744 ExternalArrayTestHelper<i::ExternalInt16Array, int16_t>(
16752 ExternalArrayTestHelper<i::ExternalUint16Array, uint16_t>(
16760 ExternalArrayTestHelper<i::ExternalInt32Array, int32_t>(
16768 ExternalArrayTestHelper<i::ExternalUint32Array, uint32_t>(
16776 ExternalArrayTestHelper<i::ExternalFloat32Array, float>(
16784 ExternalArrayTestHelper<i::ExternalFloat64Array, double>(
16792 TestExternalInt8Array();
16793 TestExternalUint8Array();
16794 TestExternalInt16Array();
16795 TestExternalUint16Array();
16796 TestExternalInt32Array();
16797 TestExternalUint32Array();
16798 TestExternalFloat32Array();
16806 int element_size = ExternalArrayElementSize(array_type);
16807 void* external_data = malloc(
size * element_size);
16810 external_data, array_type,
size);
16815 free(external_data);
16838 last_location = last_message =
NULL;
16871 template <
typename ElementType,
typename TypedArray,
16872 class ExternalArrayClass>
16874 int64_t low, int64_t high) {
16875 const int kElementCount = 50;
16883 Local<v8::ArrayBuffer> ab =
16885 (kElementCount + 2) *
sizeof(ElementType));
16886 Local<TypedArray> ta =
16887 TypedArray::New(ab, 2*
sizeof(ElementType), kElementCount);
16888 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
16889 CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
16890 CHECK_EQ(2*
sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
16891 CHECK_EQ(kElementCount*
sizeof(ElementType),
16892 static_cast<int>(ta->ByteLength()));
16895 ElementType* data = backing_store.
start() + 2;
16896 for (
int i = 0; i < kElementCount; i++) {
16897 data[i] =
static_cast<ElementType
>(i);
16900 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
16901 env.
local(), ta, kElementCount, array_type, low, high);
16906 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array>(
16912 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array>(
16926 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array>(
16932 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array>(
16938 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array>(
16944 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array>(
16950 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array>(
16963 const int kSize = 50;
16971 Local<v8::ArrayBuffer> ab =
16973 Local<v8::DataView> dv =
16975 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
16976 CHECK_EQ(2, static_cast<int>(dv->ByteOffset()));
16977 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
16982 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
16983 THREADED_TEST(Is##View) { \
16984 LocalContext env; \
16985 v8::Isolate* isolate = env->GetIsolate(); \
16986 v8::HandleScope handle_scope(isolate); \
16988 Handle<Value> result = CompileRun( \
16989 "var ab = new ArrayBuffer(128);" \
16990 "new " #View "(ab)"); \
16991 CHECK(result->IsArrayBufferView()); \
16992 CHECK(result->Is##View()); \
16993 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \
17007 #undef IS_ARRAY_BUFFER_VIEW_TEST
17014 const char *source =
"foo";
17036 const char *source =
"function foo() { FAIL.FAIL; }; foo();";
17043 ->BindToCurrentContext()
17045 CHECK(try_catch.HasCaught());
17047 CHECK(strstr(*stack,
"at foo (stack-trace-test") !=
NULL);
17053 const char* expected_func_name,
int expected_line_number,
17054 int expected_column,
bool is_eval,
bool is_constructor,
17059 if (*script_name ==
NULL) {
17063 CHECK(strstr(*script_name, expected_script_name) !=
NULL);
17065 CHECK(strstr(*func_name, expected_func_name) !=
NULL);
17075 const char* origin =
"capture-stack-trace-test";
17076 const int kOverviewTest = 1;
17077 const int kDetailedTest = 2;
17081 int testGroup = args[0]->Int32Value();
17082 if (testGroup == kOverviewTest) {
17098 }
else if (testGroup == kDetailedTest) {
17106 #ifdef ENABLE_DEBUGGER_SUPPORT
17107 bool is_eval =
true;
17108 #else // ENABLE_DEBUGGER_SUPPORT
17109 bool is_eval =
false;
17110 #endif // ENABLE_DEBUGGER_SUPPORT
17132 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17133 templ->Set(v8_str(
"AnalyzeStackInNativeCode"),
17139 const char *overview_source =
17140 "function bar() {\n"
17141 " var y; AnalyzeStackInNativeCode(1);\n"
17143 "function foo() {\n"
17147 "var x;eval('new foo();');";
17154 ->BindToCurrentContext()
17160 const char *detailed_source =
17161 "function bat() {AnalyzeStackInNativeCode(2);\n"
17164 "function baz() {\n"
17167 "eval('new baz();');";
17179 CHECK(!detailed_result.IsEmpty());
17180 CHECK(detailed_result->IsObject());
17184 static void StackTraceForUncaughtExceptionListener(
17196 TEST(CaptureStackTraceForUncaughtException) {
17203 CompileRunWithOrigin(
17204 "function foo() {\n"
17207 "function bar() {\n"
17212 Local<Value> trouble = global->
Get(v8_str(
"bar"));
17213 CHECK(trouble->IsFunction());
17214 Function::Cast(*trouble)->Call(global, 0,
NULL);
17220 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
17228 "var setters = ['column', 'lineNumber', 'scriptName',\n"
17229 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
17230 " 'isConstructor'];\n"
17231 "for (var i = 0; i < setters.length; i++) {\n"
17232 " var prop = setters[i];\n"
17233 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n"
17235 CompileRun(
"throw 'exception';");
17247 int line_number[] = {1, 2, 5};
17248 for (
int i = 0; i < frame_count; i++) {
17263 const char* source =
17264 "function g() { error; } \n"
17265 "function f() { g(); } \n"
17266 "function t(e) { throw e; } \n"
17269 "} catch (e1) { \n"
17272 " } catch (e2) { \n"
17278 CompileRun(source);
17290 int line_number[] = {3, 7};
17291 for (
int i = 0; i < frame_count; i++) {
17303 const char* source =
17304 "function g() { throw 404; } \n"
17305 "function f() { g(); } \n"
17306 "function t(e) { throw e; } \n"
17309 "} catch (e1) { \n"
17314 CompileRun(source);
17335 const char* source =
17336 "var e = new Error(); \n"
17340 CompileRun(source);
17360 const char* source =
17361 "var e = {__proto__: new Error()} \n"
17365 CompileRun(source);
17376 CHECK_EQ(5, stackTrace->GetFrameCount());
17378 for (
int i = 0; i < 3; i++) {
17380 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17390 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17391 templ->Set(v8_str(
"AnalyzeStackOfEvalWithSourceURL"),
17396 const char *source =
17397 "function outer() {\n"
17398 "function bar() {\n"
17399 " AnalyzeStackOfEvalWithSourceURL();\n"
17401 "function foo() {\n"
17407 "eval('(' + outer +')()%s');";
17411 CHECK(CompileRun(code.
start())->IsUndefined());
17413 CHECK(CompileRun(code.
start())->IsUndefined());
17417 static int scriptIdInStack[2];
17424 CHECK_EQ(2, stackTrace->GetFrameCount());
17425 for (
int i = 0; i < 2; i++) {
17426 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
17434 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17435 templ->Set(v8_str(
"AnalyzeScriptIdInStack"),
17441 "function foo() {\n"
17442 " AnalyzeScriptIdInStack();"
17447 for (
int i = 0; i < 2; i++) {
17459 CHECK_EQ(4, stackTrace->GetFrameCount());
17461 for (
int i = 0; i < 3; i++) {
17463 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17470 TEST(InlineScriptWithSourceURLInStackTrace) {
17473 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17474 templ->Set(v8_str(
"AnalyzeStackOfInlineScriptWithSourceURL"),
17479 const char *source =
17480 "function outer() {\n"
17481 "function bar() {\n"
17482 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
17484 "function foo() {\n"
17494 CHECK(CompileRunWithOrigin(code.
start(),
"url", 0, 1)->IsUndefined());
17496 CHECK(CompileRunWithOrigin(code.
start(),
"url", 0, 1)->IsUndefined());
17505 CHECK_EQ(4, stackTrace->GetFrameCount());
17507 for (
int i = 0; i < 3; i++) {
17509 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
17516 TEST(DynamicWithSourceURLInStackTrace) {
17519 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17520 templ->Set(v8_str(
"AnalyzeStackOfDynamicScriptWithSourceURL"),
17525 const char *source =
17526 "function outer() {\n"
17527 "function bar() {\n"
17528 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
17530 "function foo() {\n"
17540 CHECK(CompileRunWithOrigin(code.
start(),
"url", 0, 0)->IsUndefined());
17542 CHECK(CompileRunWithOrigin(code.
start(),
"url", 0, 0)->IsUndefined());
17546 TEST(DynamicWithSourceURLInStackTraceString) {
17550 const char *source =
17551 "function outer() {\n"
17552 " function foo() {\n"
17562 CompileRunWithOrigin(code.
start(),
"", 0, 0);
17565 CHECK(strstr(*stack,
"at foo (source_url:3:5)") !=
NULL);
17569 static void CreateGarbageInOldSpace() {
17573 for (
int i = 0; i < 1000; i++) {
17581 const intptr_t
MB = 1024 * 1024;
17585 CreateGarbageInOldSpace();
17587 CHECK_GT(size_with_garbage, initial_size + MB);
17588 bool finished =
false;
17589 for (
int i = 0; i < 200 && !finished; i++) {
17594 CHECK_LT(final_size, initial_size + 1);
17600 const intptr_t
MB = 1024 * 1024;
17601 const int IdlePauseInMs = 900;
17605 CreateGarbageInOldSpace();
17607 CHECK_GT(size_with_garbage, initial_size + MB);
17608 bool finished =
false;
17609 for (
int i = 0; i < 200 && !finished; i++) {
17614 CHECK_LT(final_size, initial_size + 1);
17620 const intptr_t
MB = 1024 * 1024;
17621 const int IdlePauseInMs = 900;
17625 CreateGarbageInOldSpace();
17627 CHECK_GT(size_with_garbage, initial_size + MB);
17628 bool finished =
false;
17629 for (
int i = 0; i < 200 && !finished; i++) {
17634 CHECK_LT(final_size, initial_size + 1);
17639 const intptr_t
MB = 1024 * 1024;
17640 const int kShortIdlePauseInMs = 100;
17641 const int kLongIdlePauseInMs = 1000;
17649 for (
int i = 0; i < 7; i++) {
17654 CreateGarbageInOldSpace();
17661 CreateGarbageInOldSpace();
17663 CHECK_GT(size_with_garbage, initial_size + MB);
17664 bool finished =
false;
17665 for (
int i = 0; i < 200 && !finished; i++) {
17669 CHECK_LT(final_size, initial_size + 1);
17675 for (
int i = 0; i < 3; i++) {
17680 static uint32_t* stack_limit;
17682 static void GetStackLimitCallback(
17684 stack_limit =
reinterpret_cast<uint32_t*
>(
17692 static uint32_t* ComputeStackLimit(uint32_t
size) {
17693 uint32_t* answer = &size - (size /
sizeof(
size));
17698 if (answer > &
size)
return reinterpret_cast<uint32_t*
>(
sizeof(
size));
17704 static const int stack_breathing_room = 256 *
i::KB;
17708 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room);
17718 Local<v8::FunctionTemplate> fun_templ =
17720 Local<Function> fun = fun_templ->GetFunction();
17721 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
17722 CompileRun(
"get_stack_limit();");
17724 CHECK(stack_limit == set_limit);
17729 uint32_t* set_limit;
17732 set_limit = ComputeStackLimit(stack_breathing_room);
17742 Local<v8::FunctionTemplate> fun_templ =
17744 Local<Function> fun = fun_templ->GetFunction();
17745 env->
Global()->Set(v8_str(
"get_stack_limit"), fun);
17746 CompileRun(
"get_stack_limit();");
17748 CHECK(stack_limit == set_limit);
17752 CHECK(stack_limit == set_limit);
17761 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
17762 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
17764 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
17765 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
17772 for (
int i = 0; i < 4; i++) {
17773 resource_[i] = resource[i];
17774 found_resource_[i] =
false;
17784 string->GetExternalStringResource();
17786 for (
int i = 0; i < 4; i++) {
17787 if (resource_[i] == resource) {
17788 CHECK(!found_resource_[i]);
17789 found_resource_[i] =
true;
17794 for (
int i = 0; i < 4; i++) {
17795 CHECK(found_resource_[i]);
17801 bool found_resource_[4];
17809 CompileRun(
"'Romeo Montague ' + 'Juliet Capulet'")->ToString();
17816 AsciiToTwoByteString(
"Romeo Montague Juliet Capulet"));
17817 cons->MakeExternal(resource);
17819 CHECK(cons->IsExternal());
17820 CHECK_EQ(resource, cons->GetExternalStringResource());
17821 String::Encoding encoding;
17822 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding));
17823 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
17831 CompileRun(
"'Romeo Montague ' + 'Juliet Capulet'")->ToString();
17839 cons->MakeExternal(resource);
17841 CHECK(cons->IsExternalAscii());
17842 CHECK_EQ(resource, cons->GetExternalAsciiStringResource());
17843 String::Encoding encoding;
17844 CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding));
17845 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding);
17852 const char*
string =
"Some string";
17853 uint16_t* two_byte_string = AsciiToTwoByteString(
string);
17866 CHECK(string2->MakeExternal(resource[2]));
17869 resource[3] =
new TestResource(AsciiToTwoByteString(
"Some other string"));
17876 CHECK(string3_i->IsInternalizedString());
17879 CHECK(string0->IsExternal());
17880 CHECK(string1->IsExternal());
17881 CHECK(string2->IsExternal());
17882 CHECK(string3->IsExternal());
17886 visitor.CheckVisitedResources();
17890 TEST(ExternalStringCollectedAtTearDown) {
17895 const char* s =
"One string to test them all, one string to find them.";
17910 TEST(ExternalInternalizedStringCollectedAtTearDown) {
17916 CompileRun(
"var ring = 'One string to test them all';");
17917 const char* s =
"One string to test them all";
17922 ring->MakeExternal(inscription);
17934 TEST(ExternalInternalizedStringCollectedAtGC) {
17938 CompileRun(
"var ring = 'One string to test them all';");
17939 const char* s =
"One string to test them all";
17944 ring->MakeExternal(inscription);
17959 static double DoubleFromBits(uint64_t value) {
17966 static uint64_t DoubleToBits(
double value) {
17973 static double DoubleToDateTime(
double input) {
17974 double date_limit = 864e13;
17975 if (
std::isnan(input) || input < -date_limit || input > date_limit) {
17978 return (input < 0) ? -(std::floor(-input)) : std::floor(input);
17984 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
17985 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
17996 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
17997 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
17998 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
17999 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
18000 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
18001 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
18002 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
18006 double date_limit = 864e13;
18008 double test_values[] = {
18030 int num_test_values = 20;
18032 for (
int i = 0; i < num_test_values; i++) {
18033 double test_value = test_values[i];
18039 CHECK_EQ(test_value, stored_number);
18041 uint64_t stored_bits = DoubleToBits(stored_number);
18043 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
18046 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
18048 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
18056 double expected_stored_date = DoubleToDateTime(test_value);
18059 CHECK_EQ(expected_stored_date, stored_date);
18061 uint64_t stored_bits = DoubleToBits(stored_date);
18063 #if defined(V8_TARGET_ARCH_MIPS) && !defined(USE_SIMULATOR)
18066 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
18068 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
18075 static void SpaghettiIncident(
18081 if (tc.HasCaught())
18099 " toString: function () {"
18111 CHECK_EQ(0, strcmp(*value,
"Hey!"));
18124 other_context = Context::New(isolate);
18128 const char* source_simple =
"1";
18135 context->SetEmbedderData(0, obj);
18136 CompileRun(source_simple);
18140 for (gc_count = 1; gc_count < 10; gc_count++) {
18141 other_context->Enter();
18142 CompileRun(source_simple);
18143 other_context->Exit();
18145 if (GetGlobalObjectsCount() == 1)
break;
18148 CHECK_EQ(1, GetGlobalObjectsCount());
18152 const char* source_eval =
"function f(){eval('1')}; f()";
18158 CompileRun(source_eval);
18162 for (gc_count = 1; gc_count < 10; gc_count++) {
18163 other_context->Enter();
18164 CompileRun(source_eval);
18165 other_context->Exit();
18167 if (GetGlobalObjectsCount() == 1)
break;
18170 CHECK_EQ(1, GetGlobalObjectsCount());
18174 const char* source_exception =
"function f(){throw 1;} f()";
18181 CompileRun(source_exception);
18184 CHECK(!message.IsEmpty());
18185 CHECK_EQ(1, message->GetLineNumber());
18189 for (gc_count = 1; gc_count < 10; gc_count++) {
18190 other_context->Enter();
18191 CompileRun(source_exception);
18192 other_context->Exit();
18194 if (GetGlobalObjectsCount() == 1)
break;
18197 CHECK_EQ(1, GetGlobalObjectsCount());
18209 env->
GetIsolate(),
"function f() {}\n\nfunction g() {}");
18222 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
18233 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
18244 const char* code =
"var error = false;"
18245 "function a() { this.x = 1; };"
18246 "a.displayName = 'display_a';"
18247 "var b = (function() {"
18248 " var f = function() { this.x = 2; };"
18249 " f.displayName = 'display_b';"
18252 "var c = function() {};"
18253 "c.__defineGetter__('displayName', function() {"
18255 " throw new Error();"
18258 "d.__defineGetter__('displayName', function() {"
18260 " return 'wrong_display_name';"
18263 "e.displayName = 'wrong_display_name';"
18264 "e.__defineSetter__('displayName', function() {"
18266 " throw new Error();"
18269 "f.displayName = { 'foo': 6, toString: function() {"
18271 " return 'wrong_display_name';"
18273 "var g = function() {"
18274 " arguments.callee.displayName = 'set_in_runtime';"
18297 CHECK_EQ(
false, error->BooleanValue());
18314 env->
GetIsolate(),
"function f() {}\n\nfunction g() {}");
18334 isolate,
"function foo() {}\n\n function bar() {}");
18353 CHECK(f->IsBuiltin());
18355 CHECK(f->IsBuiltin());
18357 CHECK(f->IsBuiltin());
18359 CHECK(!f->IsBuiltin());
18372 isolate,
"function foo() {}\n\n function bar() {}");
18391 "var a = new Object();\n"
18393 "function f () { return this.x };\n"
18394 "var g = f.bind(a);\n"
18402 Local<v8::Function> original_function = Local<v8::Function>::Cast(
18411 static void GetterWhichReturns42(
18412 Local<String> name,
18420 static void SetterWhichSetsYOnThisTo23(
18421 Local<String> name,
18422 Local<Value> value,
18426 info.
This()->Set(v8_str(
"y"), v8_num(23));
18434 if (!name->Equals(v8_str(
"foo")))
return;
18440 Local<Value> value,
18444 if (!name->Equals(v8_str(
"foo")))
return;
18445 info.
This()->Set(v8_str(
"y"), v8_num(23));
18453 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18454 templ->SetAccessor(v8_str(
"x"),
18455 GetterWhichReturns42,
18456 SetterWhichSetsYOnThisTo23);
18458 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
18459 CompileRun(
"function C1() {"
18462 "C1.prototype = P;"
18466 "C2.prototype = { };"
18467 "C2.prototype.__proto__ = P;");
18470 script = v8_compile(
"new C1();");
18471 for (
int i = 0; i < 10; i++) {
18473 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
18474 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
18477 script = v8_compile(
"new C2();");
18478 for (
int i = 0; i < 10; i++) {
18480 CHECK_EQ(42, c2->
Get(v8_str(
"x"))->Int32Value());
18481 CHECK_EQ(23, c2->
Get(v8_str(
"y"))->Int32Value());
18486 static void NamedPropertyGetterWhichReturns42(
18487 Local<String> name,
18493 static void NamedPropertySetterWhichSetsYOnThisTo23(
18494 Local<String> name,
18495 Local<Value> value,
18497 if (name->Equals(v8_str(
"x"))) {
18498 info.
This()->Set(v8_str(
"y"), v8_num(23));
18506 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18507 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
18508 NamedPropertySetterWhichSetsYOnThisTo23);
18510 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
18511 CompileRun(
"function C1() {"
18514 "C1.prototype = P;"
18518 "C2.prototype = { };"
18519 "C2.prototype.__proto__ = P;");
18522 script = v8_compile(
"new C1();");
18523 for (
int i = 0; i < 10; i++) {
18525 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
18526 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
18529 script = v8_compile(
"new C2();");
18530 for (
int i = 0; i < 10; i++) {
18532 CHECK_EQ(23, c2->
Get(v8_str(
"x"))->Int32Value());
18533 CHECK_EQ(42, c2->
Get(v8_str(
"y"))->Int32Value());
18539 const char* source =
"function C1() {"
18542 "C1.prototype = P;";
18551 prototype->
Set(v8_str(
"y"), v8_num(42));
18552 context->
Global()->Set(v8_str(
"P"), prototype);
18555 CompileRun(source);
18557 script = v8_compile(
"new C1();");
18560 for (
int i = 0; i < 256; i++) {
18562 CHECK_EQ(23, c1->
Get(v8_str(
"x"))->Int32Value());
18563 CHECK_EQ(42, c1->
Get(v8_str(
"y"))->Int32Value());
18567 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18568 templ->SetAccessor(v8_str(
"x"),
18569 GetterWhichReturns42,
18570 SetterWhichSetsYOnThisTo23);
18571 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
18574 CompileRun(source);
18576 script = v8_compile(
"new C1();");
18577 for (
int i = 0; i < 10; i++) {
18579 CHECK_EQ(42, c1->
Get(v8_str(
"x"))->Int32Value());
18580 CHECK_EQ(23, c1->
Get(v8_str(
"y"))->Int32Value());
18602 CHECK_EQ(gc_callbacks_isolate, isolate);
18617 CHECK_EQ(gc_callbacks_isolate, isolate);
18632 CHECK_EQ(gc_callbacks_isolate, isolate);
18647 CHECK_EQ(gc_callbacks_isolate, isolate);
18658 CHECK_EQ(gc_callbacks_isolate, isolate);
18664 Local<Object> obj = Object::New(isolate);
18665 CHECK(!obj.IsEmpty());
18678 CHECK_EQ(gc_callbacks_isolate, isolate);
18684 Local<Object> obj = Object::New(isolate);
18685 CHECK(!obj.IsEmpty());
18707 CHECK_EQ(1, prologue_call_count_second);
18708 CHECK_EQ(1, epilogue_call_count_second);
18714 CHECK_EQ(2, prologue_call_count_second);
18715 CHECK_EQ(2, epilogue_call_count_second);
18721 CHECK_EQ(2, prologue_call_count_second);
18722 CHECK_EQ(2, epilogue_call_count_second);
18729 gc_callbacks_isolate = isolate;
18742 CHECK_EQ(1, prologue_call_count_second);
18743 CHECK_EQ(1, epilogue_call_count_second);
18749 CHECK_EQ(2, prologue_call_count_second);
18750 CHECK_EQ(2, epilogue_call_count_second);
18756 CHECK_EQ(2, prologue_call_count_second);
18757 CHECK_EQ(2, epilogue_call_count_second);
18759 CHECK_EQ(0, prologue_call_count_alloc);
18760 CHECK_EQ(0, epilogue_call_count_alloc);
18765 CHECK_EQ(1, prologue_call_count_alloc);
18766 CHECK_EQ(1, epilogue_call_count_alloc);
18773 i::FLAG_stress_compaction =
false;
18774 i::FLAG_allow_natives_syntax =
true;
18783 " var r0 = %_GetFromCache(0, key0);"
18784 " var r1 = %_GetFromCache(0, key1);"
18785 " var r0_ = %_GetFromCache(0, key0);"
18787 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
18788 " var r1_ = %_GetFromCache(0, key1);"
18790 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
18791 " return 'PASSED';"
18794 ExpectString(code,
"PASSED");
18799 i::FLAG_allow_natives_syntax =
true;
18806 " var r = %_GetFromCache(0, k);"
18807 " for (var i = 0; i < 16; i++) {"
18808 " %_GetFromCache(0, 'a' + i);"
18810 " if (r === %_GetFromCache(0, k))"
18811 " return 'FAILED: k0CacheSize is too small';"
18812 " return 'PASSED';"
18815 ExpectString(code,
"PASSED");
18820 i::FLAG_allow_natives_syntax =
true;
18827 " for (var i = 0; i < 16; i++) keys.push(i);"
18828 " var values = [];"
18829 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
18830 " for (var i = 0; i < 16; i++) {"
18831 " var v = %_GetFromCache(0, keys[i]);"
18832 " if (v.toString() !== values[i].toString())"
18833 " return 'Wrong value for ' + "
18834 " keys[i] + ': ' + v + ' vs. ' + values[i];"
18836 " return 'PASSED';"
18839 ExpectString(code,
"PASSED");
18844 i::FLAG_allow_natives_syntax =
true;
18851 " for (var i = 0; i < 16; i++) keys.push(i);"
18852 " var values = [];"
18853 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
18854 " for (var i = 15; i >= 16; i--) {"
18855 " var v = %_GetFromCache(0, keys[i]);"
18856 " if (v !== values[i])"
18857 " return 'Wrong value for ' + "
18858 " keys[i] + ': ' + v + ' vs. ' + values[i];"
18860 " return 'PASSED';"
18863 ExpectString(code,
"PASSED");
18868 i::FLAG_allow_natives_syntax =
true;
18874 " for (var i = 0; i < 2*16; i++) {"
18875 " %_GetFromCache(0, 'a' + i);"
18877 " return 'PASSED';"
18880 ExpectString(code,
"PASSED");
18889 const char* init_code =
18890 "var str1 = 'abelspendabel';"
18891 "var str2 = str1 + str1 + str1;"
18893 Local<Value> result = CompileRun(init_code);
18895 Local<Value> indexof = CompileRun(
"str2.indexOf('els')");
18896 Local<Value> lastindexof = CompileRun(
"str2.lastIndexOf('dab')");
18898 CHECK(result->IsString());
18900 int length =
string->length();
18901 CHECK(string->IsOneByteRepresentation());
18906 CHECK(string->IsOneByteRepresentation());
18907 CHECK(flat_string->IsOneByteRepresentation());
18913 uc16_buffer[length] = 0;
18917 flat_string->MakeExternal(&resource);
18919 CHECK(flat_string->IsTwoByteRepresentation());
18922 if (!
string.is_identical_to(flat_string)) {
18927 CHECK(string->IsOneByteRepresentation());
18929 CHECK_EQ(0, cons->second()->length());
18930 CHECK(cons->first()->IsTwoByteRepresentation());
18936 Local<Value> reresult = CompileRun(
"str2.match(/abel/g).length;");
18937 CHECK_EQ(6, reresult->Int32Value());
18940 reresult = CompileRun(
"str2.match(/abe./g).length;");
18941 CHECK_EQ(6, reresult->Int32Value());
18943 reresult = CompileRun(
"str2.search(/bel/g);");
18944 CHECK_EQ(1, reresult->Int32Value());
18946 reresult = CompileRun(
"str2.search(/be./g);");
18947 CHECK_EQ(1, reresult->Int32Value());
18949 ExpectTrue(
"/bel/g.test(str2);");
18951 ExpectTrue(
"/be./g.test(str2);");
18953 reresult = CompileRun(
"/bel/g.exec(str2);");
18954 CHECK(!reresult->IsNull());
18956 reresult = CompileRun(
"/be./g.exec(str2);");
18957 CHECK(!reresult->IsNull());
18959 ExpectString(
"str2.substring(2, 10);",
"elspenda");
18961 ExpectString(
"str2.substring(2, 20);",
"elspendabelabelspe");
18963 ExpectString(
"str2.charAt(2);",
"e");
18965 ExpectObject(
"str2.indexOf('els');", indexof);
18967 ExpectObject(
"str2.lastIndexOf('dab');", lastindexof);
18969 reresult = CompileRun(
"str2.charCodeAt(2);");
18970 CHECK_EQ(static_cast<int32_t>(
'e'), reresult->Int32Value());
18979 const int length = 512;
18981 const int aligned_length = length*
sizeof(uintptr_t)/
sizeof(
uint16_t);
18983 aligned_contents(
new uintptr_t[aligned_length]);
18985 reinterpret_cast<uint16_t*
>(aligned_contents.
get());
18987 for (
int i = 0; i < length-1; i++) {
18988 string_contents[i] = 0x41;
18990 string_contents[length-1] = 0;
18992 Handle<String>
string =
18993 String::NewExternal(isolate,
18995 CHECK(!string->IsOneByte() &&
string->ContainsOnlyOneByte());
18997 string = String::NewFromTwoByte(isolate, string_contents);
18998 CHECK(string->IsOneByte() &&
string->ContainsOnlyOneByte());
19000 Handle<String> base = String::NewFromUtf8(isolate,
"a");
19001 Handle<String> left = base;
19002 Handle<String> right = base;
19003 for (
int i = 0; i < 1000; i++) {
19004 left = String::Concat(base, left);
19005 right = String::Concat(right, base);
19007 Handle<String> balanced = String::Concat(left, base);
19008 balanced = String::Concat(balanced, right);
19009 Handle<String> cons_strings[] = {left, balanced, right};
19010 Handle<String> two_byte =
19011 String::NewExternal(isolate,
19013 USE(two_byte); USE(cons_strings);
19014 for (
size_t i = 0; i <
ARRAY_SIZE(cons_strings); i++) {
19016 string = cons_strings[i];
19017 CHECK(string->IsOneByte() &&
string->ContainsOnlyOneByte());
19019 string = String::Concat(two_byte, cons_strings[i]);
19020 CHECK(!string->IsOneByte() &&
string->ContainsOnlyOneByte());
19021 string = String::Concat(cons_strings[i], two_byte);
19022 CHECK(!string->IsOneByte() &&
string->ContainsOnlyOneByte());
19026 for (
int alignment = 0; alignment < 7; alignment++) {
19027 for (
int size = 2; alignment +
size < length;
size *= 2) {
19028 int zero_offset =
size + alignment;
19029 string_contents[zero_offset] = 0;
19030 for (
int i = 0; i <
size; i++) {
19031 int shift = 8 + (i % 7);
19032 string_contents[alignment + i] = 1 <<
shift;
19033 string = String::NewExternal(
19037 CHECK(!string->ContainsOnlyOneByte());
19038 string_contents[alignment + i] = 0x41;
19040 string_contents[zero_offset] = 0x41;
19049 Local<v8::Value> data) {
19069 IndexedGetAccessBlocker,
19075 context0->
Global()->Set(v8_str(
"x"), v8_num(42));
19081 context1->
Global()->Set(v8_str(
"other"), global0);
19084 ExpectUndefined(
"other.x");
19087 ExpectUndefined(
"other[0]");
19094 result = CompileRun(
"other[0] = new Object()");
19095 CHECK(result->IsObject());
19098 ExpectFalse(
"\'x\' in other");
19101 ExpectFalse(
"0 in other");
19104 ExpectFalse(
"delete other.x");
19114 ExpectUndefined(
"Object.prototype.__defineGetter__.call("
19115 " other, \'x\', function() { return 42; })");
19118 ExpectUndefined(
"Object.prototype.__lookupGetter__.call("
19122 ExpectFalse(
"Object.prototype.hasOwnProperty.call(other, \'0\')");
19138 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
19139 CHECK(current_isolate != isolate);
19143 last_location = last_message =
NULL;
19157 ExpectTrue(
"true");
19159 last_location = last_message =
NULL;
19176 context1.
Reset(isolate1, Context::New(isolate1));
19185 CompileRun(
"var foo = 'isolate 1';");
19186 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
19196 context2.
Reset(isolate2, Context::New(isolate2));
19202 CompileRun(
"var foo = 'isolate 2';");
19203 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
19212 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
19223 context_default.
Reset(isolate, Context::New(isolate));
19233 ExpectTrue(
"function f() {"
19241 "var isDefaultIsolate = true;"
19253 ExpectString(
"function f() { return foo; }; f()",
"isolate 2");
19261 ExpectString(
"function f() { return foo; }; f()",
"isolate 1");
19273 last_location = last_message =
NULL;
19289 ExpectTrue(
"function f() { return isDefaultIsolate; }; f()");
19294 static int CalcFibonacci(
v8::Isolate* isolate,
int limit) {
19300 " if (n <= 2) return 1;"
19301 " return fib(n-1) + fib(n-2);"
19304 Local<Value> value = CompileRun(code.start());
19305 CHECK(value->IsNumber());
19306 return static_cast<int>(value->NumberValue());
19312 :
Thread(
"IsolateThread"),
19314 fib_limit_(fib_limit),
19318 result_ = CalcFibonacci(isolate_, fib_limit_);
19330 TEST(MultipleIsolatesOnIndividualThreads) {
19361 Local<v8::Context> context;
19367 Local<Value> v = CompileRun(
"2");
19368 CHECK(v->IsNumber());
19369 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
19376 Local<Value> v = CompileRun(
"22");
19377 CHECK(v->IsNumber());
19378 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
19394 :
Thread(
"InitDefaultIsolateThread"),
19395 testCase_(testCase),
19401 switch (testCase_) {
19403 static const int K = 1024;
19448 TEST(InitializeDefaultIsolateOnSecondaryThread1) {
19453 TEST(InitializeDefaultIsolateOnSecondaryThread2) {
19458 TEST(InitializeDefaultIsolateOnSecondaryThread3) {
19463 TEST(InitializeDefaultIsolateOnSecondaryThread4) {
19468 TEST(InitializeDefaultIsolateOnSecondaryThread5) {
19475 "(function() { return \"a\".charAt(0); })()";
19481 ExpectString(code,
"a");
19482 ExpectString(code,
"a");
19490 CompileRun(
"String.prototype.charAt = function() { return \"not a\"; }");
19491 ExpectString(code,
"not a");
19498 "(function() { return (42).toString(); })()";
19504 ExpectString(code,
"42");
19505 ExpectString(code,
"42");
19513 CompileRun(
"Number.prototype.toString = function() { return \"not 42\"; }");
19514 ExpectString(code,
"not 42");
19521 "(function() { return true.toString(); })()";
19527 ExpectString(code,
"true");
19528 ExpectString(code,
"true");
19536 CompileRun(
"Boolean.prototype.toString = function() { return \"\"; }");
19537 ExpectString(code,
"");
19543 const char* function_code =
19544 "function readCell() { while (true) { return cell; } }";
19551 CompileRun(
"var cell = \"first\";");
19552 ExpectBoolean(
"delete cell",
false);
19553 CompileRun(function_code);
19554 ExpectString(
"readCell()",
"first");
19555 ExpectString(
"readCell()",
"first");
19562 CompileRun(
"cell = \"second\";");
19563 CompileRun(function_code);
19564 ExpectString(
"readCell()",
"second");
19565 ExpectBoolean(
"delete cell",
true);
19566 ExpectString(
"(function() {"
19568 " return readCell();"
19570 " return e.toString();"
19573 "ReferenceError: cell is not defined");
19574 CompileRun(
"cell = \"new_second\";");
19576 ExpectString(
"readCell()",
"new_second");
19577 ExpectString(
"readCell()",
"new_second");
19582 TEST(DontDeleteCellLoadICForceDelete) {
19583 const char* function_code =
19584 "function readCell() { while (true) { return cell; } }";
19590 CompileRun(
"var cell = \"value\";");
19591 ExpectBoolean(
"delete cell",
false);
19592 CompileRun(function_code);
19593 ExpectString(
"readCell()",
"value");
19594 ExpectString(
"readCell()",
"value");
19598 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
19599 ExpectString(
"(function() {"
19601 " return readCell();"
19603 " return e.toString();"
19606 "ReferenceError: cell is not defined");
19611 const char* function_code =
19612 "function readCell() { while (true) { return cell; } }";
19619 ExpectBoolean(
"delete cell",
false);
19620 CompileRun(function_code);
19621 ExpectString(
"readCell()",
"value");
19622 ExpectString(
"readCell()",
"value");
19626 CHECK(context->
Global()->ForceDelete(v8_str(
"cell")));
19627 ExpectString(
"(function() {"
19629 " return readCell();"
19631 " return e.toString();"
19634 "ReferenceError: cell is not defined");
19645 if (class_id != 42)
return;
19646 CHECK_EQ(42, value->WrapperClassId());
19667 CHECK_EQ(0,
object.WrapperClassId());
19668 object.SetWrapperClassId(42);
19669 CHECK_EQ(42,
object.WrapperClassId());
19684 CHECK_EQ(0,
object.WrapperClassId());
19685 object.SetWrapperClassId(65535);
19686 CHECK_EQ(65535,
object.WrapperClassId());
19691 TEST(PersistentHandleInNewSpaceVisitor) {
19721 CHECK(re->IsRegExp());
19722 CHECK(re->GetSource()->Equals(v8_str(
"foo")));
19728 CHECK(re->IsRegExp());
19729 CHECK(re->GetSource()->Equals(v8_str(
"bar")));
19731 static_cast<int>(re->GetFlags()));
19736 CHECK(re->IsRegExp());
19737 CHECK(re->GetSource()->Equals(v8_str(
"baz")));
19739 static_cast<int>(re->GetFlags()));
19742 CHECK(re->IsRegExp());
19743 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
19746 re = CompileRun(
"/quux/gm").As<
v8::RegExp>();
19747 CHECK(re->IsRegExp());
19748 CHECK(re->GetSource()->Equals(v8_str(
"quux")));
19750 static_cast<int>(re->GetFlags()));
19754 CompileRun(
"RegExp = function() {}");
19757 CHECK(re->IsRegExp());
19758 CHECK(re->GetSource()->Equals(v8_str(
"foobar")));
19764 CHECK(re->IsRegExp());
19765 CHECK(re->GetSource()->Equals(v8_str(
"foobarbaz")));
19767 static_cast<int>(re->GetFlags()));
19769 context->
Global()->Set(v8_str(
"re"), re);
19770 ExpectTrue(
"re.test('FoobarbaZ')");
19779 CHECK(re.IsEmpty());
19780 CHECK(try_catch.HasCaught());
19781 context->
Global()->Set(v8_str(
"ex"), try_catch.Exception());
19782 ExpectTrue(
"ex instanceof SyntaxError");
19795 CHECK(!globalProxy->StrictEquals(global));
19796 CHECK(globalProxy->StrictEquals(globalProxy));
19800 CHECK(!globalProxy->Equals(global));
19801 CHECK(globalProxy->Equals(globalProxy));
19813 result->
Set(0, v8_str(
"universalAnswer"));
19825 tmpl->SetNamedPropertyHandler(Getter,
NULL,
NULL,
NULL, Enumerator);
19826 context->
Global()->Set(v8_str(
"o"), tmpl->NewInstance());
19828 "var result = []; for (var k in o) result.push(k); result"));
19830 CHECK_EQ(v8_str(
"universalAnswer"), result->
Get(0));
19839 CompileRun(
"(function() {"
19840 " Object.defineProperty("
19843 " { configurable: true, enumerable: true, value: 3 });"
19844 "})").
As<Function>();
19846 define_property->
Call(proxy, 0,
NULL);
19851 Context::Scope scope(context);
19852 CompileRun(
"Object.prototype").As<
Object>()->
19858 CHECK_EQ(expected, object->
Get(v8_str(
"context_id"))->Int32Value());
19864 HandleScope handle_scope(isolate);
19865 Handle<Context> context1 = Context::New(isolate);
19866 InstallContextId(context1, 1);
19867 Handle<Context> context2 = Context::New(isolate);
19868 InstallContextId(context2, 2);
19869 Handle<Context> context3 = Context::New(isolate);
19870 InstallContextId(context3, 3);
19874 Local<Object> object1;
19875 Local<Function> func1;
19877 Context::Scope scope(context1);
19878 object1 = Object::New(isolate);
19879 func1 = tmpl->GetFunction();
19882 Local<Object> object2;
19883 Local<Function> func2;
19885 Context::Scope scope(context2);
19886 object2 = Object::New(isolate);
19887 func2 = tmpl->GetFunction();
19890 Local<Object> instance1;
19891 Local<Object> instance2;
19894 Context::Scope scope(context3);
19895 instance1 = func1->NewInstance();
19896 instance2 = func2->NewInstance();
19899 CHECK(object1->CreationContext() == context1);
19900 CheckContextId(object1, 1);
19901 CHECK(func1->CreationContext() == context1);
19902 CheckContextId(func1, 1);
19903 CHECK(instance1->CreationContext() == context1);
19904 CheckContextId(instance1, 1);
19905 CHECK(object2->CreationContext() == context2);
19906 CheckContextId(object2, 2);
19907 CHECK(func2->CreationContext() == context2);
19908 CheckContextId(func2, 2);
19909 CHECK(instance2->CreationContext() == context2);
19910 CheckContextId(instance2, 2);
19913 Context::Scope scope(context1);
19914 CHECK(object1->CreationContext() == context1);
19915 CheckContextId(object1, 1);
19916 CHECK(func1->CreationContext() == context1);
19917 CheckContextId(func1, 1);
19918 CHECK(instance1->CreationContext() == context1);
19919 CheckContextId(instance1, 1);
19920 CHECK(object2->CreationContext() == context2);
19921 CheckContextId(object2, 2);
19922 CHECK(func2->CreationContext() == context2);
19923 CheckContextId(func2, 2);
19924 CHECK(instance2->CreationContext() == context2);
19925 CheckContextId(instance2, 2);
19929 Context::Scope scope(context2);
19930 CHECK(object1->CreationContext() == context1);
19931 CheckContextId(object1, 1);
19932 CHECK(func1->CreationContext() == context1);
19933 CheckContextId(func1, 1);
19934 CHECK(instance1->CreationContext() == context1);
19935 CheckContextId(instance1, 1);
19936 CHECK(object2->CreationContext() == context2);
19937 CheckContextId(object2, 2);
19938 CHECK(func2->CreationContext() == context2);
19939 CheckContextId(func2, 2);
19940 CHECK(instance2->CreationContext() == context2);
19941 CheckContextId(instance2, 2);
19949 InstallContextId(context, 1);
19951 Local<Object>
function;
19953 Context::Scope scope(context);
19954 function = CompileRun(
"function foo() {}; foo").As<
Object>();
19957 CHECK(function->CreationContext() == context);
19958 CheckContextId(
function, 1);
19970 Local<String> property,
19972 if (property->Equals(v8_str(
"foo"))) info.
GetReturnValue().Set(v8_str(
"yes"));
19983 Local<String> property,
19985 if (property->Equals(v8_str(
"foo"))) info.
GetReturnValue().Set(1);
19990 Local<String> property,
19992 if (property->Equals(v8_str(
"bar"))) info.
GetReturnValue().Set(1);
19997 Local<String> property,
20008 Handle<Value> value = CompileRun(
20011 " this.__defineGetter__('baz', function() { return 1; });"
20013 "function Bar() { "
20015 " this.__defineGetter__('bla', function() { return 2; });"
20017 "Bar.prototype = new Foo();"
20019 CHECK(value->IsObject());
20020 Handle<Object>
object = value->ToObject();
20021 CHECK(object->Has(v8_str(
"foo")));
20022 CHECK(!object->HasOwnProperty(v8_str(
"foo")));
20023 CHECK(object->HasOwnProperty(v8_str(
"bar")));
20024 CHECK(object->Has(v8_str(
"baz")));
20025 CHECK(!object->HasOwnProperty(v8_str(
"baz")));
20026 CHECK(object->HasOwnProperty(v8_str(
"bla")));
20029 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20031 Handle<Object> instance = templ->NewInstance();
20032 CHECK(!instance->HasOwnProperty(v8_str(
"42")));
20033 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
20034 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
20037 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20039 Handle<Object> instance = templ->NewInstance();
20040 CHECK(instance->HasOwnProperty(v8_str(
"42")));
20041 CHECK(!instance->HasOwnProperty(v8_str(
"43")));
20042 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
20045 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20047 Handle<Object> instance = templ->NewInstance();
20048 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
20049 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
20052 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20054 Handle<Object> instance = templ->NewInstance();
20055 CHECK(instance->HasOwnProperty(v8_str(
"42")));
20056 CHECK(!instance->HasOwnProperty(v8_str(
"41")));
20059 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20061 Handle<Object> instance = templ->NewInstance();
20062 CHECK(instance->HasOwnProperty(v8_str(
"foo")));
20063 CHECK(!instance->HasOwnProperty(v8_str(
"bar")));
20066 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20070 Handle<Object> instance = templ->NewInstance();
20071 CHECK(!instance->HasOwnProperty(v8_str(
"foo")));
20072 CHECK(instance->HasOwnProperty(v8_str(
"bar")));
20077 TEST(IndexedInterceptorWithStringProto) {
20080 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20081 templ->SetIndexedPropertyHandler(
NULL,
20085 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
20086 CompileRun(
"var s = new String('foobar'); obj.__proto__ = s;");
20088 CHECK(CompileRun(
"42 in obj")->BooleanValue());
20089 CHECK(CompileRun(
"'42' in obj")->BooleanValue());
20091 CHECK(CompileRun(
"0 in obj")->BooleanValue());
20092 CHECK(CompileRun(
"'0' in obj")->BooleanValue());
20094 CHECK(!CompileRun(
"32 in obj")->BooleanValue());
20095 CHECK(!CompileRun(
"'32' in obj")->BooleanValue());
20100 Handle<Value> result = CompileRun(
"eval('42')");
20101 CHECK_EQ(42, result->Int32Value());
20102 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
20103 CHECK_EQ(42, result->Int32Value());
20104 result = CompileRun(
"var f = new Function('return 42'); f()");
20105 CHECK_EQ(42, result->Int32Value());
20110 TryCatch try_catch;
20112 Handle<Value> result = CompileRun(
"eval('42')");
20113 CHECK(result.IsEmpty());
20114 CHECK(try_catch.HasCaught());
20117 result = CompileRun(
"(function(e) { return e('42'); })(eval)");
20118 CHECK(result.IsEmpty());
20119 CHECK(try_catch.HasCaught());
20122 result = CompileRun(
"var f = new Function('return 42'); f()");
20123 CHECK(result.IsEmpty());
20124 CHECK(try_catch.HasCaught());
20170 TEST(SetErrorMessageForCodeGenFromStrings) {
20173 TryCatch try_catch;
20175 Handle<String> message = v8_str(
"Message") ;
20176 Handle<String> expected_message = v8_str(
"Uncaught EvalError: Message");
20180 Handle<Value> result = CompileRun(
"eval('42')");
20181 CHECK(result.IsEmpty());
20182 CHECK(try_catch.HasCaught());
20183 Handle<String> actual_message = try_catch.Message()->Get();
20184 CHECK(expected_message->Equals(actual_message));
20196 Handle<FunctionTemplate> templ =
20198 Handle<Function>
function = templ->GetFunction();
20199 context->
Global()->Set(v8_str(
"f"),
function);
20200 TryCatch try_catch;
20201 CompileRun(
"f.call(2)");
20209 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
20212 Local<v8::Object> obj = templ->NewInstance();
20213 context->
Global()->Set(v8_str(
"obj"), obj);
20214 obj->Set(v8_str(
"1"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
20215 obj->Set(v8_str(
"1"), v8_str(
"foobar"));
20216 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"1")));
20217 obj->Set(v8_num(2), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
20218 obj->Set(v8_num(2), v8_str(
"foobar"));
20219 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_num(2)));
20222 obj->Set(v8_str(
"2000000000"), v8_str(
"DONT_CHANGE"),
v8::ReadOnly);
20223 obj->Set(v8_str(
"2000000000"), v8_str(
"foobar"));
20224 CHECK_EQ(v8_str(
"DONT_CHANGE"), obj->Get(v8_str(
"2000000000")));
20233 CompileRun(
"({'a': 0})");
20246 if (raw_map_cache !=
CcTest::heap()->undefined_value()) {
20254 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
20257 Local<Value> data) {
20260 name->IsString() &&
20261 name->ToString()->Length() == 9 &&
20262 name->ToString()->Utf8Length() == 9) {
20264 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
20265 return strncmp(buffer,
"__proto__", 9) != 0;
20274 HandleScope scope(isolate);
20279 no_proto_template->SetAccessCheckCallbacks(
20280 BlockProtoNamedSecurityTestCallback,
20281 IndexedSecurityTestCallback);
20284 Local<FunctionTemplate> hidden_proto_template =
20286 hidden_proto_template->SetHiddenPrototype(
true);
20288 Local<FunctionTemplate> protected_hidden_proto_template =
20290 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
20291 BlockProtoNamedSecurityTestCallback,
20292 IndexedSecurityTestCallback);
20293 protected_hidden_proto_template->SetHiddenPrototype(
true);
20300 Local<Object> simple_object = Object::New(isolate);
20303 Local<Object> protected_object =
20304 no_proto_template->NewInstance();
20307 Local<Object> proxy_object =
20311 Local<Object> global_object =
20312 proxy_object->GetPrototype()->ToObject();
20315 Local<Object> hidden_prototype =
20316 hidden_proto_template->GetFunction()->NewInstance();
20317 Local<Object> object_with_hidden =
20318 Object::New(isolate);
20319 object_with_hidden->SetPrototype(hidden_prototype);
20322 Local<Object> protected_hidden_prototype =
20323 protected_hidden_proto_template->GetFunction()->NewInstance();
20324 Local<Object> object_with_protected_hidden =
20325 Object::New(isolate);
20326 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
20332 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
20333 global_template->Set(v8_str(
"simple"), simple_object);
20334 global_template->Set(v8_str(
"protected"), protected_object);
20335 global_template->Set(v8_str(
"global"), global_object);
20336 global_template->Set(v8_str(
"proxy"), proxy_object);
20337 global_template->Set(v8_str(
"hidden"), object_with_hidden);
20338 global_template->Set(v8_str(
"phidden"), object_with_protected_hidden);
20342 Local<Value> result1 = CompileRun(
"Object.getPrototypeOf(simple)");
20343 CHECK(result1->Equals(simple_object->GetPrototype()));
20345 Local<Value> result2 = CompileRun(
"Object.getPrototypeOf(protected)");
20348 Local<Value> result3 = CompileRun(
"Object.getPrototypeOf(global)");
20349 CHECK(result3->Equals(global_object->GetPrototype()));
20351 Local<Value> result4 = CompileRun(
"Object.getPrototypeOf(proxy)");
20354 Local<Value> result5 = CompileRun(
"Object.getPrototypeOf(hidden)");
20355 CHECK(result5->Equals(
20356 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
20358 Local<Value> result6 = CompileRun(
"Object.getPrototypeOf(phidden)");
20365 Handle<FunctionTemplate> intercept = FunctionTemplate::New(
CcTest::isolate());
20368 env->
Global()->Set(v8_str(
"Intercept"), intercept->GetFunction());
20369 CompileRun(
"var a = new Object();"
20370 "var b = new Intercept();"
20371 "var c = new Object();"
20375 "for (var i = 0; i < 3; i++) c.x;");
20376 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
20377 ExpectInt32(
"c.x", 23);
20378 CompileRun(
"a.y = 42;"
20379 "for (var i = 0; i < 3; i++) c.x;");
20380 ExpectBoolean(
"c.hasOwnProperty('x')",
false);
20381 ExpectInt32(
"c.x", 23);
20382 ExpectBoolean(
"c.hasOwnProperty('y')",
false);
20383 ExpectInt32(
"c.y", 42);
20387 static void TestReceiver(Local<Value> expected_result,
20388 Local<Value> expected_receiver,
20389 const char* code) {
20390 Local<Value> result = CompileRun(code);
20391 CHECK(result->IsObject());
20392 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
20393 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
20399 HandleScope scope(isolate);
20407 foreign_context->Enter();
20408 Local<Value> foreign_function =
20409 CompileRun(
"function func() { return { 0: this.id, "
20411 " toString: function() { "
20418 CHECK(foreign_function->IsFunction());
20419 foreign_context->Exit();
20423 Local<String> password = v8_str(
"Password");
20427 foreign_context->SetSecurityToken(password);
20429 Local<String> i = v8_str(
"i");
20430 Local<String> o = v8_str(
"o");
20431 Local<String>
id = v8_str(
"id");
20433 CompileRun(
"function ownfunc() { return { 0: this.id, "
20435 " toString: function() { "
20442 context->
Global()->Set(v8_str(
"func"), foreign_function);
20445 CHECK(i->Equals(foreign_context->Global()->Get(
id)));
20450 TestReceiver(o, context->
Global(),
"ownfunc.call()");
20451 TestReceiver(o, context->
Global(),
"ownfunc.apply()");
20453 TestReceiver(o, context->
Global(),
"[1].map(ownfunc)[0]");
20454 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/,ownfunc)[1]")));
20455 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[1]")));
20456 CHECK(o->Equals(CompileRun(
"'abcbd'.replace(/b/g,ownfunc)[3]")));
20458 TestReceiver(o, context->
Global(),
"ownfunc()");
20460 TestReceiver(o, context->
Global(),
"(1,ownfunc)()");
20464 TestReceiver(i, foreign_context->Global(),
"func.call()");
20465 TestReceiver(i, foreign_context->Global(),
"func.apply()");
20467 TestReceiver(i, foreign_context->Global(),
20468 "Function.prototype.call.call(func)");
20469 TestReceiver(i, foreign_context->Global(),
20470 "Function.prototype.call.apply(func)");
20471 TestReceiver(i, foreign_context->Global(),
20472 "Function.prototype.apply.call(func)");
20473 TestReceiver(i, foreign_context->Global(),
20474 "Function.prototype.apply.apply(func)");
20476 TestReceiver(i, foreign_context->Global(),
"[1].map(func)[0]");
20478 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/,func)[1]")));
20479 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[1]")));
20480 CHECK(i->Equals(CompileRun(
"'abcbd'.replace(/b/g,func)[3]")));
20483 TestReceiver(i, foreign_context->Global(),
"func()");
20485 TestReceiver(i, foreign_context->Global(),
"(1,func)()");
20494 callback_fired ^= 1;
20500 callback_fired ^= 2;
20505 int32_t level = args[0]->Int32Value();
20508 i::OS::Print(
"Entering recursion level %d.\n", level);
20512 CompileRun(script_vector.
start());
20527 env->
Global()->Set(v8_str(
"recursion"),
20528 recursive_runtime->GetFunction());
20540 callback_fired = 0;
20546 callback_fired = 0;
20547 Local<Function> recursive_function =
20548 Local<Function>::Cast(env->
Global()->Get(v8_str(
"recursion")));
20550 recursive_function->Call(env->
Global(), 1, args);
20557 CompileRun(
"1+1;");
20563 CompileRun(
"throw 'second exception';");
20567 TEST(CallCompletedCallbackOneException) {
20571 CompileRun(
"throw 'exception';");
20575 TEST(CallCompletedCallbackTwoExceptions) {
20579 CompileRun(
"throw 'first exception';");
20585 CompileRun(
"ext1Calls++;");
20591 CompileRun(
"ext2Calls++;");
20599 "var ext1Calls = 0;"
20600 "var ext2Calls = 0;");
20601 CompileRun(
"1+1;");
20602 CHECK_EQ(0, CompileRun(
"ext1Calls")->Int32Value());
20603 CHECK_EQ(0, CompileRun(
"ext2Calls")->Int32Value());
20606 Function::New(env->
GetIsolate(), MicrotaskOne));
20607 CompileRun(
"1+1;");
20608 CHECK_EQ(1, CompileRun(
"ext1Calls")->Int32Value());
20609 CHECK_EQ(0, CompileRun(
"ext2Calls")->Int32Value());
20612 Function::New(env->
GetIsolate(), MicrotaskOne));
20614 Function::New(env->
GetIsolate(), MicrotaskTwo));
20615 CompileRun(
"1+1;");
20616 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20617 CHECK_EQ(1, CompileRun(
"ext2Calls")->Int32Value());
20620 Function::New(env->
GetIsolate(), MicrotaskTwo));
20621 CompileRun(
"1+1;");
20622 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20623 CHECK_EQ(2, CompileRun(
"ext2Calls")->Int32Value());
20625 CompileRun(
"1+1;");
20626 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20627 CHECK_EQ(2, CompileRun(
"ext2Calls")->Int32Value());
20635 "var ext1Calls = 0;"
20636 "var ext2Calls = 0;");
20637 CompileRun(
"1+1;");
20638 CHECK_EQ(0, CompileRun(
"ext1Calls")->Int32Value());
20639 CHECK_EQ(0, CompileRun(
"ext2Calls")->Int32Value());
20642 Function::New(env->
GetIsolate(), MicrotaskOne));
20643 CompileRun(
"1+1;");
20644 CHECK_EQ(1, CompileRun(
"ext1Calls")->Int32Value());
20645 CHECK_EQ(0, CompileRun(
"ext2Calls")->Int32Value());
20647 V8::SetAutorunMicrotasks(env->
GetIsolate(),
false);
20649 Function::New(env->
GetIsolate(), MicrotaskOne));
20651 Function::New(env->
GetIsolate(), MicrotaskTwo));
20652 CompileRun(
"1+1;");
20653 CHECK_EQ(1, CompileRun(
"ext1Calls")->Int32Value());
20654 CHECK_EQ(0, CompileRun(
"ext2Calls")->Int32Value());
20657 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20658 CHECK_EQ(1, CompileRun(
"ext2Calls")->Int32Value());
20661 Function::New(env->
GetIsolate(), MicrotaskTwo));
20662 CompileRun(
"1+1;");
20663 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20664 CHECK_EQ(1, CompileRun(
"ext2Calls")->Int32Value());
20667 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20668 CHECK_EQ(2, CompileRun(
"ext2Calls")->Int32Value());
20670 V8::SetAutorunMicrotasks(env->
GetIsolate(),
true);
20672 Function::New(env->
GetIsolate(), MicrotaskTwo));
20673 CompileRun(
"1+1;");
20674 CHECK_EQ(2, CompileRun(
"ext1Calls")->Int32Value());
20675 CHECK_EQ(3, CompileRun(
"ext2Calls")->Int32Value());
20679 static int probes_counter = 0;
20680 static int misses_counter = 0;
20681 static int updates_counter = 0;
20684 static int* LookupCounter(
const char* name) {
20685 if (strcmp(name,
"c:V8.MegamorphicStubCacheProbes") == 0) {
20686 return &probes_counter;
20687 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheMisses") == 0) {
20688 return &misses_counter;
20689 }
else if (strcmp(name,
"c:V8.MegamorphicStubCacheUpdates") == 0) {
20690 return &updates_counter;
20696 static const char* kMegamorphicTestProgram =
20697 "function ClassA() { };"
20698 "function ClassB() { };"
20699 "ClassA.prototype.foo = function() { };"
20700 "ClassB.prototype.foo = function() { };"
20701 "function fooify(obj) { obj.foo(); };"
20702 "var a = new ClassA();"
20703 "var b = new ClassB();"
20704 "for (var i = 0; i < 10000; i++) {"
20710 static void StubCacheHelper(
bool primary) {
20711 V8::SetCounterFunction(LookupCounter);
20712 USE(kMegamorphicTestProgram);
20714 i::FLAG_native_code_counters =
true;
20716 i::FLAG_test_primary_stub_cache =
true;
20718 i::FLAG_test_secondary_stub_cache =
true;
20720 i::FLAG_crankshaft =
false;
20723 int initial_probes = probes_counter;
20724 int initial_misses = misses_counter;
20725 int initial_updates = updates_counter;
20726 CompileRun(kMegamorphicTestProgram);
20727 int probes = probes_counter - initial_probes;
20728 int misses = misses_counter - initial_misses;
20729 int updates = updates_counter - initial_updates;
20742 StubCacheHelper(
true);
20747 StubCacheHelper(
false);
20751 static int cow_arrays_created_runtime = 0;
20754 static int* LookupCounterCOWArrays(
const char* name) {
20755 if (strcmp(name,
"c:V8.COWArraysCreatedRuntime") == 0) {
20756 return &cow_arrays_created_runtime;
20762 TEST(CheckCOWArraysCreatedRuntimeCounter) {
20763 V8::SetCounterFunction(LookupCounterCOWArrays);
20765 i::FLAG_native_code_counters =
true;
20768 int initial_cow_arrays = cow_arrays_created_runtime;
20769 CompileRun(
"var o = [1, 2, 3];");
20770 CHECK_EQ(1, cow_arrays_created_runtime - initial_cow_arrays);
20771 CompileRun(
"var o = {foo: [4, 5, 6], bar: [3, 0]};");
20772 CHECK_EQ(3, cow_arrays_created_runtime - initial_cow_arrays);
20773 CompileRun(
"var o = {foo: [1, 2, 3, [4, 5, 6]], bar: 'hi'};");
20774 CHECK_EQ(4, cow_arrays_created_runtime - initial_cow_arrays);
20805 void* data =
reinterpret_cast<void*
>(0xacce55ed + slot);
20806 isolate->
SetData(slot, data);
20809 void* data =
reinterpret_cast<void*
>(0xacce55ed + slot);
20814 void* data =
reinterpret_cast<void*
>(0xdecea5ed + slot);
20815 isolate->
SetData(slot, data);
20818 void* data =
reinterpret_cast<void*
>(0xdecea5ed + slot);
20837 static int instance_checked_getter_count = 0;
20838 static void InstanceCheckedGetter(
20839 Local<String> name,
20842 instance_checked_getter_count++;
20847 static int instance_checked_setter_count = 0;
20848 static void InstanceCheckedSetter(Local<String> name,
20849 Local<Value> value,
20853 instance_checked_setter_count++;
20857 static void CheckInstanceCheckedResult(
int getters,
20859 bool expects_callbacks,
20860 TryCatch* try_catch) {
20861 if (expects_callbacks) {
20862 CHECK(!try_catch->HasCaught());
20863 CHECK_EQ(getters, instance_checked_getter_count);
20864 CHECK_EQ(setters, instance_checked_setter_count);
20866 CHECK(try_catch->HasCaught());
20867 CHECK_EQ(0, instance_checked_getter_count);
20868 CHECK_EQ(0, instance_checked_setter_count);
20870 try_catch->Reset();
20874 static void CheckInstanceCheckedAccessors(
bool expects_callbacks) {
20875 instance_checked_getter_count = 0;
20876 instance_checked_setter_count = 0;
20877 TryCatch try_catch;
20880 CompileRun(
"obj.foo");
20881 CheckInstanceCheckedResult(1, 0, expects_callbacks, &try_catch);
20882 CompileRun(
"obj.foo = 23");
20883 CheckInstanceCheckedResult(1, 1, expects_callbacks, &try_catch);
20886 CompileRun(
"function test_get(o) { o.foo; }"
20888 CheckInstanceCheckedResult(2, 1, expects_callbacks, &try_catch);
20889 CompileRun(
"test_get(obj);");
20890 CheckInstanceCheckedResult(3, 1, expects_callbacks, &try_catch);
20891 CompileRun(
"test_get(obj);");
20892 CheckInstanceCheckedResult(4, 1, expects_callbacks, &try_catch);
20893 CompileRun(
"function test_set(o) { o.foo = 23; }"
20895 CheckInstanceCheckedResult(4, 2, expects_callbacks, &try_catch);
20896 CompileRun(
"test_set(obj);");
20897 CheckInstanceCheckedResult(4, 3, expects_callbacks, &try_catch);
20898 CompileRun(
"test_set(obj);");
20899 CheckInstanceCheckedResult(4, 4, expects_callbacks, &try_catch);
20902 CompileRun(
"%OptimizeFunctionOnNextCall(test_get);"
20904 CheckInstanceCheckedResult(5, 4, expects_callbacks, &try_catch);
20905 CompileRun(
"%OptimizeFunctionOnNextCall(test_set);"
20907 CheckInstanceCheckedResult(5, 5, expects_callbacks, &try_catch);
20910 CompileRun(
"%DeoptimizeFunction(test_get);"
20911 "%ClearFunctionTypeFeedback(test_get);"
20912 "%DeoptimizeFunction(test_set);"
20913 "%ClearFunctionTypeFeedback(test_set);");
20918 v8::internal::FLAG_allow_natives_syntax =
true;
20922 Local<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
20923 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20924 inst->SetAccessor(v8_str(
"foo"),
20925 InstanceCheckedGetter, InstanceCheckedSetter,
20930 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
20932 printf(
"Testing positive ...\n");
20933 CompileRun(
"var obj = new f();");
20934 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20935 CheckInstanceCheckedAccessors(
true);
20937 printf(
"Testing negative ...\n");
20938 CompileRun(
"var obj = {};"
20939 "obj.__proto__ = new f();");
20940 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20941 CheckInstanceCheckedAccessors(
false);
20946 v8::internal::FLAG_allow_natives_syntax =
true;
20950 Local<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
20951 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20953 inst->SetAccessor(v8_str(
"foo"),
20954 InstanceCheckedGetter, InstanceCheckedSetter,
20959 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
20961 printf(
"Testing positive ...\n");
20962 CompileRun(
"var obj = new f();");
20963 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20964 CheckInstanceCheckedAccessors(
true);
20966 printf(
"Testing negative ...\n");
20967 CompileRun(
"var obj = {};"
20968 "obj.__proto__ = new f();");
20969 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20970 CheckInstanceCheckedAccessors(
false);
20975 v8::internal::FLAG_allow_natives_syntax =
true;
20979 Local<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
20980 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
20981 proto->SetAccessor(v8_str(
"foo"),
20982 InstanceCheckedGetter, InstanceCheckedSetter,
20987 context->
Global()->Set(v8_str(
"f"), templ->GetFunction());
20989 printf(
"Testing positive ...\n");
20990 CompileRun(
"var obj = new f();");
20991 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20992 CheckInstanceCheckedAccessors(
true);
20994 printf(
"Testing negative ...\n");
20995 CompileRun(
"var obj = {};"
20996 "obj.__proto__ = new f();");
20997 CHECK(!templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
20998 CheckInstanceCheckedAccessors(
false);
21000 printf(
"Testing positive with modified prototype chain ...\n");
21001 CompileRun(
"var obj = new f();"
21003 "pro.__proto__ = obj.__proto__;"
21004 "obj.__proto__ = pro;");
21005 CHECK(templ->HasInstance(context->
Global()->Get(v8_str(
"obj"))));
21006 CheckInstanceCheckedAccessors(
true);
21017 TryCatch try_catch;
21018 const char* trigger_ic =
21020 " throw new Error('test'); \n"
21025 CompileRun(trigger_ic);
21026 CHECK(try_catch.HasCaught());
21027 Local<Message> message = try_catch.Message();
21028 CHECK(!message.IsEmpty());
21029 CHECK_EQ(2, message->GetLineNumber());
21035 TryCatch try_catch;
21036 const char* throw_again =
21038 " throw new Error('test'); \n"
21042 " throw new Error('again'); \n"
21044 CompileRun(throw_again);
21045 CHECK(try_catch.HasCaught());
21046 Local<Message> message = try_catch.Message();
21047 CHECK(!message.IsEmpty());
21048 CHECK_EQ(6, message->GetLineNumber());
21053 static void Helper137002(
bool do_store,
21055 bool remove_accessor,
21056 bool interceptor) {
21058 Local<ObjectTemplate> templ = ObjectTemplate::New(context->
GetIsolate());
21062 templ->SetAccessor(v8_str(
"foo"),
21063 GetterWhichReturns42,
21064 SetterWhichSetsYOnThisTo23);
21066 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
21070 CompileRun(do_store ?
21071 "function f(x) { x.foo = void 0; }" :
21072 "function f(x) { return x.foo; }");
21073 CompileRun(
"obj.y = void 0;");
21074 if (!interceptor) {
21075 CompileRun(
"%OptimizeObjectForAddingMultipleProperties(obj, 1);");
21077 CompileRun(
"obj.__proto__ = null;"
21078 "f(obj); f(obj); f(obj);");
21080 CompileRun(
"f({});");
21082 CompileRun(
"obj.y = void 0;"
21083 "%OptimizeFunctionOnNextCall(f);");
21084 if (remove_accessor) {
21085 CompileRun(
"delete obj.foo;");
21087 CompileRun(
"var result = f(obj);");
21089 CompileRun(
"result = obj.y;");
21091 if (remove_accessor && !interceptor) {
21092 CHECK(context->
Global()->Get(v8_str(
"result"))->IsUndefined());
21095 context->
Global()->Get(v8_str(
"result"))->Int32Value());
21101 i::FLAG_allow_natives_syntax =
true;
21102 i::FLAG_compilation_cache =
false;
21104 for (
int i = 0; i < 16; i++) {
21105 Helper137002(i & 8, i & 4, i & 2, i & 1);
21111 i::FLAG_allow_natives_syntax =
true;
21115 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
21116 templ->SetAccessor(v8_str(
"foo"),
21117 GetterWhichReturns42,
21118 SetterWhichSetsYOnThisTo23);
21119 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
21123 CompileRun(
"function load(x) { return x.foo; }"
21124 "function store(x) { x.foo = void 0; }"
21125 "function keyed_load(x, key) { return x[key]; }"
21129 "function load2(x) { void 0; return x.foo; }"
21130 "function store2(x) { void 0; x.foo = void 0; }"
21131 "function keyed_load2(x, key) { void 0; return x[key]; }"
21134 "obj.__proto__ = null;"
21136 "subobj.y = void 0;"
21137 "subobj.__proto__ = obj;"
21138 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
21141 "load(obj); load(obj);"
21142 "load2(subobj); load2(subobj);"
21143 "store(obj); store(obj);"
21144 "store2(subobj); store2(subobj);"
21145 "keyed_load(obj, 'foo'); keyed_load(obj, 'foo');"
21146 "keyed_load2(subobj, 'foo'); keyed_load2(subobj, 'foo');"
21154 "keyed_load(obj, 'foo');"
21155 "keyed_load2(subobj, 'foo');"
21160 "subobj.y = void 0;"
21162 "var load_result = load(obj);"
21163 "var load_result2 = load2(subobj);"
21164 "var keyed_load_result = keyed_load(obj, 'foo');"
21165 "var keyed_load_result2 = keyed_load2(subobj, 'foo');"
21168 "var y_from_obj = obj.y;"
21169 "var y_from_subobj = subobj.y;");
21170 CHECK(context->
Global()->Get(v8_str(
"load_result"))->IsUndefined());
21171 CHECK(context->
Global()->Get(v8_str(
"load_result2"))->IsUndefined());
21172 CHECK(context->
Global()->Get(v8_str(
"keyed_load_result"))->IsUndefined());
21173 CHECK(context->
Global()->Get(v8_str(
"keyed_load_result2"))->IsUndefined());
21174 CHECK(context->
Global()->Get(v8_str(
"y_from_obj"))->IsUndefined());
21175 CHECK(context->
Global()->Get(v8_str(
"y_from_subobj"))->IsUndefined());
21180 i::FLAG_allow_natives_syntax =
true;
21184 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
21185 templ->SetAccessor(v8_str(
"foo"),
21186 GetterWhichReturns42,
21187 SetterWhichSetsYOnThisTo23);
21188 context->
Global()->Set(v8_str(
"obj"), templ->NewInstance());
21190 CompileRun(
"function load(x) { return x.foo; }"
21191 "var o = Object.create(obj);"
21192 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
21193 "load(o); load(o); load(o); load(o);");
21198 i::FLAG_expose_gc =
true;
21204 TryCatch try_catch;
21205 try_catch.SetVerbose(
true);
21206 CompileRun(
"try { throw new Error(); } finally { gc(); }");
21207 CHECK(try_catch.HasCaught());
21214 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
21216 context->
Global()->Set(v8_str(
"Bug"), templ->GetFunction());
21217 CompileRun(
"Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
21225 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
21226 Local<Object> obj = templ->NewInstance();
21228 obj->DeleteHiddenValue(v8_str(
"Bug"));
21233 i::FLAG_harmony_collections =
true;
21236 Local<Value> set_value = CompileRun(
"new Set();");
21238 CHECK_EQ(0, set_object->InternalFieldCount());
21239 Local<Value> map_value = CompileRun(
"new Map();");
21241 CHECK_EQ(0, map_object->InternalFieldCount());
21249 Local<Object> obj = Object::New(isolate);
21250 Local<String> key = String::NewFromUtf8(context->
GetIsolate(),
"key");
21252 Local<Value> value = obj->GetHiddenValue(key);
21253 CHECK(!value.IsEmpty());
21254 CHECK(value->IsUndefined());
21262 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate,
21264 CompileRun(
"for (var i = 0; i < 128; i++) Object.prototype[i] = 0;");
21265 Local<Function>
function = templ->GetFunction();
21266 CHECK(!
function.IsEmpty());
21267 CHECK(function->IsFunction());
21275 Handle<Object> global = context->
Global();
21276 global->Set(v8_str(
"obj"), obj);
21277 ExpectString(
"JSON.stringify(obj)",
"{\"x\":42}");
21285 Handle<Object> global = context->
Global();
21286 global->Set(v8_str(
"obj"), obj);
21287 ExpectString(
"JSON.stringify(obj)",
"42");
21292 class ThreadInterruptTest {
21294 ThreadInterruptTest() : sem_(0), sem_value_(0) { }
21295 ~ThreadInterruptTest() {}
21298 InterruptThread i_thread(
this);
21302 CHECK_EQ(kExpectedValue, sem_value_);
21306 static const int kExpectedValue = 1;
21308 class InterruptThread :
public i::Thread {
21310 explicit InterruptThread(ThreadInterruptTest* test)
21311 : Thread(
"InterruptThread"), test_(test) {}
21313 virtual void Run() {
21314 struct sigaction action;
21320 memset(&action, 0,
sizeof(action));
21321 action.sa_handler = SignalHandler;
21322 sigaction(SIGCHLD, &action,
NULL);
21325 kill(getpid(), SIGCHLD);
21331 test_->sem_value_ = 1;
21332 test_->sem_.Signal();
21335 static void SignalHandler(
int signal) {
21339 ThreadInterruptTest* test_;
21343 volatile int sem_value_;
21348 ThreadInterruptTest().RunTest();
21352 #endif // V8_OS_POSIX
21355 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global,
21358 Local<Value> data) {
21364 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global,
21367 Local<Value> data) {
21368 i::PrintF(
"Indexed access blocked.\n");
21388 IndexAccessAlwaysBlocked);
21393 global0->
Set(v8_str(
"x"), v8_num(42));
21394 ExpectString(
"JSON.stringify(this)",
"{\"x\":42}");
21396 for (
int i = 0; i < 2; i++) {
21407 context1->
Global()->Set(v8_str(
"other"), global0);
21409 ExpectString(
"JSON.stringify(other)",
"{}");
21410 ExpectString(
"JSON.stringify({ 'a' : other, 'b' : ['c'] })",
21411 "{\"a\":{},\"b\":[\"c\"]}");
21412 ExpectString(
"JSON.stringify([other, 'b', 'c'])",
21413 "[{},\"b\",\"c\"]");
21416 array->
Set(0, v8_str(
"a"));
21417 array->
Set(1, v8_str(
"b"));
21418 context1->
Global()->Set(v8_str(
"array"), array);
21419 ExpectString(
"JSON.stringify(array)",
"[\"a\",\"b\"]");
21421 ExpectString(
"JSON.stringify(array)",
"[]");
21422 ExpectString(
"JSON.stringify([array])",
"[[]]");
21423 ExpectString(
"JSON.stringify({'a' : array})",
"{\"a\":[]}");
21435 Local<v8::Value> data) {
21436 access_check_fail_thrown =
true;
21437 i::PrintF(
"Access check failed. Error thrown.\n");
21444 for (
int i = 0; i < args.
Length(); i++) {
21445 i::PrintF(
"%s\n", *String::Utf8Value(args[i]));
21447 catch_callback_called =
true;
21452 args[0]->ToObject()->HasOwnProperty(args[1]->ToString());
21460 access_check_fail_thrown =
false;
21461 catch_callback_called =
false;
21463 i::OS::SNPrintF(source,
"try { %s; } catch (e) { catcher(e); }", script);
21464 CompileRun(source.
start());
21465 CHECK(access_check_fail_thrown);
21466 CHECK(catch_callback_called);
21468 access_check_fail_thrown =
false;
21469 catch_callback_called =
false;
21470 CompileRun(
"try { [1, 2, 3].sort(); } catch (e) { catcher(e) };");
21471 CHECK(!access_check_fail_thrown);
21472 CHECK(!catch_callback_called);
21477 i::FLAG_allow_natives_syntax =
true;
21488 IndexAccessAlwaysBlocked);
21492 context0->
Global()->Set(v8_str(
"x"), v8_num(42));
21498 context1->
Global()->Set(v8_str(
"other"), global0);
21506 context1->
Global()->Set(v8_str(
"has_own_property"),
21510 access_check_fail_thrown =
false;
21511 CompileRun(
"other.x;");
21512 CHECK(access_check_fail_thrown);
21533 "other, 'x', null, null, 1)");
21542 i::FLAG_allow_natives_syntax =
true;
21545 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->
GetIsolate());
21547 context->
Global()->Set(v8_str(
"Bug"), templ->GetFunction());
21548 CompileRun(
"\"use strict\"; var o = new Bug;"
21549 "function f(o) { o.x = 10; };"
21550 "f(o); f(o); f(o);"
21551 "%OptimizeFunctionOnNextCall(f);"
21553 ExpectBoolean(
"%GetOptimizationStatus(f) != 2",
true);
21558 i::FLAG_allow_natives_syntax =
true;
21560 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
21563 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
21564 CompileRun(
"var obj = new Obj;"
21567 "obj.accessor_age = 42;"
21568 "function setter(i) { this.accessor_age = i; };"
21569 "function getter() { return this.accessor_age; };"
21570 "function setAge(i) { obj.age = i; };"
21571 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
21575 "%OptimizeFunctionOnNextCall(setAge);"
21578 ExpectInt32(
"obj.interceptor_age", 4);
21579 ExpectInt32(
"obj.accessor_age", 42);
21584 i::FLAG_allow_natives_syntax =
true;
21586 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
21589 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
21590 CompileRun(
"var obj = new Obj;"
21593 "obj.accessor_age = 42;"
21594 "function getter() { return this.accessor_age; };"
21595 "function getAge() { return obj.interceptor_age; };"
21596 "Object.defineProperty(obj, 'interceptor_age', { get:getter });"
21600 "%OptimizeFunctionOnNextCall(getAge);");
21602 ExpectInt32(
"getAge()", 1);
21607 i::FLAG_allow_natives_syntax =
true;
21609 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
21612 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
21613 CompileRun(
"var obj = new Obj;"
21614 "obj.__proto__.interceptor_age = 42;"
21616 "function getAge() { return obj.interceptor_age; };");
21617 ExpectInt32(
"getAge();", 100);
21618 ExpectInt32(
"getAge();", 100);
21619 ExpectInt32(
"getAge();", 100);
21620 CompileRun(
"%OptimizeFunctionOnNextCall(getAge);");
21622 ExpectInt32(
"getAge();", 100);
21627 i::FLAG_allow_natives_syntax =
true;
21629 Handle<FunctionTemplate> templ = FunctionTemplate::New(
CcTest::isolate());
21632 env->
Global()->Set(v8_str(
"Obj"), templ->GetFunction());
21633 CompileRun(
"var obj = new Obj;"
21634 "obj.age = 100000;"
21635 "function setAge(i) { obj.age = i };"
21639 "%OptimizeFunctionOnNextCall(setAge);"
21641 ExpectInt32(
"obj.age", 100000);
21642 ExpectInt32(
"obj.interceptor_age", 103);
21703 :
Thread(
"RequestInterruptTest"), test_(test) {}
21706 test_->
sem_.Wait();
21730 Local<Function> func = Function::New(
21732 env_->
Global()->Set(v8_str(
"ShouldContinue"), func);
21734 CompileRun(
"while (ShouldContinue()) { }");
21744 proto->
Set(v8_str(
"shouldContinue"), Function::New(
21748 CompileRun(
"var obj = new Klass; while (obj.shouldContinue()) { }");
21762 CompileRun(
"var obj = new Klass; while (obj.shouldContinue) { }");
21772 v8_str(
"shouldContinue"),
21773 &ShouldContinueNativeGetter,
21778 CompileRun(
"var obj = new Klass; while (obj.shouldContinue) { }");
21782 static void ShouldContinueNativeGetter(
21783 Local<String> property,
21799 proto->
Set(v8_str(
"shouldContinue"), Function::New(
21806 CompileRun(
"var obj = new Klass; while (obj.shouldContinue()) { }");
21810 static void EmptyInterceptor(
21811 Local<String> property,
21820 env_->
Global()->Set(v8_str(
"WakeUpInterruptor"), Function::New(
21822 WakeUpInterruptorCallback,
21825 env_->
Global()->Set(v8_str(
"ShouldContinue"), Function::New(
21827 ShouldContinueCallback,
21830 i::FLAG_allow_natives_syntax =
true;
21831 CompileRun(
"function loopish(o) {"
21833 " while (o.abs(1) > 0) {"
21834 " if (o.abs(1) >= 0 && !ShouldContinue()) break;"
21836 " if (--pre === 0) WakeUpInterruptor(o === Math);"
21841 "var obj = {abs: function () { return i-- }, x: null};"
21844 "%OptimizeFunctionOnNextCall(loopish);"
21847 i::FLAG_allow_natives_syntax =
false;
21851 static void WakeUpInterruptorCallback(
21853 if (!info[0]->BooleanValue())
return;
21861 static void ShouldContinueCallback(
21901 static Local<Value> function_new_expected_env;
21913 function_new_expected_env = data;
21914 Local<Function> func = Function::New(isolate, FunctionNewCallback, data);
21915 env->
Global()->Set(v8_str(
"func"), func);
21916 Local<Value> result = CompileRun(
"func();");
21919 int serial_number =
21921 ->shared()->get_api_func_data()->serial_number())->
value();
21926 CHECK(elm->IsUndefined());
21929 function_new_expected_env = data2;
21930 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
21931 CHECK(!func2->IsNull());
21933 env->
Global()->Set(v8_str(
"func2"), func2);
21934 Local<Value> result2 = CompileRun(
"func2();");
21942 const int runs = 10;
21943 Local<String> values[runs];
21944 for (
int i = 0; i < runs; i++) {
21946 Local<String> value;
21947 if (i != 0) value = v8_str(
"escape value");
21948 values[i] = inner_scope.
Escape(value);
21950 for (
int i = 0; i < runs; i++) {
21951 Local<String> expected;
21953 CHECK_EQ(v8_str(
"escape value"), values[i]);
21955 CHECK(values[i].IsEmpty());
21961 static void SetterWhichExpectsThisAndHolderToDiffer(
21971 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
21972 templ->SetAccessor(v8_str(
"x"), 0, SetterWhichExpectsThisAndHolderToDiffer);
21973 context->
Global()->Set(v8_str(
"P"), templ->NewInstance());
21978 "C1.prototype = P;"
21979 "for (var i = 0; i < 4; i++ ) {"
21987 static Local<Object> data;
21988 static Local<Object> receiver;
21989 static Local<Object> holder;
21990 static Local<Object> callee;
21993 static void OptimizationCallback(
21998 if (info.
Length() == 1) {
22016 for (
unsigned i = 0; i <
ARRAY_SIZE(signature_types); i++) {
22018 for (
int j = 0; j < 2; j++) {
22019 bool global = j == 0;
22020 int key = signature_type +
22021 ARRAY_SIZE(signature_types) * (global ? 1 : 0);
22022 Run(signature_type, global, key);
22031 Local<v8::ObjectTemplate> signature_template;
22032 Local<v8::Signature> signature;
22034 Local<v8::FunctionTemplate> parent_template =
22035 FunctionTemplate::New(isolate);
22036 parent_template->SetHiddenPrototype(
true);
22037 Local<v8::FunctionTemplate> function_template
22038 = FunctionTemplate::New(isolate);
22039 function_template->Inherit(parent_template);
22040 switch (signature_type) {
22050 signature_template = function_template->InstanceTemplate();
22053 Local<v8::Context> context =
22057 Local<Object> function_receiver = signature_template->NewInstance();
22058 context->Global()->Set(v8_str(
"function_receiver"), function_receiver);
22060 Local<Object> inner_global =
22063 data = Object::New(isolate);
22064 Local<FunctionTemplate> function_template = FunctionTemplate::New(
22065 isolate, OptimizationCallback, data, signature);
22066 Local<Function>
function = function_template->GetFunction();
22067 Local<Object> global_holder = inner_global;
22068 Local<Object> function_holder = function_receiver;
22073 global_holder->Set(v8_str(
"g_f"),
function);
22074 global_holder->SetAccessorProperty(v8_str(
"g_acc"),
function,
function);
22075 function_holder->Set(v8_str(
"f"),
function);
22076 function_holder->SetAccessorProperty(v8_str(
"acc"),
function,
function);
22081 receiver = context->Global();
22082 holder = inner_global;
22084 holder = function_receiver;
22089 "var receiver_subclass = {};\n"
22090 "receiver_subclass.__proto__ = function_receiver;\n"
22091 "receiver_subclass"));
22094 "var receiver_subclass = function_receiver;\n"
22095 "receiver_subclass"));
22099 if (signature_type ==
kNoSignature) holder = receiver;
22105 "function wrap_f_%d() { var f = g_f; return f(); }\n"
22106 "function wrap_get_%d() { return this.g_acc; }\n"
22107 "function wrap_set_%d() { return this.g_acc = 1; }\n",
22112 "function wrap_f_%d() { return receiver_subclass.f(); }\n"
22113 "function wrap_get_%d() { return receiver_subclass.acc; }\n"
22114 "function wrap_set_%d() { return receiver_subclass.acc = 1; }\n",
22122 "function wrap_f() { return wrap_f_%d(); }\n"
22123 "function wrap_get() { return wrap_get_%d(); }\n"
22124 "function wrap_set() { return wrap_set_%d(); }\n"
22125 "check = function(returned) {\n"
22126 " if (returned !== 'returned') { throw returned; }\n"
22129 "check(wrap_f());\n"
22130 "check(wrap_f());\n"
22131 "%%OptimizeFunctionOnNextCall(wrap_f_%d);\n"
22132 "check(wrap_f());\n"
22134 "check(wrap_get());\n"
22135 "check(wrap_get());\n"
22136 "%%OptimizeFunctionOnNextCall(wrap_get_%d);\n"
22137 "check(wrap_get());\n"
22139 "check = function(returned) {\n"
22140 " if (returned !== 1) { throw returned; }\n"
22142 "check(wrap_set());\n"
22143 "check(wrap_set());\n"
22144 "%%OptimizeFunctionOnNextCall(wrap_set_%d);\n"
22145 "check(wrap_set());\n",
22146 wrap_function.
start(), key, key, key, key, key, key);
22148 CompileRun(source.
start());
22149 ASSERT(!try_catch.HasCaught());
22155 Local<Object> ApiCallOptimizationChecker::data;
22156 Local<Object> ApiCallOptimizationChecker::receiver;
22157 Local<Object> ApiCallOptimizationChecker::holder;
22158 Local<Object> ApiCallOptimizationChecker::callee;
22159 int ApiCallOptimizationChecker::count = 0;
22163 i::FLAG_allow_natives_syntax =
true;
22169 static const char* last_event_message;
22170 static int last_event_status;
22172 last_event_message =
message;
22173 last_event_status = status;
22182 "V8.Test", 0, 10000, 50,
22183 reinterpret_cast<v8::internal::Isolate*>(isolate));
22184 histogramTimer->
Start();
22185 CHECK_EQ(
"V8.Test", last_event_message);
22187 histogramTimer->
Stop();
22188 CHECK_EQ(
"V8.Test", last_event_message);
22197 Handle<Object> global = context->
Global();
22202 Handle<v8::Promise> p = pr->GetPromise();
22203 Handle<v8::Promise> r = rr->GetPromise();
22206 CHECK(p->IsPromise());
22207 CHECK(r->IsPromise());
22209 CHECK(!o->IsPromise());
22213 CHECK(p->IsPromise());
22215 CHECK(r->IsPromise());
22221 "function f1(x) { x1 = x; return x+1 };\n"
22222 "function f2(x) { x2 = x; return x+1 };\n");
22223 Handle<Function>
f1 = Handle<Function>::Cast(global->Get(v8_str(
"f1")));
22224 Handle<Function>
f2 = Handle<Function>::Cast(global->Get(v8_str(
"f2")));
22227 CHECK_EQ(0, global->Get(v8_str(
"x1"))->Int32Value());
22228 V8::RunMicrotasks(isolate);
22229 CHECK_EQ(1, global->Get(v8_str(
"x1"))->Int32Value());
22232 V8::RunMicrotasks(isolate);
22233 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22236 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22237 V8::RunMicrotasks(isolate);
22238 CHECK_EQ(2, global->Get(v8_str(
"x2"))->Int32Value());
22241 V8::RunMicrotasks(isolate);
22242 CHECK_EQ(1, global->Get(v8_str(
"x1"))->Int32Value());
22245 CompileRun(
"x1 = x2 = 0;");
22249 pr->GetPromise()->Chain(f1);
22250 rr->GetPromise()->Catch(f2);
22251 V8::RunMicrotasks(isolate);
22252 CHECK_EQ(0, global->Get(v8_str(
"x1"))->Int32Value());
22253 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22257 CHECK_EQ(0, global->Get(v8_str(
"x1"))->Int32Value());
22258 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22260 V8::RunMicrotasks(isolate);
22261 CHECK_EQ(1, global->Get(v8_str(
"x1"))->Int32Value());
22262 CHECK_EQ(2, global->Get(v8_str(
"x2"))->Int32Value());
22265 CompileRun(
"x1 = x2 = 0;");
22267 pr->GetPromise()->Chain(f1)->Chain(f2);
22269 CHECK_EQ(0, global->Get(v8_str(
"x1"))->Int32Value());
22270 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22271 V8::RunMicrotasks(isolate);
22272 CHECK_EQ(3, global->Get(v8_str(
"x1"))->Int32Value());
22273 CHECK_EQ(4, global->Get(v8_str(
"x2"))->Int32Value());
22275 CompileRun(
"x1 = x2 = 0;");
22277 rr->GetPromise()->Catch(f1)->Chain(f2);
22279 CHECK_EQ(0, global->Get(v8_str(
"x1"))->Int32Value());
22280 CHECK_EQ(0, global->Get(v8_str(
"x2"))->Int32Value());
22281 V8::RunMicrotasks(isolate);
22282 CHECK_EQ(3, global->Get(v8_str(
"x1"))->Int32Value());
22283 CHECK_EQ(4, global->Get(v8_str(
"x2"))->Int32Value());
22287 TEST(DisallowJavascriptExecutionScope) {
22333 named_access_count = 0;
22334 CompileRun(
"friend.__proto__ = {};");
22336 CompileRun(
"friend.__proto__;");
22340 named_access_count = 0;
22341 CompileRun(
"var p = Object.prototype;"
22342 "var f = Object.getOwnPropertyDescriptor(p, '__proto__').set;"
22343 "f.call(friend, {});");
22345 CompileRun(
"var p = Object.prototype;"
22346 "var f = Object.getOwnPropertyDescriptor(p, '__proto__').get;"
22347 "f.call(friend);");
22351 named_access_count = 0;
22352 CompileRun(
"var f = Object.prototype.__lookupSetter__('__proto__');"
22353 "f.call(friend, {});");
22355 CompileRun(
"var f = Object.prototype.__lookupGetter__('__proto__');"
22356 "f.call(friend);");
22360 named_access_count = 0;
22361 CompileRun(
"Object.setPrototypeOf(friend, {});");
22363 CompileRun(
"Object.getPrototypeOf(friend);");
v8::DefaultPersistentValueMapTraits< K, V >::Impl Impl
static void RunAllTests()
V8_INLINE UniquePersistent Pass()
void DisposingCallback(const v8::WeakCallbackData< v8::Object, v8::Persistent< v8::Object > > &data)
void SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
v8::Handle< Value > keyed_call_ic_function
void RequestInterrupt(InterruptCallback callback, void *data)
static Local< Signature > New(Isolate *isolate, Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >(), int argc=0, Handle< FunctionTemplate > argv[]=0)
static Isolate * GetCurrent()
static Handle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attributes, StrictMode strict_mode, bool check_prototype=true, SetPropertyMode set_mode=SET_PROPERTY)
void ThrowFromC(const v8::FunctionCallbackInfo< v8::Value > &args)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static V8_INLINE Local< T > New(Isolate *isolate, Handle< T > that)
int prologue_call_count_alloc
static Local< Symbol > ForApi(Isolate *isolate, Local< String > name)
v8::Persistent< v8::Object > some_object
double NumberValue() const
static V8_INLINE Object * Cast(Value *obj)
void ThrowingDirectApiCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
static V8_INLINE Persistent< T > & Cast(Persistent< S > &that)
int GetLineNumber() const
void FlattenString(Handle< String > string)
void Fail(const v8::FunctionCallbackInfo< v8::Value > &args)
static void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
V8_INLINE void SetWrapperClassId(uint16_t class_id)
bool HasRealIndexedProperty(uint32_t index)
void CheckCorrectThrow(const char *script)
virtual ~RequestInterruptTestBase()
TestAsciiResourceWithDisposeControl(const char *data, bool dispose)
void set_max_young_space_size(int value)
Handle< String > NewExternalStringFromAscii(const ExternalAsciiString::Resource *resource)
#define CHECK_EQ(expected, value)
TEST(InitializeAndDisposeOnce)
void RunWithProfiler(void(*test)())
uint8_t * GetIndexedPropertiesPixelData()
v8::Handle< Value > call_ic_function
void CheckThisIndexedPropertySetter(uint32_t index, Local< Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
CpuProfiler * GetCpuProfiler()
void StoringErrorCallback(const char *location, const char *message)
static int NumberOfHandles(Isolate *isolate)
Local< Value > Call(Handle< Value > recv, int argc, Handle< Value > argv[])
void FastReturnValueCallback< uint32_t >(const v8::FunctionCallbackInfo< v8::Value > &info)
bool catch_callback_called
bool DeleteHiddenValue(Handle< String > key)
void(* CallCompletedCallback)()
void SetEventLogger(LogEventCallback that)
void EmptyInterceptorGetter(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
static void Echo(const v8::FunctionCallbackInfo< v8::Value > &args)
void CatcherCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
CompilationCache * compilation_cache()
Handle< FixedTypedArrayBase > NewFixedTypedArray(int length, ExternalArrayType array_type, PretenureFlag pretenure=NOT_TENURED)
Handle< String > InternalizeString(Handle< String > str)
void PrintF(const char *format,...)
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
static Local< Private > ForApi(Isolate *isolate, Local< String > name)
static Local< Value > New(bool value)
Thread(const Options &options)
virtual void TestBody()=0
bool InNewSpace(Object *object)
void SetSecurityToken(Handle< Value > token)
Local< Value > Exception() const
void HandleCreatingCallback(const v8::WeakCallbackData< v8::Object, v8::Persistent< v8::Object > > &data)
static MapCache * cast(Object *obj)
void CallCompletedCallbackNoException()
void(* FunctionCallback)(const FunctionCallbackInfo< Value > &info)
~SetFunctionEntryHookTest()
bool StrictEquals(Handle< Value > that) const
V8_INLINE Isolate * GetIsolate() const
static void SetAddHistogramSampleFunction(AddHistogramSampleCallback)
Local< Value > Get(Handle< Value > key)
void AnalyzeStackOfInlineScriptWithSourceURL(const v8::FunctionCallbackInfo< v8::Value > &args)
static Smi * FromInt(int value)
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
void V8_EXPORT RegisterExtension(Extension *extension)
PropertyAttribute GetPropertyAttributes(Handle< Value > key)
Local< Object > NewInstance()
Local< Array > GetOwnPropertyNames()
V8_INLINE ReturnValue< T > GetReturnValue() const
v8::Persistent< v8::Object > to_be_disposed
int echo_named_call_count
bool SameValue(Handle< Value > that) const
void OnEntryHook(uintptr_t function, uintptr_t return_addr_location)
void HasOwnPropertyNamedPropertyQuery(Local< String > property, const v8::PropertyCallbackInfo< v8::Integer > &info)
bool IsBooleanObject() const
static Handle< T > cast(Handle< S > that)
Local< String > Get() const
void NewPersistentHandleCallback(const v8::WeakCallbackData< v8::Object, v8::Persistent< v8::Object > > &data)
static void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit=10, StackTrace::StackTraceOptions options=StackTrace::kOverview)
void AllowCodeGenerationFromStrings(bool allow)
static v8::internal::Handle< v8::internal::Object > OpenPersistent(const v8::Persistent< T > &persistent)
bool DeletePrivate(Handle< Private > key)
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_INLINE void * GetAlignedPointerFromEmbedderData(int index)
V8_INLINE int Length() const
void FastReturnValueCallback(const v8::FunctionCallbackInfo< v8::Value > &info)
Local< ObjectTemplate > InstanceTemplate()
void OnJitEvent(const v8::JitCodeEvent *event)
SetFunctionEntryHookTest()
kSerializedDataOffset Object
bool IsSymbolObject() const
TestResource(uint16_t *data, int *counter=NULL, bool owning_data=true)
Local< Value > ThrowException(Local< Value > exception)
V8_INLINE Local< Function > Callee() const
static void DisableAutomaticDispose()
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
void FastReturnValueCallback< int32_t >(const v8::FunctionCallbackInfo< v8::Value > &info)
static V8_INLINE uint32_t GetNumberOfDataSlots()
static v8::Local< v8::Object > global()
bool HasRealNamedCallbackProperty(Handle< String > key)
Local< Value > GetHiddenValue(Handle< String > key)
void RunBeforeGC(v8::GCType type, v8::GCCallbackFlags flags)
V8_INLINE Local< Object > Holder() const
static void EnqueueMicrotask(Isolate *isolate, Handle< Function > microtask)
InvocationMap invocations_
void CheckThisIndexedPropertyDeleter(uint32_t index, const v8::PropertyCallbackInfo< v8::Boolean > &info)
static Handle< Object > GetElementNoExceptionThrown(Isolate *isolate, Handle< Object > object, uint32_t index)
static Local< Value > Error(Handle< String > message)
void FastReturnValueCallback< Object >(const v8::FunctionCallbackInfo< v8::Value > &info)
bool SetPrivate(Handle< Private > key, Handle< Value > value)
V8_INLINE Local< T > Escape(Local< T > value)
void AnalyzeStackOfEvalWithSourceURL(const v8::FunctionCallbackInfo< v8::Value > &args)
Local< Array > GetPropertyNames()
ExternalArrayType GetIndexedPropertiesExternalArrayDataType()
void EpilogueCallbackAlloc(v8::Isolate *isolate, v8::GCType, v8::GCCallbackFlags flags)
Local< Context > GetCurrentContext()
void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter=kGCTypeAll)
virtual void VisitExternalString(v8::Handle< v8::String > string)
void EpilogueCallbackSecond(v8::GCType, v8::GCCallbackFlags flags)
void FastReturnValueCallback< void >(const v8::FunctionCallbackInfo< v8::Value > &info)
V8_INLINE void Set(const Persistent< S > &handle)
#define ASSERT(condition)
Local< Number > ToNumber() const
~ScopedArrayBufferContents()
static const int kReduceMemoryFootprintMask
Handle< Value > GetDisplayName() const
void(* AccessorSetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
void * GetIndexedPropertiesExternalArrayData()
v8::Handle< Script > call_recursively_script
void TryCatchMixedNestingCheck(v8::TryCatch *try_catch)
std::map< std::pair< SymbolInfo *, SymbolInfo * >, int > InvocationMap
static Local< Integer > New(Isolate *isolate, int32_t value)
V8_INLINE Local< Value > GetInternalField(int index)
void HasOwnPropertyAccessorGetter(Local< String > property, const v8::PropertyCallbackInfo< v8::Value > &info)
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
Local< String > ToString() const
InterruptThread(RequestInterruptTestBase *test)
VisitorImpl(TestResource **resource)
void CThrowCountDown(const v8::FunctionCallbackInfo< v8::Value > &args)
Local< Script > BindToCurrentContext()
#define THREADED_PROFILED_TEST(Name)
static K KeyFromWeakCallbackData(const v8::WeakCallbackData< V, WeakCallbackDataType > &data)
static const int kNoScriptIdInfo
V8_INLINE bool IsConstructCall() const
void ThrowingDirectGetterCallback(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
void SetVerbose(bool value)
virtual size_t length() const
static Local< StackTrace > CurrentStackTrace(Isolate *isolate, int frame_limit, StackTraceOptions options=kOverview)
virtual const char * data() const
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
void CheckThisIndexedPropertyEnumerator(const v8::PropertyCallbackInfo< v8::Array > &info)
static ExternalAsciiString * cast(Object *obj)
UC16VectorResource * string_resource
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing 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 statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage message
Handle< Value > GetName() const
static V8_INLINE Symbol * Cast(v8::Value *obj)
static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback)
void SetIndexedPropertiesToExternalArrayData(void *data, ExternalArrayType array_type, int number_of_elements)
void DirectApiCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing 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 statistics of the maximum memory committed for the heap in name
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
bool Equals(Handle< Value > that) const
void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
void HasOwnPropertyCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
V8_INLINE P * ClearWeak()
static void VisitExternalResources(ExternalResourceVisitor *visitor)
static V8_INLINE Number * Cast(v8::Value *obj)
v8::Handle< Value > call_ic_function3
void RunLoopInNewEnv(v8::Isolate *isolate)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing 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 statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including flags
void CallCompletedCallbackException()
void HandleF(const v8::FunctionCallbackInfo< v8::Value > &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)
static void JitEvent(const v8::JitCodeEvent *event)
static V8_INLINE SymbolObject * Cast(v8::Value *obj)
bool HasIndexedPropertiesInExternalArrayData()
bool HasPrivate(Handle< Private > key)
v8::Isolate * GetIsolate()
bool Equals(String *other)
static Local< UnboundScript > CompileUnbound(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions)
v8::Persistent< Value > xValue
void GetHeapStatistics(HeapStatistics *heap_statistics)
void SetNamedPropertyHandler(NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter=0, NamedPropertyQueryCallback query=0, NamedPropertyDeleterCallback deleter=0, NamedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
void SetInternalField(int index, Handle< Value > value)
WeakCallCounterAndPersistent(WeakCallCounter *counter)
kInstanceClassNameOffset flag
void SetClassName(Handle< String > name)
StackGuard * stack_guard()
bool HasTerminated() const
void StartCpuProfiling(Handle< String > title, bool record_samples=false)
void CheckCodeGenerationAllowed()
void PrologueCallbackSecond(v8::GCType, v8::GCCallbackFlags flags)
V8_INLINE Handle< Boolean > True(Isolate *isolate)
Local< StackFrame > GetFrame(uint32_t index) const
static const char * GetVersion()
static bool IsLocked(Isolate *isolate)
bool IsExternalAscii() const
static void TerminateExecution(Isolate *isolate=NULL)
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
RegExpInterruptionThread(v8::Isolate *isolate)
void CheckThisNamedPropertyQuery(Local< String > property, const v8::PropertyCallbackInfo< v8::Integer > &info)
bool IsStringObject() const
uint32_t ComputePointerHash(void *ptr)
ScriptOrigin GetScriptOrigin() const
V8_INLINE bool IsNull() const
void SimpleAccessorGetter(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
bool access_check_fail_thrown
static bool AddMessageListener(MessageCallback that, Handle< Value > data=Handle< Value >())
void EnsureHeapIsIterable()
void RemoveGCPrologueCallback(GCPrologueCallback callback)
virtual const char * Data()=0
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths true
void CheckCodeGenerationDisallowed()
static void RemoveCallCompletedCallback(CallCompletedCallback callback)
std::map< i::Address, SymbolInfo * > SymbolLocationMap
void set_max_old_space_size(int value)
V8_INLINE Local< Value > Data() const
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
void FooSetInterceptor(Local< String > name, Local< Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
WeakCallCounter * counter
static Local< ObjectTemplate > New()
virtual bool HasError()=0
bool HasIndexedPropertiesInPixelData()
i::Handle< i::JSFunction > bar_func_
static void SetJitCodeEventHandler(JitCodeEventOptions options, JitCodeEventHandler event_handler)
Handle< Value > ReThrow()
V8_INLINE Isolate * GetIsolate() const
static void MemCopy(void *dest, const void *src, size_t size)
bool V8_EXPORT SetResourceConstraints(Isolate *isolate, ResourceConstraints *constraints)
void SimpleAccessorSetter(Local< String > name, Local< Value > value, const v8::PropertyCallbackInfo< void > &info)
Local< Value > GetPrototype()
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< String > name)
static bool IsValid(intptr_t value)
void set_resource(const Resource *buffer)
void PrologueCallback(v8::GCType, v8::GCCallbackFlags flags)
v8::Isolate * gc_callbacks_isolate
void CollectAllAvailableGarbage(const char *gc_reason=NULL)
static const int kMinValue
bool ForceDelete(Handle< Value > key)
bool ToArrayIndex(uint32_t *index)
v8::Handle< v8::Object > bottom
void CallCompletedCallback1()
byte * instruction_start()
static const int kNoGCFlags
static Handle< Map > GetElementsTransitionMap(Handle< JSObject > object, ElementsKind to_kind)
V8_INLINE bool IsIndependent() const
void CheckProperties(v8::Isolate *isolate, v8::Handle< v8::Value > val, int elmc, const char *elmv[])
virtual ~AsciiVectorResource()
static Local< External > New(Isolate *isolate, void *value)
uint32_t occupancy() const
V8_INLINE Local< Object > Holder() const
void JSCheck(const v8::FunctionCallbackInfo< v8::Value > &args)
void SetInternalFieldCount(int value)
TestAsciiResource(const char *data, int *counter=NULL, size_t offset=0)
Local< Value > GetPrivate(Handle< Private > key)
NativeFunctionExtension(const char *name, const char *source, v8::FunctionCallback fun=&Echo)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
i::Handle< i::JSFunction > foo_func_
static void SetFatalErrorHandler(FatalErrorCallback that)
static int ContextDisposedNotification()
bool CodeGenerationDisallowed(Local< Context > context)
void FastReturnValueCallback< double >(const v8::FunctionCallbackInfo< v8::Value > &info)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
V8_INLINE void SetData(uint32_t slot, void *data)
int32_t Int32Value() const
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *script_data=NULL)
void Version(const v8::FunctionCallbackInfo< v8::Value > &args)
Local< Object > NewInstance() const
void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo< v8::Value > &args)
IsolateThread(v8::Isolate *isolate, int fib_limit)
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_THROWS, false > ThrowOnJavascriptExecution
struct RegExpInterruptionData regexp_interruption_data
bool IsSharedCrossOrigin() const
bool IsConstructor() const
static Local< Value > New(Isolate *isolate, Handle< Symbol > value)
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
static V8_INLINE Handle< T > Cast(Handle< S > that)
Handle< ExternalArray > NewExternalArray(int length, ExternalArrayType array_type, void *external_pointer, PretenureFlag pretenure=NOT_TENURED)
static FunctionTemplateInfo * cast(Object *obj)
void SetIndexedPropertiesToPixelData(uint8_t *data, int length)
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
Handle< Value > TestFastReturnValues()
Handle< FixedArray > NewFixedArray(int size, PretenureFlag pretenure=NOT_TENURED)
void HasOwnPropertyIndexedPropertyQuery(uint32_t index, const v8::PropertyCallbackInfo< v8::Integer > &info)
ScopedArrayBufferContents(const v8::ArrayBuffer::Contents &contents)
V8_INLINE ReturnValue< T > GetReturnValue() const
int prologue_call_count_second
void TypedArrayTestHelper(v8::ExternalArrayType array_type, int64_t low, int64_t high)
void UnboxedDoubleIndexedPropertyEnumerator(const v8::PropertyCallbackInfo< v8::Array > &info)
int GetScriptColumnNumber() const
static i::Isolate * i_isolate()
static void RemoveMessageListeners(MessageCallback that)
const uint16_t * data() const
static Code * GetCodeFromTargetAddress(Address address)
V8_INLINE Local< Object > This() const
v8::Persistent< v8::String > string
int CountInvocations(const char *caller_name, const char *function_name)
void SloppyArgsIndexedPropertyEnumerator(const v8::PropertyCallbackInfo< v8::Array > &info)
bool SetHiddenValue(Handle< String > key, Handle< Value > value)
void CheckThisNamedPropertyEnumerator(const v8::PropertyCallbackInfo< v8::Array > &info)
void set_stack_limit(uint32_t *value)
static const int kMakeHeapIterableMask
void SetAlignedPointerInEmbedderData(int index, void *value)
Local< Symbol > ValueOf() const
void HasOwnPropertyNamedPropertyQuery2(Local< String > property, const v8::PropertyCallbackInfo< v8::Integer > &info)
int global_handles_count() const
static V8_INLINE String * Cast(v8::Value *obj)
void FailedAccessCheckCallbackGC(Local< v8::Object > target, v8::AccessType type, Local< v8::Value > data)
bool BooleanValue() const
static V8_INLINE External * Cast(Value *obj)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< v8::String > name)
static Local< Number > New(Isolate *isolate, double value)
void FailedAccessCheckThrows(Local< v8::Object > target, v8::AccessType type, Local< v8::Value > data)
void set_resource(const Resource *buffer)
static Local< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, NewStringType type=kNormalString, int length=-1)
bool SetPrototype(Handle< Value > prototype)
void CheckThisNamedPropertyDeleter(Local< String > property, const v8::PropertyCallbackInfo< v8::Boolean > &info)
static Local< Array > New(Isolate *isolate, int length=0)
V8_INLINE bool IsUndefined() const
int GetLineNumber() const
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
V8_INLINE Handle< Primitive > Undefined(Isolate *isolate)
static Local< Value > RangeError(Handle< String > message)
#define CHECK_NE(unexpected, value)
static V8_INLINE Local< Object > Cast(Local< S > that)
void SetHiddenPrototype(bool value)
V8_INLINE uint16_t WrapperClassId() const
static void Sleep(const int milliseconds)
static const int kAbortIncrementalMarkingMask
Vector< const char > CStrVector(const char *data)
bool CollectGarbage(AllocationSpace space, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
V8_INLINE P * GetParameter() const
int StrLength(const char *string)
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static Local< Object > New(Isolate *isolate)
static void Print(const char *format,...)
void DisposeAndForceGcCallback(const v8::WeakCallbackData< v8::Object, v8::Persistent< v8::Object > > &data)
#define T(name, string, precedence)
static void AddCallCompletedCallback(CallCompletedCallback callback)
void HasOwnPropertyIndexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo< v8::Value > &info)
Local< String > GetScriptName() const
static bool SetFunctionEntryHook(Isolate *isolate, FunctionEntryHook entry_hook)
void FastReturnValueCallback< bool >(const v8::FunctionCallbackInfo< v8::Value > &info)
V8_INLINE bool IsString() const
static Local< Value > New(Isolate *isolate, double value)
size_t ByteLength() const
std::map< size_t, SymbolInfo > SymbolMap
static Local< Value > New(Isolate *isolate, double time)
void Run(SignatureType signature_type, bool global, int key)
void ExtArrayLimitsHelper(v8::Isolate *isolate, v8::ExternalArrayType array_type, int size)
void EpilogueCallback(v8::GCType, v8::GCCallbackFlags flags)
bool IsCodeGenerationFromStringsAllowed()
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static Local< Value > ReferenceError(Handle< String > message)
void FooGetInterceptor(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
virtual ~UC16VectorResource()
static int SNPrintF(Vector< char > str, const char *format,...)
Local< Value > StackTrace() const
static Local< DataView > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array shift
void GetThisX(const v8::FunctionCallbackInfo< v8::Value > &info)
void CheckThisIndexedPropertyQuery(uint32_t index, const v8::PropertyCallbackInfo< v8::Integer > &info)
static void RuntimeCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
static Local< RegExp > New(Handle< String > pattern, Flags flags)
int ToNumber(Register reg)
V8_INLINE Handle< Boolean > False(Isolate *isolate)
v8::Persistent< T > handle
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
int GetIndexedPropertiesExternalArrayDataLength()
void CCatcher(const v8::FunctionCallbackInfo< v8::Value > &args)
uint32_t Uint32Value() const
static double nan_value()
V8_INLINE Local< S > As()
v8::Persistent< v8::Object > handle
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
V8_INLINE Local< Object > This() const
Handle< T > handle(T *t, Isolate *isolate)
V8_INLINE bool IsEmpty() const
void RecursiveCall(const v8::FunctionCallbackInfo< v8::Value > &args)
void CallCompletedCallback2()
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
#define IS_ARRAY_BUFFER_VIEW_TEST(View)
Local< Function > GetFunction()
void CheckVisitedResources()
static RegisterThreadedTest * nth(int i)
StrongMapTraits< K, V >::Impl Impl
bool ForceSet(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
int GetUtf8Length(Handle< String > str)
void InsertSymbolAt(i::Address addr, SymbolInfo *symbol)
V8_INLINE bool IsEmpty() const
static Local< Value > SyntaxError(Handle< String > message)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
static Local< String > NewExternal(Isolate *isolate, ExternalStringResource *resource)
void AnalyzeStackOfDynamicScriptWithSourceURL(const v8::FunctionCallbackInfo< v8::Value > &args)
Local< Value > GetBoundFunction() const
v8::Persistent< v8::Object > bad_handle
static SetFunctionEntryHookTest * instance_
virtual const i::uc16 * data() const
static const bool kIsWeak
V8_INLINE void * GetData(uint32_t slot)
void * Remove(void *key, uint32_t hash)
Local< Value > Name() const
AsciiVectorResource(i::Vector< const char > vector)
const char * data() const
int GetIndexedPropertiesPixelDataLength()
Local< ObjectTemplate > PrototypeTemplate()
static void VisitHandlesWithClassIds(PersistentHandleVisitor *visitor)
#define ASSERT_EQ(v1, v2)
SymbolInfo * FindSymbolForAddr(i::Address addr)
static Local< Value > TypeError(Handle< String > message)
V8_INLINE Isolate * GetIsolate()
void WithTryCatch(const v8::FunctionCallbackInfo< v8::Value > &args)
int GetScriptLineNumber() const
static Local< Resolver > New(Isolate *isolate)
virtual size_t length() const
static void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
Handle< StackTrace > GetStackTrace() const
InitDefaultIsolateThread(TestCase testCase)
static void VisitHandlesForPartialDependence(Isolate *isolate, PersistentHandleVisitor *visitor)
static void SetCreateHistogramFunction(CreateHistogramCallback)
bool IsNumberObject() const
static void RemoveGCPrologueCallback(GCPrologueCallback callback)
void UnreachableCallback(const v8::FunctionCallbackInfo< v8::Value > &args)
void StoringEventLoggerCallback(const char *message, int status)
RequestInterruptTestBase()
void * GetData(uint32_t slot)
void CheckThisNamedPropertySetter(Local< String > property, Local< Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
static void ShouldContinueCallback(const v8::FunctionCallbackInfo< Value > &info)
static void Dispose(v8::Isolate *isolate, v8::UniquePersistent< V > value, Impl *impl, K key)
void(* NamedPropertyGetter)(Local< String > property, const v8::PropertyCallbackInfo< v8::Value > &info)
void PrologueCallbackAlloc(v8::Isolate *isolate, v8::GCType, v8::GCCallbackFlags flags)
bool Has(Handle< Value > key)
void AnalyzeScriptIdInStack(const v8::FunctionCallbackInfo< v8::Value > &args)
int echo_indexed_call_count
bool IsOneByteRepresentation()
bool CodeGenerationAllowed(Local< Context > context)
void InterceptorGetter(Local< String > name, const v8::PropertyCallbackInfo< v8::Value > &info)
void ClearJSFunctionResultCaches()
void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
static Handle< Object > GetElement(Isolate *isolate, Handle< Object > object, uint32_t index)
UNINITIALIZED_TEST(SetJitCodeEventHandler)
void AddInterceptor(Handle< FunctionTemplate > templ, v8::NamedPropertyGetterCallback getter, v8::NamedPropertySetterCallback setter)
static Local< Value > Parse(Local< String > json_string)
CcTest::TestFunction * callback()
static Local< TypeSwitch > New(Handle< FunctionTemplate > type)
int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
void SetAccessorProperty(Local< String > name, Local< FunctionTemplate > getter=Local< FunctionTemplate >(), Local< FunctionTemplate > setter=Local< FunctionTemplate >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
int epilogue_call_count_second
void EmptyInterceptorSetter(Local< String > name, Local< Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
void TryCatchMixedNestingHelper(const v8::FunctionCallbackInfo< v8::Value > &args)
char * StrDup(const char *str)
Local< Value > Name() const
static Local< AccessorSignature > New(Isolate *isolate, Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >())
Handle< Context > native_context()
static ScriptData * New(const char *data, int length)
size_t ByteLength() const
Local< Boolean > ToBoolean() const
static Local< Symbol > New(Isolate *isolate, Local< String > name=Local< String >())
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
size_t ByteLength() const
V8_INLINE Handle< S > As()
void AddAccessor(Handle< FunctionTemplate > templ, Handle< String > name, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter)
v8::Local< v8::Context > local()
bool HasRealNamedProperty(Handle< String > key)
std::map< K, PersistentContainerValue > Impl
static WeakCallbackDataType * WeakCallbackParameter(Impl *impl, const K &key, Local< V > value)
void InterceptorSetter(Local< String > name, Local< Value > value, const v8::PropertyCallbackInfo< v8::Value > &info)
static ScriptData * PreCompile(Handle< String > source)
bool Delete(Handle< Value > key)
static void SetUp(PartOfTest part)
void DeleteArray(T *array)
Handle< Value > GetInferredName() const
void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type)
void CheckOwnProperties(v8::Isolate *isolate, v8::Handle< v8::Value > val, int elmc, const char *elmv[])
static ConsString * cast(Object *obj)
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackData< T, P >::Callback callback)
bool SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None)
static void EntryHook(uintptr_t function, uintptr_t return_addr_location)
SymbolLocationMap symbol_locations_
v8::Persistent< v8::Object > * object_
V8_INLINE Local< Value > Data() const
static const int kMaxValue
static const int kHeaderSize
V8_INLINE void MarkIndependent()
v8::Handle< Function > args_fun
void SetErrorMessageForCodeGenerationFromStrings(Handle< String > message)
static Local< Value > New(Handle< String > value)
Local< String > ValueOf() const
static V8_INLINE v8::Local< v8::String > Empty(Isolate *isolate)
int match(Handle< Value > value)
Local< v8::Message > Message() const
V8_INLINE Handle< Primitive > Null(Isolate *isolate)
static Impl * ImplFromWeakCallbackData(const v8::WeakCallbackData< V, WeakCallbackDataType > &data)
void Inherit(Handle< FunctionTemplate > parent)
void ThrowValue(const v8::FunctionCallbackInfo< v8::Value > &args)
Visitor42(v8::Persistent< v8::Object > *object)
int epilogue_call_count_alloc
Local< String > GetFunctionName() const
Local< String > GetSourceLine() const
static void SetCounterFunction(CounterLookupCallback)
Local< Uint32 > ToArrayIndex() const
void HasOwnPropertyNamedPropertyGetter(Local< String > property, const v8::PropertyCallbackInfo< v8::Value > &info)
static V8_INLINE Handle< Boolean > New(Isolate *isolate, bool value)
bool should_continue() const
void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle< Value > data=Handle< Value >(), bool turned_on_by_default=true)
static void DisposeCallbackData(WeakCallbackDataType *data)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static v8::Isolate * isolate()
const char * name() const
int GetFrameCount() const
static void OnInterrupt(v8::Isolate *isolate, void *data)
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
static bool IdleNotification(int hint=1000)
v8::Handle< Value > call_ic_function2
static Local< Symbol > For(Isolate *isolate, Local< String > name)