Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: test/cctest/test-api.cc

Issue 1660263003: Revert of [api] Make ObjectTemplate::SetNativeDataProperty() work even if the ObjectTemplate ... (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x87/builtins-x87.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 LocalContext env(0, templ); 1882 LocalContext env(0, templ);
1883 v8::Local<Script> script(v8_compile("dummy()")); 1883 v8::Local<Script> script(v8_compile("dummy()"));
1884 v8::Local<Value> result(script->Run(env.local()).ToLocalChecked()); 1884 v8::Local<Value> result(script->Run(env.local()).ToLocalChecked());
1885 CHECK_EQ(13.4, result->NumberValue(env.local()).FromJust()); 1885 CHECK_EQ(13.4, result->NumberValue(env.local()).FromJust());
1886 CHECK_EQ(200, v8_run_int32value(v8_compile("x"))); 1886 CHECK_EQ(200, v8_run_int32value(v8_compile("x")));
1887 CHECK_EQ(876, v8_run_int32value(v8_compile("m"))); 1887 CHECK_EQ(876, v8_run_int32value(v8_compile("m")));
1888 } 1888 }
1889 1889
1890 1890
1891 THREADED_TEST(ObjectTemplate) { 1891 THREADED_TEST(ObjectTemplate) {
1892 LocalContext env;
1893 v8::Isolate* isolate = CcTest::isolate(); 1892 v8::Isolate* isolate = CcTest::isolate();
1894 v8::HandleScope scope(isolate); 1893 v8::HandleScope scope(isolate);
1895 Local<v8::FunctionTemplate> acc =
1896 v8::FunctionTemplate::New(isolate, Returns42);
1897 CHECK(env->Global()
1898 ->Set(env.local(), v8_str("acc"),
1899 acc->GetFunction(env.local()).ToLocalChecked())
1900 .FromJust());
1901
1902 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 1894 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
1903 v8::Local<v8::String> class_name = v8_str("the_class_name"); 1895 v8::Local<v8::String> class_name = v8_str("the_class_name");
1904 fun->SetClassName(class_name); 1896 fun->SetClassName(class_name);
1905 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun); 1897 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun);
1906 templ1->Set(isolate, "x", v8_num(10)); 1898 templ1->Set(isolate, "x", v8_num(10));
1907 templ1->Set(isolate, "y", v8_num(13)); 1899 templ1->Set(isolate, "y", v8_num(13));
1900 LocalContext env;
1908 Local<v8::Object> instance1 = 1901 Local<v8::Object> instance1 =
1909 templ1->NewInstance(env.local()).ToLocalChecked(); 1902 templ1->NewInstance(env.local()).ToLocalChecked();
1910 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); 1903 CHECK(class_name->StrictEquals(instance1->GetConstructorName()));
1911 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust()); 1904 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust());
1912 CHECK(CompileRun("(p.x == 10)")->BooleanValue(env.local()).FromJust()); 1905 CHECK(v8_compile("(p.x == 10)")
1913 CHECK(CompileRun("(p.y == 13)")->BooleanValue(env.local()).FromJust()); 1906 ->Run(env.local())
1907 .ToLocalChecked()
1908 ->BooleanValue(env.local())
1909 .FromJust());
1910 CHECK(v8_compile("(p.y == 13)")
1911 ->Run(env.local())
1912 .ToLocalChecked()
1913 ->BooleanValue(env.local())
1914 .FromJust());
1914 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); 1915 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate);
1915 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); 1916 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1916 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); 1917 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate();
1917 templ2->Set(isolate, "a", v8_num(12)); 1918 templ2->Set(isolate, "a", v8_num(12));
1918 templ2->Set(isolate, "b", templ1); 1919 templ2->Set(isolate, "b", templ1);
1919 templ2->SetAccessorProperty(v8_str("acc"), acc);
1920 Local<v8::Object> instance2 = 1920 Local<v8::Object> instance2 =
1921 templ2->NewInstance(env.local()).ToLocalChecked(); 1921 templ2->NewInstance(env.local()).ToLocalChecked();
1922 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust()); 1922 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust());
1923 CHECK(CompileRun("(q.nirk == 123)")->BooleanValue(env.local()).FromJust()); 1923 CHECK(v8_compile("(q.nirk == 123)")
1924 CHECK(CompileRun("(q.a == 12)")->BooleanValue(env.local()).FromJust()); 1924 ->Run(env.local())
1925 CHECK(CompileRun("(q.b.x == 10)")->BooleanValue(env.local()).FromJust()); 1925 .ToLocalChecked()
1926 CHECK(CompileRun("(q.b.y == 13)")->BooleanValue(env.local()).FromJust());
1927 CHECK(CompileRun("(q.b !== p)")->BooleanValue(env.local()).FromJust());
1928 CHECK(CompileRun("(q.acc == 42)")->BooleanValue(env.local()).FromJust());
1929
1930 instance2 = templ2->NewInstance(env.local()).ToLocalChecked();
1931 CHECK(env->Global()->Set(env.local(), v8_str("q2"), instance2).FromJust());
1932 CHECK(CompileRun("(q2.nirk == 123)")->BooleanValue(env.local()).FromJust());
1933 CHECK(CompileRun("(q2.a == 12)")->BooleanValue(env.local()).FromJust());
1934 CHECK(CompileRun("(q2.b.x == 10)")->BooleanValue(env.local()).FromJust());
1935 CHECK(CompileRun("(q2.b.y == 13)")->BooleanValue(env.local()).FromJust());
1936 CHECK(CompileRun("(q2.acc == 42)")->BooleanValue(env.local()).FromJust());
1937
1938 CHECK(CompileRun("(q.b !== q2.b)")->BooleanValue(env.local()).FromJust());
1939 CHECK(CompileRun("q.b.x = 17; (q2.b.x == 10)")
1940 ->BooleanValue(env.local()) 1926 ->BooleanValue(env.local())
1941 .FromJust()); 1927 .FromJust());
1942 CHECK(CompileRun("desc1 = Object.getOwnPropertyDescriptor(q, 'acc');" 1928 CHECK(v8_compile("(q.a == 12)")
1943 "(desc1.get === acc)") 1929 ->Run(env.local())
1930 .ToLocalChecked()
1944 ->BooleanValue(env.local()) 1931 ->BooleanValue(env.local())
1945 .FromJust()); 1932 .FromJust());
1946 CHECK(CompileRun("desc2 = Object.getOwnPropertyDescriptor(q2, 'acc');" 1933 CHECK(v8_compile("(q.b.x == 10)")
1947 "(desc2.get === acc)") 1934 ->Run(env.local())
1935 .ToLocalChecked()
1936 ->BooleanValue(env.local())
1937 .FromJust());
1938 CHECK(v8_compile("(q.b.y == 13)")
1939 ->Run(env.local())
1940 .ToLocalChecked()
1948 ->BooleanValue(env.local()) 1941 ->BooleanValue(env.local())
1949 .FromJust()); 1942 .FromJust());
1950 } 1943 }
1951 1944
1952 THREADED_TEST(IntegerValue) {
1953 LocalContext env;
1954 v8::Isolate* isolate = CcTest::isolate();
1955 v8::HandleScope scope(isolate);
1956
1957 CHECK_EQ(0, CompileRun("undefined")->IntegerValue(env.local()).FromJust());
1958 }
1959
1960 static void GetNirk(Local<String> name,
1961 const v8::PropertyCallbackInfo<v8::Value>& info) {
1962 ApiTestFuzzer::Fuzz();
1963 info.GetReturnValue().Set(v8_num(900));
1964 }
1965
1966 static void GetRino(Local<String> name,
1967 const v8::PropertyCallbackInfo<v8::Value>& info) {
1968 ApiTestFuzzer::Fuzz();
1969 info.GetReturnValue().Set(v8_num(560));
1970 }
1971
1972 enum ObjectInstantiationMode {
1973 // Create object using ObjectTemplate::NewInstance.
1974 ObjectTemplate_NewInstance,
1975 // Create object using FunctionTemplate::NewInstance on constructor.
1976 Constructor_GetFunction_NewInstance,
1977 // Create object using new operator on constructor.
1978 Constructor_GetFunction_New
1979 };
1980
1981 // Test object instance creation using a function template with an instance
1982 // template inherited from another function template with accessors and data
1983 // properties in prototype template.
1984 static void TestObjectTemplateInheritedWithPrototype(
1985 ObjectInstantiationMode mode) {
1986 LocalContext env;
1987 v8::Isolate* isolate = CcTest::isolate();
1988 v8::HandleScope scope(isolate);
1989
1990 Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
1991 fun_A->SetClassName(v8_str("A"));
1992 v8::Local<v8::ObjectTemplate> prototype_templ = fun_A->PrototypeTemplate();
1993 prototype_templ->Set(isolate, "a", v8_num(113));
1994 prototype_templ->SetNativeDataProperty(v8_str("nirk"), GetNirk);
1995 prototype_templ->Set(isolate, "b", v8_num(153));
1996
1997 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
1998 v8::Local<v8::String> class_name = v8_str("B");
1999 fun_B->SetClassName(class_name);
2000 fun_B->Inherit(fun_A);
2001 prototype_templ = fun_B->PrototypeTemplate();
2002 prototype_templ->Set(isolate, "c", v8_num(713));
2003 prototype_templ->SetNativeDataProperty(v8_str("rino"), GetRino);
2004 prototype_templ->Set(isolate, "d", v8_num(753));
2005
2006 Local<ObjectTemplate> templ = fun_B->InstanceTemplate();
2007 templ->Set(isolate, "x", v8_num(10));
2008 templ->Set(isolate, "y", v8_num(13));
2009
2010 // Perform several iterations to trigger creation from cached boilerplate.
2011 for (int i = 0; i < 3; i++) {
2012 Local<v8::Object> instance;
2013 switch (mode) {
2014 case ObjectTemplate_NewInstance:
2015 instance = templ->NewInstance(env.local()).ToLocalChecked();
2016 break;
2017
2018 case Constructor_GetFunction_NewInstance: {
2019 Local<v8::Function> function_B =
2020 fun_B->GetFunction(env.local()).ToLocalChecked();
2021 instance = function_B->NewInstance(env.local()).ToLocalChecked();
2022 break;
2023 }
2024 case Constructor_GetFunction_New: {
2025 Local<v8::Function> function_B =
2026 fun_B->GetFunction(env.local()).ToLocalChecked();
2027 if (i == 0) {
2028 CHECK(env->Global()
2029 ->Set(env.local(), class_name, function_B)
2030 .FromJust());
2031 }
2032 instance =
2033 CompileRun("new B()")->ToObject(env.local()).ToLocalChecked();
2034 break;
2035 }
2036 default:
2037 UNREACHABLE();
2038 }
2039
2040 CHECK(class_name->StrictEquals(instance->GetConstructorName()));
2041 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust());
2042
2043 CHECK_EQ(10, CompileRun("o.x")->IntegerValue(env.local()).FromJust());
2044 CHECK_EQ(13, CompileRun("o.y")->IntegerValue(env.local()).FromJust());
2045
2046 CHECK_EQ(113, CompileRun("o.a")->IntegerValue(env.local()).FromJust());
2047 CHECK_EQ(900, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust());
2048 CHECK_EQ(153, CompileRun("o.b")->IntegerValue(env.local()).FromJust());
2049 CHECK_EQ(713, CompileRun("o.c")->IntegerValue(env.local()).FromJust());
2050 CHECK_EQ(560, CompileRun("o.rino")->IntegerValue(env.local()).FromJust());
2051 CHECK_EQ(753, CompileRun("o.d")->IntegerValue(env.local()).FromJust());
2052 }
2053 }
2054
2055 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype1) {
2056 TestObjectTemplateInheritedWithPrototype(ObjectTemplate_NewInstance);
2057 }
2058
2059 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype2) {
2060 TestObjectTemplateInheritedWithPrototype(Constructor_GetFunction_NewInstance);
2061 }
2062
2063 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype3) {
2064 TestObjectTemplateInheritedWithPrototype(Constructor_GetFunction_New);
2065 }
2066
2067 // Test object instance creation using a function template without an instance
2068 // template inherited from another function template.
2069 static void TestObjectTemplateInheritedWithoutInstanceTemplate(
2070 ObjectInstantiationMode mode) {
2071 LocalContext env;
2072 v8::Isolate* isolate = CcTest::isolate();
2073 v8::HandleScope scope(isolate);
2074
2075 Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
2076 fun_A->SetClassName(v8_str("A"));
2077
2078 Local<ObjectTemplate> templ_A = fun_A->InstanceTemplate();
2079 templ_A->SetNativeDataProperty(v8_str("nirk"), GetNirk);
2080 templ_A->SetNativeDataProperty(v8_str("rino"), GetRino);
2081
2082 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
2083 v8::Local<v8::String> class_name = v8_str("B");
2084 fun_B->SetClassName(class_name);
2085 fun_B->Inherit(fun_A);
2086
2087 // Perform several iterations to trigger creation from cached boilerplate.
2088 for (int i = 0; i < 3; i++) {
2089 Local<v8::Object> instance;
2090 switch (mode) {
2091 case Constructor_GetFunction_NewInstance: {
2092 Local<v8::Function> function_B =
2093 fun_B->GetFunction(env.local()).ToLocalChecked();
2094 instance = function_B->NewInstance(env.local()).ToLocalChecked();
2095 break;
2096 }
2097 case Constructor_GetFunction_New: {
2098 Local<v8::Function> function_B =
2099 fun_B->GetFunction(env.local()).ToLocalChecked();
2100 if (i == 0) {
2101 CHECK(env->Global()
2102 ->Set(env.local(), class_name, function_B)
2103 .FromJust());
2104 }
2105 instance =
2106 CompileRun("new B()")->ToObject(env.local()).ToLocalChecked();
2107 break;
2108 }
2109 default:
2110 UNREACHABLE();
2111 }
2112
2113 CHECK(class_name->StrictEquals(instance->GetConstructorName()));
2114 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust());
2115
2116 CHECK_EQ(900, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust());
2117 CHECK_EQ(560, CompileRun("o.rino")->IntegerValue(env.local()).FromJust());
2118 }
2119 }
2120
2121 THREADED_TEST(TestObjectTemplateInheritedWithPrototype1) {
2122 TestObjectTemplateInheritedWithoutInstanceTemplate(
2123 Constructor_GetFunction_NewInstance);
2124 }
2125
2126 THREADED_TEST(TestObjectTemplateInheritedWithPrototype2) {
2127 TestObjectTemplateInheritedWithoutInstanceTemplate(
2128 Constructor_GetFunction_New);
2129 }
2130 1945
2131 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 1946 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
2132 ApiTestFuzzer::Fuzz(); 1947 ApiTestFuzzer::Fuzz();
2133 args.GetReturnValue().Set(v8_num(17.2)); 1948 args.GetReturnValue().Set(v8_num(17.2));
2134 } 1949 }
2135 1950
2136 1951
2137 static void GetKnurd(Local<String> property, 1952 static void GetKnurd(Local<String> property,
2138 const v8::PropertyCallbackInfo<v8::Value>& info) { 1953 const v8::PropertyCallbackInfo<v8::Value>& info) {
2139 ApiTestFuzzer::Fuzz(); 1954 ApiTestFuzzer::Fuzz();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 CHECK(CompileRun("base1.prototype.knurd == undefined") 2013 CHECK(CompileRun("base1.prototype.knurd == undefined")
2199 ->BooleanValue(env.local()) 2014 ->BooleanValue(env.local())
2200 .FromJust()); 2015 .FromJust());
2201 2016
2202 CHECK(env->Global() 2017 CHECK(env->Global()
2203 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local()) 2018 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local())
2204 .ToLocalChecked() 2019 .ToLocalChecked()
2205 ->NewInstance(env.local()) 2020 ->NewInstance(env.local())
2206 .ToLocalChecked()) 2021 .ToLocalChecked())
2207 .FromJust()); 2022 .FromJust());
2208 CHECK_EQ(17.2, 2023 CHECK_EQ(17.2, v8_compile("obj.flabby()")
2209 CompileRun("obj.flabby()")->NumberValue(env.local()).FromJust()); 2024 ->Run(env.local())
2210 CHECK(CompileRun("'flabby' in obj")->BooleanValue(env.local()).FromJust()); 2025 .ToLocalChecked()
2211 CHECK_EQ(15.2, CompileRun("obj.knurd")->NumberValue(env.local()).FromJust()); 2026 ->NumberValue(env.local())
2212 CHECK(CompileRun("'knurd' in obj")->BooleanValue(env.local()).FromJust()); 2027 .FromJust());
2213 CHECK_EQ(20.1, CompileRun("obj.v1")->NumberValue(env.local()).FromJust()); 2028 CHECK(v8_compile("'flabby' in obj")
2029 ->Run(env.local())
2030 .ToLocalChecked()
2031 ->BooleanValue(env.local())
2032 .FromJust());
2033 CHECK_EQ(15.2, v8_compile("obj.knurd")
2034 ->Run(env.local())
2035 .ToLocalChecked()
2036 ->NumberValue(env.local())
2037 .FromJust());
2038 CHECK(v8_compile("'knurd' in obj")
2039 ->Run(env.local())
2040 .ToLocalChecked()
2041 ->BooleanValue(env.local())
2042 .FromJust());
2043 CHECK_EQ(20.1, v8_compile("obj.v1")
2044 ->Run(env.local())
2045 .ToLocalChecked()
2046 ->NumberValue(env.local())
2047 .FromJust());
2214 2048
2215 CHECK(env->Global() 2049 CHECK(env->Global()
2216 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local()) 2050 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local())
2217 .ToLocalChecked() 2051 .ToLocalChecked()
2218 ->NewInstance(env.local()) 2052 ->NewInstance(env.local())
2219 .ToLocalChecked()) 2053 .ToLocalChecked())
2220 .FromJust()); 2054 .FromJust());
2221 CHECK_EQ(17.2, 2055 CHECK_EQ(17.2, v8_compile("obj2.flabby()")
2222 CompileRun("obj2.flabby()")->NumberValue(env.local()).FromJust()); 2056 ->Run(env.local())
2223 CHECK(CompileRun("'flabby' in obj2")->BooleanValue(env.local()).FromJust()); 2057 .ToLocalChecked()
2224 CHECK_EQ(15.2, CompileRun("obj2.knurd")->NumberValue(env.local()).FromJust()); 2058 ->NumberValue(env.local())
2225 CHECK(CompileRun("'knurd' in obj2")->BooleanValue(env.local()).FromJust()); 2059 .FromJust());
2226 CHECK_EQ(10.1, CompileRun("obj2.v2")->NumberValue(env.local()).FromJust()); 2060 CHECK(v8_compile("'flabby' in obj2")
2061 ->Run(env.local())
2062 .ToLocalChecked()
2063 ->BooleanValue(env.local())
2064 .FromJust());
2065 CHECK_EQ(15.2, v8_compile("obj2.knurd")
2066 ->Run(env.local())
2067 .ToLocalChecked()
2068 ->NumberValue(env.local())
2069 .FromJust());
2070 CHECK(v8_compile("'knurd' in obj2")
2071 ->Run(env.local())
2072 .ToLocalChecked()
2073 ->BooleanValue(env.local())
2074 .FromJust());
2075 CHECK_EQ(10.1, v8_compile("obj2.v2")
2076 ->Run(env.local())
2077 .ToLocalChecked()
2078 ->NumberValue(env.local())
2079 .FromJust());
2227 2080
2228 // base1 and base2 cannot cross reference to each's prototype 2081 // base1 and base2 cannot cross reference to each's prototype
2229 CHECK(CompileRun("obj.v2")->IsUndefined()); 2082 CHECK(v8_compile("obj.v2")->Run(env.local()).ToLocalChecked()->IsUndefined());
2230 CHECK(CompileRun("obj2.v1")->IsUndefined()); 2083 CHECK(
2231 } 2084 v8_compile("obj2.v1")->Run(env.local()).ToLocalChecked()->IsUndefined());
2232
2233 THREADED_TEST(DescriptorInheritance2) {
2234 LocalContext env;
2235 v8::Isolate* isolate = CcTest::isolate();
2236 v8::HandleScope scope(isolate);
2237 v8::Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
2238 fun_A->SetClassName(v8_str("A"));
2239 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd1"), GetKnurd);
2240 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk1"), GetNirk);
2241 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("rino1"), GetRino);
2242
2243 v8::Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
2244 fun_B->SetClassName(v8_str("B"));
2245 fun_B->Inherit(fun_A);
2246
2247 v8::Local<v8::FunctionTemplate> fun_C = v8::FunctionTemplate::New(isolate);
2248 fun_C->SetClassName(v8_str("C"));
2249 fun_C->Inherit(fun_B);
2250 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd2"), GetKnurd);
2251 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk2"), GetNirk);
2252 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("rino2"), GetRino);
2253
2254 v8::Local<v8::FunctionTemplate> fun_D = v8::FunctionTemplate::New(isolate);
2255 fun_D->SetClassName(v8_str("D"));
2256 fun_D->Inherit(fun_C);
2257
2258 v8::Local<v8::FunctionTemplate> fun_E = v8::FunctionTemplate::New(isolate);
2259 fun_E->SetClassName(v8_str("E"));
2260 fun_E->Inherit(fun_D);
2261 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd3"), GetKnurd);
2262 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk3"), GetNirk);
2263 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("rino3"), GetRino);
2264
2265 v8::Local<v8::FunctionTemplate> fun_F = v8::FunctionTemplate::New(isolate);
2266 fun_F->SetClassName(v8_str("F"));
2267 fun_F->Inherit(fun_E);
2268 v8::Local<v8::ObjectTemplate> templ = fun_F->InstanceTemplate();
2269 const int kDataPropertiesNumber = 100;
2270 for (int i = 0; i < kDataPropertiesNumber; i++) {
2271 v8::Local<v8::Value> val = v8_num(i);
2272 v8::Local<v8::String> val_str = val->ToString(env.local()).ToLocalChecked();
2273 v8::Local<v8::String> name = String::Concat(v8_str("p"), val_str);
2274
2275 templ->Set(name, val);
2276 templ->Set(val_str, val);
2277 }
2278
2279 CHECK(env->Global()
2280 ->Set(env.local(), v8_str("F"),
2281 fun_F->GetFunction(env.local()).ToLocalChecked())
2282 .FromJust());
2283
2284 v8::Local<v8::Script> script = v8_compile("o = new F()");
2285
2286 for (int i = 0; i < 100; i++) {
2287 v8::HandleScope scope(isolate);
2288 script->Run(env.local()).ToLocalChecked();
2289 }
2290 v8::Local<v8::Object> object = script->Run(env.local())
2291 .ToLocalChecked()
2292 ->ToObject(env.local())
2293 .ToLocalChecked();
2294
2295 CHECK_EQ(15.2, CompileRun("o.knurd1")->NumberValue(env.local()).FromJust());
2296 CHECK_EQ(15.2, CompileRun("o.knurd2")->NumberValue(env.local()).FromJust());
2297 CHECK_EQ(15.2, CompileRun("o.knurd3")->NumberValue(env.local()).FromJust());
2298
2299 CHECK_EQ(900, CompileRun("o.nirk1")->IntegerValue(env.local()).FromJust());
2300 CHECK_EQ(900, CompileRun("o.nirk2")->IntegerValue(env.local()).FromJust());
2301 CHECK_EQ(900, CompileRun("o.nirk3")->IntegerValue(env.local()).FromJust());
2302
2303 CHECK_EQ(560, CompileRun("o.rino1")->IntegerValue(env.local()).FromJust());
2304 CHECK_EQ(560, CompileRun("o.rino2")->IntegerValue(env.local()).FromJust());
2305 CHECK_EQ(560, CompileRun("o.rino3")->IntegerValue(env.local()).FromJust());
2306
2307 for (int i = 0; i < kDataPropertiesNumber; i++) {
2308 v8::Local<v8::Value> val = v8_num(i);
2309 v8::Local<v8::String> val_str = val->ToString(env.local()).ToLocalChecked();
2310 v8::Local<v8::String> name = String::Concat(v8_str("p"), val_str);
2311
2312 CHECK_EQ(i, object->Get(env.local(), name)
2313 .ToLocalChecked()
2314 ->IntegerValue(env.local())
2315 .FromJust());
2316 CHECK_EQ(i, object->Get(env.local(), val)
2317 .ToLocalChecked()
2318 ->IntegerValue(env.local())
2319 .FromJust());
2320 }
2321 } 2085 }
2322 2086
2323 2087
2324 // Helper functions for Interceptor/Accessor interaction tests 2088 // Helper functions for Interceptor/Accessor interaction tests
2325 2089
2326 void SimpleAccessorGetter(Local<String> name, 2090 void SimpleAccessorGetter(Local<String> name,
2327 const v8::PropertyCallbackInfo<v8::Value>& info) { 2091 const v8::PropertyCallbackInfo<v8::Value>& info) {
2328 Local<Object> self = Local<Object>::Cast(info.This()); 2092 Local<Object> self = Local<Object>::Cast(info.This());
2329 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(), 2093 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(),
2330 String::Concat(v8_str("accessor_"), name)) 2094 String::Concat(v8_str("accessor_"), name))
(...skipping 8621 matching lines...) Expand 10 before | Expand all | Expand 10 after
10952 LocalContext context; 10716 LocalContext context;
10953 v8::Isolate* isolate = context->GetIsolate(); 10717 v8::Isolate* isolate = context->GetIsolate();
10954 v8::HandleScope handle_scope(isolate); 10718 v8::HandleScope handle_scope(isolate);
10955 10719
10956 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10720 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10957 t1->SetHiddenPrototype(true); 10721 t1->SetHiddenPrototype(true);
10958 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10722 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
10959 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10723 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10960 t2->SetHiddenPrototype(true); 10724 t2->SetHiddenPrototype(true);
10961 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10725 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
10962 t2->InstanceTemplate()->Set(v8_str("objects"), 10726 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate));
10963 v8::ObjectTemplate::New(isolate));
10964 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10727 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
10965 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10728 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
10966 t3->SetHiddenPrototype(true); 10729 t3->SetHiddenPrototype(true);
10967 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10730 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
10968 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10731 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
10969 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10732 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
10970 10733
10971 // Force dictionary-based properties. 10734 // Force dictionary-based properties.
10972 i::ScopedVector<char> name_buf(1024); 10735 i::ScopedVector<char> name_buf(1024);
10973 for (int i = 1; i <= 1000; i++) { 10736 for (int i = 1; i <= 1000; i++) {
(...skipping 27 matching lines...) Expand all
11001 // created object through JavaScript. 10764 // created object through JavaScript.
11002 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust()); 10765 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust());
11003 // PROPERTY_FILTER_NONE = 0 10766 // PROPERTY_FILTER_NONE = 0
11004 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);"); 10767 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);");
11005 10768
11006 ExpectInt32("names.length", 1006); 10769 ExpectInt32("names.length", 1006);
11007 ExpectTrue("names.indexOf(\"baz\") >= 0"); 10770 ExpectTrue("names.indexOf(\"baz\") >= 0");
11008 ExpectTrue("names.indexOf(\"boo\") >= 0"); 10771 ExpectTrue("names.indexOf(\"boo\") >= 0");
11009 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10772 ExpectTrue("names.indexOf(\"foo\") >= 0");
11010 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 10773 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
11011 ExpectTrue("names.indexOf(\"objects\") >= 0");
11012 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 10774 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
11013 ExpectFalse("names[1005] == undefined"); 10775 ExpectFalse("names[1005] == undefined");
11014 } 10776 }
11015 10777
11016 10778
11017 // Getting property names of an object with a hidden and inherited 10779 // Getting property names of an object with a hidden and inherited
11018 // prototype should not duplicate the accessor properties inherited. 10780 // prototype should not duplicate the accessor properties inherited.
11019 THREADED_TEST(Regress269562) { 10781 THREADED_TEST(Regress269562) {
11020 i::FLAG_allow_natives_syntax = true; 10782 i::FLAG_allow_natives_syntax = true;
11021 LocalContext context; 10783 LocalContext context;
(...skipping 9570 matching lines...) Expand 10 before | Expand all | Expand 10 after
20592 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) 20354 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context)
20593 .ToLocalChecked() 20355 .ToLocalChecked()
20594 ->NewInstance(context) 20356 ->NewInstance(context)
20595 .ToLocalChecked(); 20357 .ToLocalChecked();
20596 Local<Object> object_with_hidden = 20358 Local<Object> object_with_hidden =
20597 Object::New(isolate); 20359 Object::New(isolate);
20598 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust(); 20360 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust();
20599 20361
20600 context->Exit(); 20362 context->Exit();
20601 20363
20602 LocalContext context2; 20364 // Template for object for second context. Values to test are put on it as
20603 v8::Local<v8::Object> global = context2->Global(); 20365 // properties.
20366 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
20367 global_template->Set(v8_str("simple"), simple_object);
20368 global_template->Set(v8_str("protected"), protected_object);
20369 global_template->Set(v8_str("global"), global_object);
20370 global_template->Set(v8_str("proxy"), proxy_object);
20371 global_template->Set(v8_str("hidden"), object_with_hidden);
20604 20372
20605 // Setup global variables. 20373 LocalContext context2(NULL, global_template);
20606 CHECK(global->Set(context2.local(), v8_str("simple"), simple_object)
20607 .FromJust());
20608 CHECK(global->Set(context2.local(), v8_str("protected"), protected_object)
20609 .FromJust());
20610 CHECK(global->Set(context2.local(), v8_str("global"), global_object)
20611 .FromJust());
20612 CHECK(
20613 global->Set(context2.local(), v8_str("proxy"), proxy_object).FromJust());
20614 CHECK(global->Set(context2.local(), v8_str("hidden"), object_with_hidden)
20615 .FromJust());
20616 20374
20617 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); 20375 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)");
20618 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype()) 20376 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype())
20619 .FromJust()); 20377 .FromJust());
20620 20378
20621 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); 20379 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)");
20622 CHECK(result2->IsNull()); 20380 CHECK(result2->IsNull());
20623 20381
20624 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); 20382 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)");
20625 CHECK(result3->Equals(context2.local(), global_object->GetPrototype()) 20383 CHECK(result3->Equals(context2.local(), global_object->GetPrototype())
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
22101 }; 21859 };
22102 21860
22103 21861
22104 class RequestInterruptTestWithMethodCall 21862 class RequestInterruptTestWithMethodCall
22105 : public RequestInterruptTestBaseWithSimpleInterrupt { 21863 : public RequestInterruptTestBaseWithSimpleInterrupt {
22106 public: 21864 public:
22107 virtual void TestBody() { 21865 virtual void TestBody() {
22108 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21866 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
22109 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 21867 v8::Local<v8::Template> proto = t->PrototypeTemplate();
22110 proto->Set(v8_str("shouldContinue"), 21868 proto->Set(v8_str("shouldContinue"),
22111 FunctionTemplate::New(isolate_, ShouldContinueCallback, 21869 Function::New(env_.local(), ShouldContinueCallback,
22112 v8::External::New(isolate_, this))); 21870 v8::External::New(isolate_, this))
21871 .ToLocalChecked());
22113 CHECK(env_->Global() 21872 CHECK(env_->Global()
22114 ->Set(env_.local(), v8_str("Klass"), 21873 ->Set(env_.local(), v8_str("Klass"),
22115 t->GetFunction(env_.local()).ToLocalChecked()) 21874 t->GetFunction(env_.local()).ToLocalChecked())
22116 .FromJust()); 21875 .FromJust());
22117 21876
22118 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 21877 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
22119 } 21878 }
22120 }; 21879 };
22121 21880
22122 21881
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
22168 }; 21927 };
22169 21928
22170 21929
22171 class RequestInterruptTestWithMethodCallAndInterceptor 21930 class RequestInterruptTestWithMethodCallAndInterceptor
22172 : public RequestInterruptTestBaseWithSimpleInterrupt { 21931 : public RequestInterruptTestBaseWithSimpleInterrupt {
22173 public: 21932 public:
22174 virtual void TestBody() { 21933 virtual void TestBody() {
22175 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21934 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
22176 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 21935 v8::Local<v8::Template> proto = t->PrototypeTemplate();
22177 proto->Set(v8_str("shouldContinue"), 21936 proto->Set(v8_str("shouldContinue"),
22178 FunctionTemplate::New(isolate_, ShouldContinueCallback, 21937 Function::New(env_.local(), ShouldContinueCallback,
22179 v8::External::New(isolate_, this))); 21938 v8::External::New(isolate_, this))
21939 .ToLocalChecked());
22180 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); 21940 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate();
22181 instance_template->SetHandler( 21941 instance_template->SetHandler(
22182 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); 21942 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor));
22183 21943
22184 CHECK(env_->Global() 21944 CHECK(env_->Global()
22185 ->Set(env_.local(), v8_str("Klass"), 21945 ->Set(env_.local(), v8_str("Klass"),
22186 t->GetFunction(env_.local()).ToLocalChecked()) 21946 t->GetFunction(env_.local()).ToLocalChecked())
22187 .FromJust()); 21947 .FromJust());
22188 21948
22189 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 21949 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
22381 Local<Value> result = CompileRun("func();"); 22141 Local<Value> result = CompileRun("func();");
22382 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust()); 22142 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust());
22383 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 22143 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
22384 // Verify function not cached 22144 // Verify function not cached
22385 auto serial_number = handle( 22145 auto serial_number = handle(
22386 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) 22146 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
22387 ->shared() 22147 ->shared()
22388 ->get_api_func_data() 22148 ->get_api_func_data()
22389 ->serial_number()), 22149 ->serial_number()),
22390 i_isolate); 22150 i_isolate);
22391 auto cache = i_isolate->template_instantiations_cache(); 22151 auto cache = i_isolate->function_cache();
22392 CHECK(cache->Lookup(serial_number)->IsTheHole()); 22152 CHECK(cache->Lookup(serial_number)->IsTheHole());
22393 // Verify that each Function::New creates a new function instance 22153 // Verify that each Function::New creates a new function instance
22394 Local<Object> data2 = v8::Object::New(isolate); 22154 Local<Object> data2 = v8::Object::New(isolate);
22395 function_new_expected_env = data2; 22155 function_new_expected_env = data2;
22396 Local<Function> func2 = 22156 Local<Function> func2 =
22397 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked(); 22157 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked();
22398 CHECK(!func2->IsNull()); 22158 CHECK(!func2->IsNull());
22399 CHECK(!func->Equals(env.local(), func2).FromJust()); 22159 CHECK(!func->Equals(env.local(), func2).FromJust());
22400 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); 22160 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust());
22401 Local<Value> result2 = CompileRun("func2();"); 22161 Local<Value> result2 = CompileRun("func2();");
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
24879 CHECK(proxy->GetTarget()->SameValue(target)); 24639 CHECK(proxy->GetTarget()->SameValue(target));
24880 CHECK(proxy->GetHandler()->SameValue(handler)); 24640 CHECK(proxy->GetHandler()->SameValue(handler));
24881 24641
24882 proxy->Revoke(); 24642 proxy->Revoke();
24883 CHECK(proxy->IsProxy()); 24643 CHECK(proxy->IsProxy());
24884 CHECK(!target->IsProxy()); 24644 CHECK(!target->IsProxy());
24885 CHECK(proxy->IsRevoked()); 24645 CHECK(proxy->IsRevoked());
24886 CHECK(proxy->GetTarget()->SameValue(target)); 24646 CHECK(proxy->GetTarget()->SameValue(target));
24887 CHECK(proxy->GetHandler()->IsNull()); 24647 CHECK(proxy->GetHandler()->IsNull());
24888 } 24648 }
OLDNEW
« no previous file with comments | « src/x87/builtins-x87.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698