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

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: Removed asserts preventing JSReceiver properties in ObjectTemplate 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 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; 1908 templ1->Set(v8_str("foo"), acc);
1901 Local<v8::Object> instance1 = 1909 Local<v8::Object> instance1 =
1902 templ1->NewInstance(env.local()).ToLocalChecked(); 1910 templ1->NewInstance(env.local()).ToLocalChecked();
1903 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); 1911 CHECK(class_name->StrictEquals(instance1->GetConstructorName()));
1904 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust()); 1912 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust());
1905 CHECK(v8_compile("(p.x == 10)") 1913 CHECK(CompileRun("(p.x == 10)")->BooleanValue(env.local()).FromJust());
1906 ->Run(env.local()) 1914 CHECK(CompileRun("(p.y == 13)")->BooleanValue(env.local()).FromJust());
1907 .ToLocalChecked() 1915 CHECK(CompileRun("(p.foo() == 42)")->BooleanValue(env.local()).FromJust());
1908 ->BooleanValue(env.local()) 1916 CHECK(CompileRun("(p.foo == acc)")->BooleanValue(env.local()).FromJust());
1909 .FromJust()); 1917 // Ensure that foo become a data field.
1910 CHECK(v8_compile("(p.y == 13)") 1918 CompileRun("p.foo = function() {}");
1911 ->Run(env.local())
1912 .ToLocalChecked()
1913 ->BooleanValue(env.local())
1914 .FromJust());
1915 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); 1919 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate);
1916 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); 1920 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1917 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); 1921 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate();
1918 templ2->Set(isolate, "a", v8_num(12)); 1922 templ2->Set(isolate, "a", v8_num(12));
1919 templ2->Set(isolate, "b", templ1); 1923 templ2->Set(isolate, "b", templ1);
1924 templ2->Set(v8_str("bar"), acc);
1925 templ2->SetAccessorProperty(v8_str("acc"), acc);
1920 Local<v8::Object> instance2 = 1926 Local<v8::Object> instance2 =
1921 templ2->NewInstance(env.local()).ToLocalChecked(); 1927 templ2->NewInstance(env.local()).ToLocalChecked();
1922 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust()); 1928 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust());
1923 CHECK(v8_compile("(q.nirk == 123)") 1929 CHECK(CompileRun("(q.nirk == 123)")->BooleanValue(env.local()).FromJust());
1924 ->Run(env.local()) 1930 CHECK(CompileRun("(q.a == 12)")->BooleanValue(env.local()).FromJust());
1925 .ToLocalChecked() 1931 CHECK(CompileRun("(q.b.x == 10)")->BooleanValue(env.local()).FromJust());
1932 CHECK(CompileRun("(q.b.y == 13)")->BooleanValue(env.local()).FromJust());
1933 CHECK(CompileRun("(q.b.foo() == 42)")->BooleanValue(env.local()).FromJust());
1934 CHECK(CompileRun("(q.b.foo === acc)")->BooleanValue(env.local()).FromJust());
1935 CHECK(CompileRun("(q.b !== p)")->BooleanValue(env.local()).FromJust());
1936 CHECK(CompileRun("(q.acc == 42)")->BooleanValue(env.local()).FromJust());
1937 CHECK(CompileRun("(q.bar() == 42)")->BooleanValue(env.local()).FromJust());
1938 CHECK(CompileRun("(q.bar == acc)")->BooleanValue(env.local()).FromJust());
1939
1940 instance2 = templ2->NewInstance(env.local()).ToLocalChecked();
1941 CHECK(env->Global()->Set(env.local(), v8_str("q2"), instance2).FromJust());
1942 CHECK(CompileRun("(q2.nirk == 123)")->BooleanValue(env.local()).FromJust());
1943 CHECK(CompileRun("(q2.a == 12)")->BooleanValue(env.local()).FromJust());
1944 CHECK(CompileRun("(q2.b.x == 10)")->BooleanValue(env.local()).FromJust());
1945 CHECK(CompileRun("(q2.b.y == 13)")->BooleanValue(env.local()).FromJust());
1946 CHECK(CompileRun("(q2.b.foo() == 42)")->BooleanValue(env.local()).FromJust());
1947 CHECK(CompileRun("(q2.b.foo === acc)")->BooleanValue(env.local()).FromJust());
1948 CHECK(CompileRun("(q2.acc == 42)")->BooleanValue(env.local()).FromJust());
1949 CHECK(CompileRun("(q2.bar() == 42)")->BooleanValue(env.local()).FromJust());
1950 CHECK(CompileRun("(q2.bar === acc)")->BooleanValue(env.local()).FromJust());
1951
1952 CHECK(CompileRun("(q.b !== q2.b)")->BooleanValue(env.local()).FromJust());
1953 CHECK(CompileRun("q.b.x = 17; (q2.b.x == 10)")
1926 ->BooleanValue(env.local()) 1954 ->BooleanValue(env.local())
1927 .FromJust()); 1955 .FromJust());
1928 CHECK(v8_compile("(q.a == 12)") 1956 CHECK(CompileRun("desc1 = Object.getOwnPropertyDescriptor(q, 'acc');"
1929 ->Run(env.local()) 1957 "(desc1.get === acc)")
1930 .ToLocalChecked()
1931 ->BooleanValue(env.local()) 1958 ->BooleanValue(env.local())
1932 .FromJust()); 1959 .FromJust());
1933 CHECK(v8_compile("(q.b.x == 10)") 1960 CHECK(CompileRun("desc2 = Object.getOwnPropertyDescriptor(q2, 'acc');"
1934 ->Run(env.local()) 1961 "(desc2.get === acc)")
1935 .ToLocalChecked()
1936 ->BooleanValue(env.local()) 1962 ->BooleanValue(env.local())
1937 .FromJust()); 1963 .FromJust());
1938 CHECK(v8_compile("(q.b.y == 13)") 1964 }
1939 ->Run(env.local()) 1965
1940 .ToLocalChecked() 1966 THREADED_TEST(IntegerValue) {
1941 ->BooleanValue(env.local()) 1967 LocalContext env;
1942 .FromJust()); 1968 v8::Isolate* isolate = CcTest::isolate();
1943 } 1969 v8::HandleScope scope(isolate);
1944 1970
1971 CHECK_EQ(0, CompileRun("undefined")->IntegerValue(env.local()).FromJust());
1972 }
1973
1974 static void GetNirk(Local<String> name,
1975 const v8::PropertyCallbackInfo<v8::Value>& info) {
1976 ApiTestFuzzer::Fuzz();
1977 info.GetReturnValue().Set(v8_num(900));
1978 }
1979
1980 static void GetRino(Local<String> name,
1981 const v8::PropertyCallbackInfo<v8::Value>& info) {
1982 ApiTestFuzzer::Fuzz();
1983 info.GetReturnValue().Set(v8_num(560));
1984 }
1985
1986 enum ObjectInstantiationMode {
1987 // Create object using ObjectTemplate::NewInstance.
1988 ObjectTemplate_NewInstance,
1989 // Create object using FunctionTemplate::NewInstance on constructor.
1990 Constructor_GetFunction_NewInstance,
1991 // Create object using new operator on constructor.
1992 Constructor_GetFunction_New
1993 };
1994
1995 // Test object instance creation using a function template with an instance
1996 // template inherited from another function template with accessors and data
1997 // properties in prototype template.
1998 static void TestObjectTemplateInheritedWithPrototype(
1999 ObjectInstantiationMode mode) {
2000 LocalContext env;
2001 v8::Isolate* isolate = CcTest::isolate();
2002 v8::HandleScope scope(isolate);
2003
2004 Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
2005 fun_A->SetClassName(v8_str("A"));
2006 v8::Local<v8::ObjectTemplate> prototype_templ = fun_A->PrototypeTemplate();
2007 prototype_templ->Set(isolate, "a", v8_num(113));
2008 prototype_templ->SetNativeDataProperty(v8_str("nirk"), GetNirk);
2009 prototype_templ->Set(isolate, "b", v8_num(153));
2010
2011 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
2012 v8::Local<v8::String> class_name = v8_str("B");
2013 fun_B->SetClassName(class_name);
2014 fun_B->Inherit(fun_A);
2015 prototype_templ = fun_B->PrototypeTemplate();
2016 prototype_templ->Set(isolate, "c", v8_num(713));
2017 prototype_templ->SetNativeDataProperty(v8_str("rino"), GetRino);
2018 prototype_templ->Set(isolate, "d", v8_num(753));
2019
2020 Local<ObjectTemplate> templ = fun_B->InstanceTemplate();
2021 templ->Set(isolate, "x", v8_num(10));
2022 templ->Set(isolate, "y", v8_num(13));
2023
2024 // Perform several iterations to trigger creation from cached boilerplate.
2025 for (int i = 0; i < 3; i++) {
2026 Local<v8::Object> instance;
2027 switch (mode) {
2028 case ObjectTemplate_NewInstance:
2029 instance = templ->NewInstance(env.local()).ToLocalChecked();
2030 break;
2031
2032 case Constructor_GetFunction_NewInstance: {
2033 Local<v8::Function> function_B =
2034 fun_B->GetFunction(env.local()).ToLocalChecked();
2035 instance = function_B->NewInstance(env.local()).ToLocalChecked();
2036 break;
2037 }
2038 case Constructor_GetFunction_New: {
2039 Local<v8::Function> function_B =
2040 fun_B->GetFunction(env.local()).ToLocalChecked();
2041 if (i == 0) {
2042 CHECK(env->Global()
2043 ->Set(env.local(), class_name, function_B)
2044 .FromJust());
2045 }
2046 instance =
2047 CompileRun("new B()")->ToObject(env.local()).ToLocalChecked();
2048 break;
2049 }
2050 default:
2051 UNREACHABLE();
2052 }
2053
2054 CHECK(class_name->StrictEquals(instance->GetConstructorName()));
2055 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust());
2056
2057 CHECK_EQ(10, CompileRun("o.x")->IntegerValue(env.local()).FromJust());
2058 CHECK_EQ(13, CompileRun("o.y")->IntegerValue(env.local()).FromJust());
2059
2060 CHECK_EQ(113, CompileRun("o.a")->IntegerValue(env.local()).FromJust());
2061 CHECK_EQ(900, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust());
2062 CHECK_EQ(153, CompileRun("o.b")->IntegerValue(env.local()).FromJust());
2063 CHECK_EQ(713, CompileRun("o.c")->IntegerValue(env.local()).FromJust());
2064 CHECK_EQ(560, CompileRun("o.rino")->IntegerValue(env.local()).FromJust());
2065 CHECK_EQ(753, CompileRun("o.d")->IntegerValue(env.local()).FromJust());
2066 }
2067 }
2068
2069 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype1) {
2070 TestObjectTemplateInheritedWithPrototype(ObjectTemplate_NewInstance);
2071 }
2072
2073 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype2) {
2074 TestObjectTemplateInheritedWithPrototype(Constructor_GetFunction_NewInstance);
2075 }
2076
2077 THREADED_TEST(TestObjectTemplateInheritedWithAccessorsInPrototype3) {
2078 TestObjectTemplateInheritedWithPrototype(Constructor_GetFunction_New);
2079 }
2080
2081 // Test object instance creation using a function template without an instance
2082 // template inherited from another function template.
2083 static void TestObjectTemplateInheritedWithoutInstanceTemplate(
2084 ObjectInstantiationMode mode) {
2085 LocalContext env;
2086 v8::Isolate* isolate = CcTest::isolate();
2087 v8::HandleScope scope(isolate);
2088
2089 Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
2090 fun_A->SetClassName(v8_str("A"));
2091
2092 Local<ObjectTemplate> templ_A = fun_A->InstanceTemplate();
2093 templ_A->SetNativeDataProperty(v8_str("nirk"), GetNirk);
2094 templ_A->SetNativeDataProperty(v8_str("rino"), GetRino);
2095
2096 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
2097 v8::Local<v8::String> class_name = v8_str("B");
2098 fun_B->SetClassName(class_name);
2099 fun_B->Inherit(fun_A);
2100
2101 // Perform several iterations to trigger creation from cached boilerplate.
2102 for (int i = 0; i < 3; i++) {
2103 Local<v8::Object> instance;
2104 switch (mode) {
2105 case Constructor_GetFunction_NewInstance: {
2106 Local<v8::Function> function_B =
2107 fun_B->GetFunction(env.local()).ToLocalChecked();
2108 instance = function_B->NewInstance(env.local()).ToLocalChecked();
2109 break;
2110 }
2111 case Constructor_GetFunction_New: {
2112 Local<v8::Function> function_B =
2113 fun_B->GetFunction(env.local()).ToLocalChecked();
2114 if (i == 0) {
2115 CHECK(env->Global()
2116 ->Set(env.local(), class_name, function_B)
2117 .FromJust());
2118 }
2119 instance =
2120 CompileRun("new B()")->ToObject(env.local()).ToLocalChecked();
2121 break;
2122 }
2123 default:
2124 UNREACHABLE();
2125 }
2126
2127 CHECK(class_name->StrictEquals(instance->GetConstructorName()));
2128 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust());
2129
2130 CHECK_EQ(900, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust());
2131 CHECK_EQ(560, CompileRun("o.rino")->IntegerValue(env.local()).FromJust());
2132 }
2133 }
2134
2135 THREADED_TEST(TestObjectTemplateInheritedWithPrototype1) {
2136 TestObjectTemplateInheritedWithoutInstanceTemplate(
2137 Constructor_GetFunction_NewInstance);
2138 }
2139
2140 THREADED_TEST(TestObjectTemplateInheritedWithPrototype2) {
2141 TestObjectTemplateInheritedWithoutInstanceTemplate(
2142 Constructor_GetFunction_New);
2143 }
1945 2144
1946 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 2145 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1947 ApiTestFuzzer::Fuzz(); 2146 ApiTestFuzzer::Fuzz();
1948 args.GetReturnValue().Set(v8_num(17.2)); 2147 args.GetReturnValue().Set(v8_num(17.2));
1949 } 2148 }
1950 2149
1951 2150
1952 static void GetKnurd(Local<String> property, 2151 static void GetKnurd(Local<String> property,
1953 const v8::PropertyCallbackInfo<v8::Value>& info) { 2152 const v8::PropertyCallbackInfo<v8::Value>& info) {
1954 ApiTestFuzzer::Fuzz(); 2153 ApiTestFuzzer::Fuzz();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 CHECK(CompileRun("base1.prototype.knurd == undefined") 2212 CHECK(CompileRun("base1.prototype.knurd == undefined")
2014 ->BooleanValue(env.local()) 2213 ->BooleanValue(env.local())
2015 .FromJust()); 2214 .FromJust());
2016 2215
2017 CHECK(env->Global() 2216 CHECK(env->Global()
2018 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local()) 2217 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local())
2019 .ToLocalChecked() 2218 .ToLocalChecked()
2020 ->NewInstance(env.local()) 2219 ->NewInstance(env.local())
2021 .ToLocalChecked()) 2220 .ToLocalChecked())
2022 .FromJust()); 2221 .FromJust());
2023 CHECK_EQ(17.2, v8_compile("obj.flabby()") 2222 CHECK_EQ(17.2,
2024 ->Run(env.local()) 2223 CompileRun("obj.flabby()")->NumberValue(env.local()).FromJust());
2025 .ToLocalChecked() 2224 CHECK(CompileRun("'flabby' in obj")->BooleanValue(env.local()).FromJust());
2026 ->NumberValue(env.local()) 2225 CHECK_EQ(15.2, CompileRun("obj.knurd")->NumberValue(env.local()).FromJust());
2027 .FromJust()); 2226 CHECK(CompileRun("'knurd' in obj")->BooleanValue(env.local()).FromJust());
2028 CHECK(v8_compile("'flabby' in obj") 2227 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 2228
2049 CHECK(env->Global() 2229 CHECK(env->Global()
2050 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local()) 2230 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local())
2051 .ToLocalChecked() 2231 .ToLocalChecked()
2052 ->NewInstance(env.local()) 2232 ->NewInstance(env.local())
2053 .ToLocalChecked()) 2233 .ToLocalChecked())
2054 .FromJust()); 2234 .FromJust());
2055 CHECK_EQ(17.2, v8_compile("obj2.flabby()") 2235 CHECK_EQ(17.2,
2056 ->Run(env.local()) 2236 CompileRun("obj2.flabby()")->NumberValue(env.local()).FromJust());
2057 .ToLocalChecked() 2237 CHECK(CompileRun("'flabby' in obj2")->BooleanValue(env.local()).FromJust());
2058 ->NumberValue(env.local()) 2238 CHECK_EQ(15.2, CompileRun("obj2.knurd")->NumberValue(env.local()).FromJust());
2059 .FromJust()); 2239 CHECK(CompileRun("'knurd' in obj2")->BooleanValue(env.local()).FromJust());
2060 CHECK(v8_compile("'flabby' in obj2") 2240 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 2241
2081 // base1 and base2 cannot cross reference to each's prototype 2242 // base1 and base2 cannot cross reference to each's prototype
2082 CHECK(v8_compile("obj.v2")->Run(env.local()).ToLocalChecked()->IsUndefined()); 2243 CHECK(CompileRun("obj.v2")->IsUndefined());
2083 CHECK( 2244 CHECK(CompileRun("obj2.v1")->IsUndefined());
2084 v8_compile("obj2.v1")->Run(env.local()).ToLocalChecked()->IsUndefined()); 2245 }
2246
2247 THREADED_TEST(DescriptorInheritance2) {
2248 LocalContext env;
2249 v8::Isolate* isolate = CcTest::isolate();
2250 v8::HandleScope scope(isolate);
2251 v8::Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate);
2252 fun_A->SetClassName(v8_str("A"));
2253 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd1"), GetKnurd);
2254 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk1"), GetNirk);
2255 fun_A->InstanceTemplate()->SetNativeDataProperty(v8_str("rino1"), GetRino);
2256
2257 v8::Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate);
2258 fun_B->SetClassName(v8_str("B"));
2259 fun_B->Inherit(fun_A);
2260
2261 v8::Local<v8::FunctionTemplate> fun_C = v8::FunctionTemplate::New(isolate);
2262 fun_C->SetClassName(v8_str("C"));
2263 fun_C->Inherit(fun_B);
2264 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd2"), GetKnurd);
2265 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk2"), GetNirk);
2266 fun_C->InstanceTemplate()->SetNativeDataProperty(v8_str("rino2"), GetRino);
2267
2268 v8::Local<v8::FunctionTemplate> fun_D = v8::FunctionTemplate::New(isolate);
2269 fun_D->SetClassName(v8_str("D"));
2270 fun_D->Inherit(fun_C);
2271
2272 v8::Local<v8::FunctionTemplate> fun_E = v8::FunctionTemplate::New(isolate);
2273 fun_E->SetClassName(v8_str("E"));
2274 fun_E->Inherit(fun_D);
2275 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("knurd3"), GetKnurd);
2276 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("nirk3"), GetNirk);
2277 fun_E->InstanceTemplate()->SetNativeDataProperty(v8_str("rino3"), GetRino);
2278
2279 v8::Local<v8::FunctionTemplate> fun_F = v8::FunctionTemplate::New(isolate);
2280 fun_F->SetClassName(v8_str("F"));
2281 fun_F->Inherit(fun_E);
2282 v8::Local<v8::ObjectTemplate> templ = fun_F->InstanceTemplate();
2283 const int kDataPropertiesNumber = 100;
2284 for (int i = 0; i < kDataPropertiesNumber; i++) {
2285 v8::Local<v8::Value> val = v8_num(i);
2286 v8::Local<v8::String> val_str = val->ToString(env.local()).ToLocalChecked();
2287 v8::Local<v8::String> name = String::Concat(v8_str("p"), val_str);
2288
2289 templ->Set(name, val);
2290 templ->Set(val_str, val);
2291 }
2292
2293 CHECK(env->Global()
2294 ->Set(env.local(), v8_str("F"),
2295 fun_F->GetFunction(env.local()).ToLocalChecked())
2296 .FromJust());
2297
2298 v8::Local<v8::Script> script = v8_compile("o = new F()");
2299
2300 for (int i = 0; i < 100; i++) {
2301 v8::HandleScope scope(isolate);
2302 script->Run(env.local()).ToLocalChecked();
2303 }
2304 v8::Local<v8::Object> object = script->Run(env.local())
2305 .ToLocalChecked()
2306 ->ToObject(env.local())
2307 .ToLocalChecked();
2308
2309 CHECK_EQ(15.2, CompileRun("o.knurd1")->NumberValue(env.local()).FromJust());
2310 CHECK_EQ(15.2, CompileRun("o.knurd2")->NumberValue(env.local()).FromJust());
2311 CHECK_EQ(15.2, CompileRun("o.knurd3")->NumberValue(env.local()).FromJust());
2312
2313 CHECK_EQ(900, CompileRun("o.nirk1")->IntegerValue(env.local()).FromJust());
2314 CHECK_EQ(900, CompileRun("o.nirk2")->IntegerValue(env.local()).FromJust());
2315 CHECK_EQ(900, CompileRun("o.nirk3")->IntegerValue(env.local()).FromJust());
2316
2317 CHECK_EQ(560, CompileRun("o.rino1")->IntegerValue(env.local()).FromJust());
2318 CHECK_EQ(560, CompileRun("o.rino2")->IntegerValue(env.local()).FromJust());
2319 CHECK_EQ(560, CompileRun("o.rino3")->IntegerValue(env.local()).FromJust());
2320
2321 for (int i = 0; i < kDataPropertiesNumber; i++) {
2322 v8::Local<v8::Value> val = v8_num(i);
2323 v8::Local<v8::String> val_str = val->ToString(env.local()).ToLocalChecked();
2324 v8::Local<v8::String> name = String::Concat(v8_str("p"), val_str);
2325
2326 CHECK_EQ(i, object->Get(env.local(), name)
2327 .ToLocalChecked()
2328 ->IntegerValue(env.local())
2329 .FromJust());
2330 CHECK_EQ(i, object->Get(env.local(), val)
2331 .ToLocalChecked()
2332 ->IntegerValue(env.local())
2333 .FromJust());
2334 }
2085 } 2335 }
2086 2336
2087 2337
2088 // Helper functions for Interceptor/Accessor interaction tests 2338 // Helper functions for Interceptor/Accessor interaction tests
2089 2339
2090 void SimpleAccessorGetter(Local<String> name, 2340 void SimpleAccessorGetter(Local<String> name,
2091 const v8::PropertyCallbackInfo<v8::Value>& info) { 2341 const v8::PropertyCallbackInfo<v8::Value>& info) {
2092 Local<Object> self = Local<Object>::Cast(info.This()); 2342 Local<Object> self = Local<Object>::Cast(info.This());
2093 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(), 2343 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(),
2094 String::Concat(v8_str("accessor_"), name)) 2344 String::Concat(v8_str("accessor_"), name))
(...skipping 8621 matching lines...) Expand 10 before | Expand all | Expand 10 after
10716 LocalContext context; 10966 LocalContext context;
10717 v8::Isolate* isolate = context->GetIsolate(); 10967 v8::Isolate* isolate = context->GetIsolate();
10718 v8::HandleScope handle_scope(isolate); 10968 v8::HandleScope handle_scope(isolate);
10719 10969
10720 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10970 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10721 t1->SetHiddenPrototype(true); 10971 t1->SetHiddenPrototype(true);
10722 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10972 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
10723 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10973 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10724 t2->SetHiddenPrototype(true); 10974 t2->SetHiddenPrototype(true);
10725 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10975 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
10726 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New(isolate)); 10976 t2->InstanceTemplate()->Set(v8_str("objects"),
10977 v8::ObjectTemplate::New(isolate));
10727 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10978 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
10728 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10979 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
10729 t3->SetHiddenPrototype(true); 10980 t3->SetHiddenPrototype(true);
10730 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10981 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
10731 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10982 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
10732 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10983 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
10733 10984
10734 // Force dictionary-based properties. 10985 // Force dictionary-based properties.
10735 i::ScopedVector<char> name_buf(1024); 10986 i::ScopedVector<char> name_buf(1024);
10736 for (int i = 1; i <= 1000; i++) { 10987 for (int i = 1; i <= 1000; i++) {
(...skipping 27 matching lines...) Expand all
10764 // created object through JavaScript. 11015 // created object through JavaScript.
10765 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust()); 11016 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust());
10766 // PROPERTY_FILTER_NONE = 0 11017 // PROPERTY_FILTER_NONE = 0
10767 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);"); 11018 CompileRun("var names = %GetOwnPropertyKeys(obj, 0);");
10768 11019
10769 ExpectInt32("names.length", 1006); 11020 ExpectInt32("names.length", 1006);
10770 ExpectTrue("names.indexOf(\"baz\") >= 0"); 11021 ExpectTrue("names.indexOf(\"baz\") >= 0");
10771 ExpectTrue("names.indexOf(\"boo\") >= 0"); 11022 ExpectTrue("names.indexOf(\"boo\") >= 0");
10772 ExpectTrue("names.indexOf(\"foo\") >= 0"); 11023 ExpectTrue("names.indexOf(\"foo\") >= 0");
10773 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 11024 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
11025 ExpectTrue("names.indexOf(\"objects\") >= 0");
10774 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 11026 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
10775 ExpectFalse("names[1005] == undefined"); 11027 ExpectFalse("names[1005] == undefined");
10776 } 11028 }
10777 11029
10778 11030
10779 // Getting property names of an object with a hidden and inherited 11031 // Getting property names of an object with a hidden and inherited
10780 // prototype should not duplicate the accessor properties inherited. 11032 // prototype should not duplicate the accessor properties inherited.
10781 THREADED_TEST(Regress269562) { 11033 THREADED_TEST(Regress269562) {
10782 i::FLAG_allow_natives_syntax = true; 11034 i::FLAG_allow_natives_syntax = true;
10783 LocalContext context; 11035 LocalContext context;
(...skipping 9570 matching lines...) Expand 10 before | Expand all | Expand 10 after
20354 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) 20606 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context)
20355 .ToLocalChecked() 20607 .ToLocalChecked()
20356 ->NewInstance(context) 20608 ->NewInstance(context)
20357 .ToLocalChecked(); 20609 .ToLocalChecked();
20358 Local<Object> object_with_hidden = 20610 Local<Object> object_with_hidden =
20359 Object::New(isolate); 20611 Object::New(isolate);
20360 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust(); 20612 object_with_hidden->SetPrototype(context, hidden_prototype).FromJust();
20361 20613
20362 context->Exit(); 20614 context->Exit();
20363 20615
20364 // Template for object for second context. Values to test are put on it as 20616 LocalContext context2;
20365 // properties. 20617 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 20618
20373 LocalContext context2(NULL, global_template); 20619 // Setup global variables.
20620 CHECK(global->Set(context2.local(), v8_str("simple"), simple_object)
20621 .FromJust());
20622 CHECK(global->Set(context2.local(), v8_str("protected"), protected_object)
20623 .FromJust());
20624 CHECK(global->Set(context2.local(), v8_str("global"), global_object)
20625 .FromJust());
20626 CHECK(
20627 global->Set(context2.local(), v8_str("proxy"), proxy_object).FromJust());
20628 CHECK(global->Set(context2.local(), v8_str("hidden"), object_with_hidden)
20629 .FromJust());
20374 20630
20375 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); 20631 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)");
20376 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype()) 20632 CHECK(result1->Equals(context2.local(), simple_object->GetPrototype())
20377 .FromJust()); 20633 .FromJust());
20378 20634
20379 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); 20635 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)");
20380 CHECK(result2->IsNull()); 20636 CHECK(result2->IsNull());
20381 20637
20382 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); 20638 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)");
20383 CHECK(result3->Equals(context2.local(), global_object->GetPrototype()) 20639 CHECK(result3->Equals(context2.local(), global_object->GetPrototype())
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
21859 }; 22115 };
21860 22116
21861 22117
21862 class RequestInterruptTestWithMethodCall 22118 class RequestInterruptTestWithMethodCall
21863 : public RequestInterruptTestBaseWithSimpleInterrupt { 22119 : public RequestInterruptTestBaseWithSimpleInterrupt {
21864 public: 22120 public:
21865 virtual void TestBody() { 22121 virtual void TestBody() {
21866 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 22122 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
21867 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 22123 v8::Local<v8::Template> proto = t->PrototypeTemplate();
21868 proto->Set(v8_str("shouldContinue"), 22124 proto->Set(v8_str("shouldContinue"),
21869 Function::New(env_.local(), ShouldContinueCallback, 22125 FunctionTemplate::New(isolate_, ShouldContinueCallback,
21870 v8::External::New(isolate_, this)) 22126 v8::External::New(isolate_, this)));
21871 .ToLocalChecked());
21872 CHECK(env_->Global() 22127 CHECK(env_->Global()
21873 ->Set(env_.local(), v8_str("Klass"), 22128 ->Set(env_.local(), v8_str("Klass"),
21874 t->GetFunction(env_.local()).ToLocalChecked()) 22129 t->GetFunction(env_.local()).ToLocalChecked())
21875 .FromJust()); 22130 .FromJust());
21876 22131
21877 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 22132 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
21878 } 22133 }
21879 }; 22134 };
21880 22135
21881 22136
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
21927 }; 22182 };
21928 22183
21929 22184
21930 class RequestInterruptTestWithMethodCallAndInterceptor 22185 class RequestInterruptTestWithMethodCallAndInterceptor
21931 : public RequestInterruptTestBaseWithSimpleInterrupt { 22186 : public RequestInterruptTestBaseWithSimpleInterrupt {
21932 public: 22187 public:
21933 virtual void TestBody() { 22188 virtual void TestBody() {
21934 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 22189 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
21935 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 22190 v8::Local<v8::Template> proto = t->PrototypeTemplate();
21936 proto->Set(v8_str("shouldContinue"), 22191 proto->Set(v8_str("shouldContinue"),
21937 Function::New(env_.local(), ShouldContinueCallback, 22192 FunctionTemplate::New(isolate_, ShouldContinueCallback,
21938 v8::External::New(isolate_, this)) 22193 v8::External::New(isolate_, this)));
21939 .ToLocalChecked());
21940 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); 22194 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate();
21941 instance_template->SetHandler( 22195 instance_template->SetHandler(
21942 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); 22196 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor));
21943 22197
21944 CHECK(env_->Global() 22198 CHECK(env_->Global()
21945 ->Set(env_.local(), v8_str("Klass"), 22199 ->Set(env_.local(), v8_str("Klass"),
21946 t->GetFunction(env_.local()).ToLocalChecked()) 22200 t->GetFunction(env_.local()).ToLocalChecked())
21947 .FromJust()); 22201 .FromJust());
21948 22202
21949 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 22203 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();"); 22395 Local<Value> result = CompileRun("func();");
22142 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust()); 22396 CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust());
22143 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 22397 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
22144 // Verify function not cached 22398 // Verify function not cached
22145 auto serial_number = handle( 22399 auto serial_number = handle(
22146 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) 22400 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
22147 ->shared() 22401 ->shared()
22148 ->get_api_func_data() 22402 ->get_api_func_data()
22149 ->serial_number()), 22403 ->serial_number()),
22150 i_isolate); 22404 i_isolate);
22151 auto cache = i_isolate->function_cache(); 22405 auto cache = i_isolate->template_instantiations_cache();
22152 CHECK(cache->Lookup(serial_number)->IsTheHole()); 22406 CHECK(cache->Lookup(serial_number)->IsTheHole());
22153 // Verify that each Function::New creates a new function instance 22407 // Verify that each Function::New creates a new function instance
22154 Local<Object> data2 = v8::Object::New(isolate); 22408 Local<Object> data2 = v8::Object::New(isolate);
22155 function_new_expected_env = data2; 22409 function_new_expected_env = data2;
22156 Local<Function> func2 = 22410 Local<Function> func2 =
22157 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked(); 22411 Function::New(env.local(), FunctionNewCallback, data2).ToLocalChecked();
22158 CHECK(!func2->IsNull()); 22412 CHECK(!func2->IsNull());
22159 CHECK(!func->Equals(env.local(), func2).FromJust()); 22413 CHECK(!func->Equals(env.local(), func2).FromJust());
22160 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); 22414 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust());
22161 Local<Value> result2 = CompileRun("func2();"); 22415 Local<Value> result2 = CompileRun("func2();");
(...skipping 2477 matching lines...) Expand 10 before | Expand all | Expand 10 after
24639 CHECK(proxy->GetTarget()->SameValue(target)); 24893 CHECK(proxy->GetTarget()->SameValue(target));
24640 CHECK(proxy->GetHandler()->SameValue(handler)); 24894 CHECK(proxy->GetHandler()->SameValue(handler));
24641 24895
24642 proxy->Revoke(); 24896 proxy->Revoke();
24643 CHECK(proxy->IsProxy()); 24897 CHECK(proxy->IsProxy());
24644 CHECK(!target->IsProxy()); 24898 CHECK(!target->IsProxy());
24645 CHECK(proxy->IsRevoked()); 24899 CHECK(proxy->IsRevoked());
24646 CHECK(proxy->GetTarget()->SameValue(target)); 24900 CHECK(proxy->GetTarget()->SameValue(target));
24647 CHECK(proxy->GetHandler()->IsNull()); 24901 CHECK(proxy->GetHandler()->IsNull());
24648 } 24902 }
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