| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 9895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9906 v8::Handle<v8::Object> obj = val.As<v8::Object>(); | 9906 v8::Handle<v8::Object> obj = val.As<v8::Object>(); |
| 9907 v8::Handle<v8::Array> props = obj->GetPropertyNames(); | 9907 v8::Handle<v8::Array> props = obj->GetPropertyNames(); |
| 9908 CHECK_EQ(elmc, props->Length()); | 9908 CHECK_EQ(elmc, props->Length()); |
| 9909 for (int i = 0; i < elmc; i++) { | 9909 for (int i = 0; i < elmc; i++) { |
| 9910 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); | 9910 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); |
| 9911 CHECK_EQ(elmv[i], *elm); | 9911 CHECK_EQ(elmv[i], *elm); |
| 9912 } | 9912 } |
| 9913 } | 9913 } |
| 9914 | 9914 |
| 9915 | 9915 |
| 9916 void CheckOwnProperties(v8::Handle<v8::Value> val, |
| 9917 int elmc, |
| 9918 const char* elmv[]) { |
| 9919 v8::Handle<v8::Object> obj = val.As<v8::Object>(); |
| 9920 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); |
| 9921 CHECK_EQ(elmc, props->Length()); |
| 9922 for (int i = 0; i < elmc; i++) { |
| 9923 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); |
| 9924 CHECK_EQ(elmv[i], *elm); |
| 9925 } |
| 9926 } |
| 9927 |
| 9928 |
| 9916 THREADED_TEST(PropertyEnumeration) { | 9929 THREADED_TEST(PropertyEnumeration) { |
| 9917 v8::HandleScope scope; | 9930 v8::HandleScope scope; |
| 9918 LocalContext context; | 9931 LocalContext context; |
| 9919 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( | 9932 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( |
| 9920 "var result = [];" | 9933 "var result = [];" |
| 9921 "result[0] = {};" | 9934 "result[0] = {};" |
| 9922 "result[1] = {a: 1, b: 2};" | 9935 "result[1] = {a: 1, b: 2};" |
| 9923 "result[2] = [1, 2, 3];" | 9936 "result[2] = [1, 2, 3];" |
| 9924 "var proto = {x: 1, y: 2, z: 3};" | 9937 "var proto = {x: 1, y: 2, z: 3};" |
| 9925 "var x = { __proto__: proto, w: 0, z: 1 };" | 9938 "var x = { __proto__: proto, w: 0, z: 1 };" |
| 9926 "result[3] = x;" | 9939 "result[3] = x;" |
| 9927 "result;"))->Run(); | 9940 "result;"))->Run(); |
| 9928 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 9941 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); |
| 9929 CHECK_EQ(4, elms->Length()); | 9942 CHECK_EQ(4, elms->Length()); |
| 9930 int elmc0 = 0; | 9943 int elmc0 = 0; |
| 9931 const char** elmv0 = NULL; | 9944 const char** elmv0 = NULL; |
| 9932 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); | 9945 CheckProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
| 9946 CheckOwnProperties(elms->Get(v8::Integer::New(0)), elmc0, elmv0); |
| 9933 int elmc1 = 2; | 9947 int elmc1 = 2; |
| 9934 const char* elmv1[] = {"a", "b"}; | 9948 const char* elmv1[] = {"a", "b"}; |
| 9935 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); | 9949 CheckProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
| 9950 CheckOwnProperties(elms->Get(v8::Integer::New(1)), elmc1, elmv1); |
| 9936 int elmc2 = 3; | 9951 int elmc2 = 3; |
| 9937 const char* elmv2[] = {"0", "1", "2"}; | 9952 const char* elmv2[] = {"0", "1", "2"}; |
| 9938 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); | 9953 CheckProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
| 9954 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); |
| 9939 int elmc3 = 4; | 9955 int elmc3 = 4; |
| 9940 const char* elmv3[] = {"w", "z", "x", "y"}; | 9956 const char* elmv3[] = {"w", "z", "x", "y"}; |
| 9941 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); | 9957 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); |
| 9958 int elmc4 = 2; |
| 9959 const char* elmv4[] = {"w", "z"}; |
| 9960 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); |
| 9942 } | 9961 } |
| 9943 | 9962 |
| 9944 THREADED_TEST(PropertyEnumeration2) { | 9963 THREADED_TEST(PropertyEnumeration2) { |
| 9945 v8::HandleScope scope; | 9964 v8::HandleScope scope; |
| 9946 LocalContext context; | 9965 LocalContext context; |
| 9947 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( | 9966 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( |
| 9948 "var result = [];" | 9967 "var result = [];" |
| 9949 "result[0] = {};" | 9968 "result[0] = {};" |
| 9950 "result[1] = {a: 1, b: 2};" | 9969 "result[1] = {a: 1, b: 2};" |
| 9951 "result[2] = [1, 2, 3];" | 9970 "result[2] = [1, 2, 3];" |
| (...skipping 4506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14458 | 14477 |
| 14459 THREADED_TEST(CallAPIFunctionOnNonObject) { | 14478 THREADED_TEST(CallAPIFunctionOnNonObject) { |
| 14460 v8::HandleScope scope; | 14479 v8::HandleScope scope; |
| 14461 LocalContext context; | 14480 LocalContext context; |
| 14462 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); | 14481 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); |
| 14463 Handle<Function> function = templ->GetFunction(); | 14482 Handle<Function> function = templ->GetFunction(); |
| 14464 context->Global()->Set(v8_str("f"), function); | 14483 context->Global()->Set(v8_str("f"), function); |
| 14465 TryCatch try_catch; | 14484 TryCatch try_catch; |
| 14466 CompileRun("f.call(2)"); | 14485 CompileRun("f.call(2)"); |
| 14467 } | 14486 } |
| OLD | NEW |