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

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

Issue 1642223003: [api] Make ObjectTemplate::SetNativeDataProperty() work even if the ObjectTemplate does not have a … (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments 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
« src/api-natives.cc ('K') | « 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 v8::Isolate* isolate = CcTest::isolate(); 1892 LocalContext env;
1893 v8::HandleScope scope(isolate); 1893 v8::Isolate* isolate = CcTest::isolate();
1894 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
1894 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 1902 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
1895 v8::Local<v8::String> class_name = v8_str("the_class_name"); 1903 v8::Local<v8::String> class_name = v8_str("the_class_name");
1896 fun->SetClassName(class_name); 1904 fun->SetClassName(class_name);
1897 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun); 1905 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun);
1898 templ1->Set(isolate, "x", v8_num(10)); 1906 templ1->Set(isolate, "x", v8_num(10));
1899 templ1->Set(isolate, "y", v8_num(13)); 1907 templ1->Set(isolate, "y", v8_num(13));
1900 LocalContext env;
1901 Local<v8::Object> instance1 = 1908 Local<v8::Object> instance1 =
1902 templ1->NewInstance(env.local()).ToLocalChecked(); 1909 templ1->NewInstance(env.local()).ToLocalChecked();
1903 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); 1910 CHECK(class_name->StrictEquals(instance1->GetConstructorName()));
1904 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust()); 1911 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust());
1905 CHECK(v8_compile("(p.x == 10)") 1912 CHECK(CompileRun("(p.x == 10)")->BooleanValue(env.local()).FromJust());
1906 ->Run(env.local()) 1913 CHECK(CompileRun("(p.y == 13)")->BooleanValue(env.local()).FromJust());
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());
1915 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); 1914 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate);
1916 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); 1915 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1917 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); 1916 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate();
1918 templ2->Set(isolate, "a", v8_num(12)); 1917 templ2->Set(isolate, "a", v8_num(12));
1919 templ2->Set(isolate, "b", templ1); 1918 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(v8_compile("(q.nirk == 123)") 1923 CHECK(CompileRun("(q.nirk == 123)")->BooleanValue(env.local()).FromJust());
1924 ->Run(env.local()) 1924 CHECK(CompileRun("(q.a == 12)")->BooleanValue(env.local()).FromJust());
1925 .ToLocalChecked() 1925 CHECK(CompileRun("(q.b.x == 10)")->BooleanValue(env.local()).FromJust());
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)")
1926 ->BooleanValue(env.local()) 1940 ->BooleanValue(env.local())
1927 .FromJust()); 1941 .FromJust());
1928 CHECK(v8_compile("(q.a == 12)") 1942 CHECK(CompileRun("desc1 = Object.getOwnPropertyDescriptor(q, 'acc');"
1929 ->Run(env.local()) 1943 "(desc1.get === acc)")
1930 .ToLocalChecked()
1931 ->BooleanValue(env.local()) 1944 ->BooleanValue(env.local())
1932 .FromJust()); 1945 .FromJust());
1933 CHECK(v8_compile("(q.b.x == 10)") 1946 CHECK(CompileRun("desc2 = Object.getOwnPropertyDescriptor(q2, 'acc');"
1934 ->Run(env.local()) 1947 "(desc2.get === acc)")
1935 .ToLocalChecked()
1936 ->BooleanValue(env.local()) 1948 ->BooleanValue(env.local())
1937 .FromJust()); 1949 .FromJust());
1938 CHECK(v8_compile("(q.b.y == 13)") 1950 }
1939 ->Run(env.local()) 1951
1940 .ToLocalChecked() 1952 THREADED_TEST(IntegerValue) {
1941 ->BooleanValue(env.local()) 1953 LocalContext env;
1942 .FromJust()); 1954 v8::Isolate* isolate = CcTest::isolate();
1943 } 1955 v8::HandleScope scope(isolate);
1944 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 }
1945 2130
1946 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 2131 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1947 ApiTestFuzzer::Fuzz(); 2132 ApiTestFuzzer::Fuzz();
1948 args.GetReturnValue().Set(v8_num(17.2)); 2133 args.GetReturnValue().Set(v8_num(17.2));
1949 } 2134 }
1950 2135
1951 2136
1952 static void GetKnurd(Local<String> property, 2137 static void GetKnurd(Local<String> property,
1953 const v8::PropertyCallbackInfo<v8::Value>& info) { 2138 const v8::PropertyCallbackInfo<v8::Value>& info) {
1954 ApiTestFuzzer::Fuzz(); 2139 ApiTestFuzzer::Fuzz();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 CHECK(CompileRun("base1.prototype.knurd == undefined") 2198 CHECK(CompileRun("base1.prototype.knurd == undefined")
2014 ->BooleanValue(env.local()) 2199 ->BooleanValue(env.local())
2015 .FromJust()); 2200 .FromJust());
2016 2201
2017 CHECK(env->Global() 2202 CHECK(env->Global()
2018 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local()) 2203 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local())
2019 .ToLocalChecked() 2204 .ToLocalChecked()
2020 ->NewInstance(env.local()) 2205 ->NewInstance(env.local())
2021 .ToLocalChecked()) 2206 .ToLocalChecked())
2022 .FromJust()); 2207 .FromJust());
2023 CHECK_EQ(17.2, v8_compile("obj.flabby()") 2208 CHECK_EQ(17.2,
2024 ->Run(env.local()) 2209 CompileRun("obj.flabby()")->NumberValue(env.local()).FromJust());
2025 .ToLocalChecked() 2210 CHECK(CompileRun("'flabby' in obj")->BooleanValue(env.local()).FromJust());
2026 ->NumberValue(env.local()) 2211 CHECK_EQ(15.2, CompileRun("obj.knurd")->NumberValue(env.local()).FromJust());
2027 .FromJust()); 2212 CHECK(CompileRun("'knurd' in obj")->BooleanValue(env.local()).FromJust());
2028 CHECK(v8_compile("'flabby' in obj") 2213 CHECK_EQ(20.1, CompileRun("obj.v1")->NumberValue(env.local()).FromJust());
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());
2048 2214
2049 CHECK(env->Global() 2215 CHECK(env->Global()
2050 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local()) 2216 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local())
2051 .ToLocalChecked() 2217 .ToLocalChecked()
2052 ->NewInstance(env.local()) 2218 ->NewInstance(env.local())
2053 .ToLocalChecked()) 2219 .ToLocalChecked())
2054 .FromJust()); 2220 .FromJust());
2055 CHECK_EQ(17.2, v8_compile("obj2.flabby()") 2221 CHECK_EQ(17.2,
2056 ->Run(env.local()) 2222 CompileRun("obj2.flabby()")->NumberValue(env.local()).FromJust());
2057 .ToLocalChecked() 2223 CHECK(CompileRun("'flabby' in obj2")->BooleanValue(env.local()).FromJust());
2058 ->NumberValue(env.local()) 2224 CHECK_EQ(15.2, CompileRun("obj2.knurd")->NumberValue(env.local()).FromJust());
2059 .FromJust()); 2225 CHECK(CompileRun("'knurd' in obj2")->BooleanValue(env.local()).FromJust());
2060 CHECK(v8_compile("'flabby' in obj2") 2226 CHECK_EQ(10.1, CompileRun("obj2.v2")->NumberValue(env.local()).FromJust());
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());
2080 2227
2081 // base1 and base2 cannot cross reference to each's prototype 2228 // base1 and base2 cannot cross reference to each's prototype
2082 CHECK(v8_compile("obj.v2")->Run(env.local()).ToLocalChecked()->IsUndefined()); 2229 CHECK(CompileRun("obj.v2")->IsUndefined());
2083 CHECK( 2230 CHECK(CompileRun("obj2.v1")->IsUndefined());
2084 v8_compile("obj2.v1")->Run(env.local()).ToLocalChecked()->IsUndefined()); 2231 }
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 }
2085 } 2321 }
2086 2322
2087 2323
2088 // Helper functions for Interceptor/Accessor interaction tests 2324 // Helper functions for Interceptor/Accessor interaction tests
2089 2325
2090 void SimpleAccessorGetter(Local<String> name, 2326 void SimpleAccessorGetter(Local<String> name,
2091 const v8::PropertyCallbackInfo<v8::Value>& info) { 2327 const v8::PropertyCallbackInfo<v8::Value>& info) {
2092 Local<Object> self = Local<Object>::Cast(info.This()); 2328 Local<Object> self = Local<Object>::Cast(info.This());
2093 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(), 2329 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(),
2094 String::Concat(v8_str("accessor_"), name)) 2330 String::Concat(v8_str("accessor_"), name))
(...skipping 8621 matching lines...) Expand 10 before | Expand all | Expand 10 after
10716 LocalContext context; 10952 LocalContext context;
10717 v8::Isolate* isolate = context->GetIsolate(); 10953 v8::Isolate* isolate = context->GetIsolate();
10718 v8::HandleScope handle_scope(isolate); 10954 v8::HandleScope handle_scope(isolate);
10719 10955
10720 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10956 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10721 t1->SetHiddenPrototype(true); 10957 t1->SetHiddenPrototype(true);
10722 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10958 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
10723 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10959 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10724 t2->SetHiddenPrototype(true); 10960 t2->SetHiddenPrototype(true);
10725 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10961 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
10726 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate)); 10962 t2->InstanceTemplate()->Set(v8_str("objects"),
10963 v8::ObjectTemplate::New(isolate));
10727 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10964 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
10728 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10965 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
10729 t3->SetHiddenPrototype(true); 10966 t3->SetHiddenPrototype(true);
10730 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10967 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
10731 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10968 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
10732 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10969 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
10733 10970
10734 // Force dictionary-based properties. 10971 // Force dictionary-based properties.
10735 i::ScopedVector<char> name_buf(1024); 10972 i::ScopedVector<char> name_buf(1024);
10736 for (int i = 1; i <= 1000; i++) { 10973 for (int i = 1; i <= 1000; i++) {
(...skipping 27 matching lines...) Expand all
10764 // created object through JavaScript. 11001 // created object through JavaScript.
10765 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust()); 11002 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust());
10766 // PROPERTY_FILTER_NONE = 0 11003 // PROPERTY_FILTER_NONE = 0
10767 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);"); 11004 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);");
10768 11005
10769 ExpectInt32("names.length", 1006); 11006 ExpectInt32("names.length", 1006);
10770 ExpectTrue("names.indexOf(\"baz\") >= 0"); 11007 ExpectTrue("names.indexOf(\"baz\") >= 0");
10771 ExpectTrue("names.indexOf(\"boo\") >= 0"); 11008 ExpectTrue("names.indexOf(\"boo\") >= 0");
10772 ExpectTrue("names.indexOf(\"foo\") >= 0"); 11009 ExpectTrue("names.indexOf(\"foo\") >= 0");
10773 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 11010 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
11011 ExpectTrue("names.indexOf(\"objects\") >= 0");
10774 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 11012 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
10775 ExpectFalse("names[1005] == undefined"); 11013 ExpectFalse("names[1005] == undefined");
10776 } 11014 }
10777 11015
10778 11016
10779 // Getting property names of an object with a hidden and inherited 11017 // Getting property names of an object with a hidden and inherited
10780 // prototype should not duplicate the accessor properties inherited. 11018 // prototype should not duplicate the accessor properties inherited.
10781 THREADED_TEST(Regress269562) { 11019 THREADED_TEST(Regress269562) {
10782 i::FLAG_allow_natives_syntax = true; 11020 i::FLAG_allow_natives_syntax = true;
10783 LocalContext context; 11021 LocalContext context;
(...skipping 9570 matching lines...) Expand 10 before | Expand all | Expand 10 after
20354 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) 20592 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context)
20355 .ToLocalChecked() 20593 .ToLocalChecked()
20356 ->NewInstance(context) 20594 ->NewInstance(context)
20357 .ToLocalChecked(); 20595 .ToLocalChecked();
20358 Local<Object> object_with_hidden = 20596 Local<Object> object_with_hidden =
20359 Object::New(isolate); 20597 Object::New(isolate);
20360 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust(); 20598 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust();
20361 20599
20362 context->Exit(); 20600 context->Exit();
20363 20601
20364 // Template for object for second context. Values to test are put on it as 20602 LocalContext context2;
20365 // properties. 20603 v8::Local<v8::Object> global = context2->Global();
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);
20372 20604
20373 LocalContext context2(NULL, global_template); 20605 // Setup global variables.
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());
20374 20616
20375 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); 20617 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)");
20376 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype()) 20618 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype())
20377 .FromJust()); 20619 .FromJust());
20378 20620
20379 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); 20621 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)");
20380 CHECK(result2->IsNull()); 20622 CHECK(result2->IsNull());
20381 20623
20382 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); 20624 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)");
20383 CHECK(result3->Equals(context2.local(), global_object->GetPrototype()) 20625 CHECK(result3->Equals(context2.local(), global_object->GetPrototype())
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
21859 }; 22101 };
21860 22102
21861 22103
21862 class RequestInterruptTestWithMethodCall 22104 class RequestInterruptTestWithMethodCall
21863 : public RequestInterruptTestBaseWithSimpleInterrupt { 22105 : public RequestInterruptTestBaseWithSimpleInterrupt {
21864 public: 22106 public:
21865 virtual void TestBody() { 22107 virtual void TestBody() {
21866 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 22108 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
21867 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 22109 v8::Local<v8::Template> proto = t->PrototypeTemplate();
21868 proto->Set(v8_str("shouldContinue"), 22110 proto->Set(v8_str("shouldContinue"),
21869 Function::New(env_.local(), ShouldContinueCallback, 22111 FunctionTemplate::New(isolate_, ShouldContinueCallback,
21870 v8::External::New(isolate_, this)) 22112 v8::External::New(isolate_, this)));
21871 .ToLocalChecked());
21872 CHECK(env_->Global() 22113 CHECK(env_->Global()
21873 ->Set(env_.local(), v8_str("Klass"), 22114 ->Set(env_.local(), v8_str("Klass"),
21874 t->GetFunction(env_.local()).ToLocalChecked()) 22115 t->GetFunction(env_.local()).ToLocalChecked())
21875 .FromJust()); 22116 .FromJust());
21876 22117
21877 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 22118 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
21878 } 22119 }
21879 }; 22120 };
21880 22121
21881 22122
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
21927 }; 22168 };
21928 22169
21929 22170
21930 class RequestInterruptTestWithMethodCallAndInterceptor 22171 class RequestInterruptTestWithMethodCallAndInterceptor
21931 : public RequestInterruptTestBaseWithSimpleInterrupt { 22172 : public RequestInterruptTestBaseWithSimpleInterrupt {
21932 public: 22173 public:
21933 virtual void TestBody() { 22174 virtual void TestBody() {
21934 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 22175 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
21935 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 22176 v8::Local<v8::Template> proto = t->PrototypeTemplate();
21936 proto->Set(v8_str("shouldContinue"), 22177 proto->Set(v8_str("shouldContinue"),
21937 Function::New(env_.local(), ShouldContinueCallback, 22178 FunctionTemplate::New(isolate_, ShouldContinueCallback,
21938 v8::External::New(isolate_, this)) 22179 v8::External::New(isolate_, this)));
21939 .ToLocalChecked());
21940 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); 22180 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate();
21941 instance_template->SetHandler( 22181 instance_template->SetHandler(
21942 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); 22182 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor));
21943 22183
21944 CHECK(env_->Global() 22184 CHECK(env_->Global()
21945 ->Set(env_.local(), v8_str("Klass"), 22185 ->Set(env_.local(), v8_str("Klass"),
21946 t->GetFunction(env_.local()).ToLocalChecked()) 22186 t->GetFunction(env_.local()).ToLocalChecked())
21947 .FromJust()); 22187 .FromJust());
21948 22188
21949 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 22189 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
22141 Local<Value> result = CompileRun("func();"); 22381 Local<Value> result = CompileRun("func();");
22142 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust()); 22382 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust());
22143 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 22383 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
22144 // Verify function not cached 22384 // Verify function not cached
22145 auto serial_number = handle( 22385 auto serial_number = handle(
22146 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) 22386 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
22147 ->shared() 22387 ->shared()
22148 ->get_api_func_data() 22388 ->get_api_func_data()
22149 ->serial_number()), 22389 ->serial_number()),
22150 i_isolate); 22390 i_isolate);
22151 auto cache = i_isolate->function_cache(); 22391 auto cache = i_isolate->template_instantiations_cache();
22152 CHECK(cache->Lookup(serial_number)->IsTheHole()); 22392 CHECK(cache->Lookup(serial_number)->IsTheHole());
22153 // Verify that each Function::New creates a new function instance 22393 // Verify that each Function::New creates a new function instance
22154 Local<Object> data2 = v8::Object::New(isolate); 22394 Local<Object> data2 = v8::Object::New(isolate);
22155 function_new_expected_env = data2; 22395 function_new_expected_env = data2;
22156 Local<Function> func2 = 22396 Local<Function> func2 =
22157 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked(); 22397 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked();
22158 CHECK(!func2->IsNull()); 22398 CHECK(!func2->IsNull());
22159 CHECK(!func->Equals(env.local(), func2).FromJust()); 22399 CHECK(!func->Equals(env.local(), func2).FromJust());
22160 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); 22400 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust());
22161 Local<Value> result2 = CompileRun("func2();"); 22401 Local<Value> result2 = CompileRun("func2();");
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
24639 CHECK(proxy->GetTarget()->SameValue(target)); 24879 CHECK(proxy->GetTarget()->SameValue(target));
24640 CHECK(proxy->GetHandler()->SameValue(handler)); 24880 CHECK(proxy->GetHandler()->SameValue(handler));
24641 24881
24642 proxy->Revoke(); 24882 proxy->Revoke();
24643 CHECK(proxy->IsProxy()); 24883 CHECK(proxy->IsProxy());
24644 CHECK(!target->IsProxy()); 24884 CHECK(!target->IsProxy());
24645 CHECK(proxy->IsRevoked()); 24885 CHECK(proxy->IsRevoked());
24646 CHECK(proxy->GetTarget()->SameValue(target)); 24886 CHECK(proxy->GetTarget()->SameValue(target));
24647 CHECK(proxy->GetHandler()->IsNull()); 24887 CHECK(proxy->GetHandler()->IsNull());
24648 } 24888 }
OLDNEW
« src/api-natives.cc ('K') | « src/x87/builtins-x87.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698