OLD | NEW |
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 2124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 THREADED_TEST(TestObjectTemplateInheritedWithPrototype1) { | 2135 THREADED_TEST(TestObjectTemplateInheritedWithPrototype1) { |
2136 TestObjectTemplateInheritedWithoutInstanceTemplate( | 2136 TestObjectTemplateInheritedWithoutInstanceTemplate( |
2137 Constructor_GetFunction_NewInstance); | 2137 Constructor_GetFunction_NewInstance); |
2138 } | 2138 } |
2139 | 2139 |
2140 THREADED_TEST(TestObjectTemplateInheritedWithPrototype2) { | 2140 THREADED_TEST(TestObjectTemplateInheritedWithPrototype2) { |
2141 TestObjectTemplateInheritedWithoutInstanceTemplate( | 2141 TestObjectTemplateInheritedWithoutInstanceTemplate( |
2142 Constructor_GetFunction_New); | 2142 Constructor_GetFunction_New); |
2143 } | 2143 } |
2144 | 2144 |
| 2145 THREADED_TEST(TestObjectTemplateClassInheritance) { |
| 2146 LocalContext env; |
| 2147 v8::Isolate* isolate = CcTest::isolate(); |
| 2148 v8::HandleScope scope(isolate); |
| 2149 |
| 2150 Local<v8::FunctionTemplate> fun_A = v8::FunctionTemplate::New(isolate); |
| 2151 fun_A->SetClassName(v8_str("A")); |
| 2152 |
| 2153 Local<ObjectTemplate> templ_A = fun_A->InstanceTemplate(); |
| 2154 templ_A->SetNativeDataProperty(v8_str("nirk"), GetNirk); |
| 2155 templ_A->SetNativeDataProperty(v8_str("rino"), GetRino); |
| 2156 |
| 2157 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate); |
| 2158 v8::Local<v8::String> class_name = v8_str("B"); |
| 2159 fun_B->SetClassName(class_name); |
| 2160 fun_B->Inherit(fun_A); |
| 2161 |
| 2162 v8::Local<v8::String> subclass_name = v8_str("C"); |
| 2163 v8::Local<v8::Object> b_proto; |
| 2164 v8::Local<v8::Object> c_proto; |
| 2165 // Perform several iterations to make sure the cache doesn't break |
| 2166 // subclassing. |
| 2167 for (int i = 0; i < 3; i++) { |
| 2168 Local<v8::Function> function_B = |
| 2169 fun_B->GetFunction(env.local()).ToLocalChecked(); |
| 2170 if (i == 0) { |
| 2171 CHECK(env->Global()->Set(env.local(), class_name, function_B).FromJust()); |
| 2172 CompileRun("class C extends B {}"); |
| 2173 b_proto = |
| 2174 CompileRun("B.prototype")->ToObject(env.local()).ToLocalChecked(); |
| 2175 c_proto = |
| 2176 CompileRun("C.prototype")->ToObject(env.local()).ToLocalChecked(); |
| 2177 CHECK(b_proto->Equals(env.local(), c_proto->GetPrototype()).FromJust()); |
| 2178 } |
| 2179 Local<v8::Object> instance = |
| 2180 CompileRun("new C()")->ToObject(env.local()).ToLocalChecked(); |
| 2181 CHECK(c_proto->Equals(env.local(), instance->GetPrototype()).FromJust()); |
| 2182 |
| 2183 CHECK(subclass_name->StrictEquals(instance->GetConstructorName())); |
| 2184 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust()); |
| 2185 |
| 2186 CHECK_EQ(900, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust()); |
| 2187 CHECK_EQ(560, CompileRun("o.rino")->IntegerValue(env.local()).FromJust()); |
| 2188 } |
| 2189 } |
| 2190 |
| 2191 static void NamedPropertyGetterWhichReturns42( |
| 2192 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 2193 info.GetReturnValue().Set(v8_num(42)); |
| 2194 } |
| 2195 |
| 2196 THREADED_TEST(TestObjectTemplateReflectConstruct) { |
| 2197 LocalContext env; |
| 2198 v8::Isolate* isolate = CcTest::isolate(); |
| 2199 v8::HandleScope scope(isolate); |
| 2200 |
| 2201 Local<v8::FunctionTemplate> fun_B = v8::FunctionTemplate::New(isolate); |
| 2202 fun_B->InstanceTemplate()->SetHandler( |
| 2203 v8::NamedPropertyHandlerConfiguration(NamedPropertyGetterWhichReturns42)); |
| 2204 v8::Local<v8::String> class_name = v8_str("B"); |
| 2205 fun_B->SetClassName(class_name); |
| 2206 |
| 2207 v8::Local<v8::String> subclass_name = v8_str("C"); |
| 2208 v8::Local<v8::Object> b_proto; |
| 2209 v8::Local<v8::Object> c_proto; |
| 2210 // Perform several iterations to make sure the cache doesn't break |
| 2211 // subclassing. |
| 2212 for (int i = 0; i < 3; i++) { |
| 2213 Local<v8::Function> function_B = |
| 2214 fun_B->GetFunction(env.local()).ToLocalChecked(); |
| 2215 if (i == 0) { |
| 2216 CHECK(env->Global()->Set(env.local(), class_name, function_B).FromJust()); |
| 2217 CompileRun("function C() {}"); |
| 2218 c_proto = |
| 2219 CompileRun("C.prototype")->ToObject(env.local()).ToLocalChecked(); |
| 2220 } |
| 2221 Local<v8::Object> instance = CompileRun("Reflect.construct(B, [], C)") |
| 2222 ->ToObject(env.local()) |
| 2223 .ToLocalChecked(); |
| 2224 CHECK(c_proto->Equals(env.local(), instance->GetPrototype()).FromJust()); |
| 2225 |
| 2226 CHECK(subclass_name->StrictEquals(instance->GetConstructorName())); |
| 2227 CHECK(env->Global()->Set(env.local(), v8_str("o"), instance).FromJust()); |
| 2228 |
| 2229 CHECK_EQ(42, CompileRun("o.nirk")->IntegerValue(env.local()).FromJust()); |
| 2230 CHECK_EQ(42, CompileRun("o.rino")->IntegerValue(env.local()).FromJust()); |
| 2231 } |
| 2232 } |
| 2233 |
2145 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { | 2234 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { |
2146 ApiTestFuzzer::Fuzz(); | 2235 ApiTestFuzzer::Fuzz(); |
2147 args.GetReturnValue().Set(v8_num(17.2)); | 2236 args.GetReturnValue().Set(v8_num(17.2)); |
2148 } | 2237 } |
2149 | 2238 |
2150 | 2239 |
2151 static void GetKnurd(Local<String> property, | 2240 static void GetKnurd(Local<String> property, |
2152 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2241 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2153 ApiTestFuzzer::Fuzz(); | 2242 ApiTestFuzzer::Fuzz(); |
2154 info.GetReturnValue().Set(v8_num(15.2)); | 2243 info.GetReturnValue().Set(v8_num(15.2)); |
(...skipping 16568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18723 ->Int32Value(context.local()) | 18812 ->Int32Value(context.local()) |
18724 .FromJust()); | 18813 .FromJust()); |
18725 CHECK_EQ(23, c2->Get(context.local(), v8_str("y")) | 18814 CHECK_EQ(23, c2->Get(context.local(), v8_str("y")) |
18726 .ToLocalChecked() | 18815 .ToLocalChecked() |
18727 ->Int32Value(context.local()) | 18816 ->Int32Value(context.local()) |
18728 .FromJust()); | 18817 .FromJust()); |
18729 } | 18818 } |
18730 } | 18819 } |
18731 | 18820 |
18732 | 18821 |
18733 static void NamedPropertyGetterWhichReturns42( | |
18734 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | |
18735 info.GetReturnValue().Set(v8_num(42)); | |
18736 } | |
18737 | |
18738 | |
18739 static void NamedPropertySetterWhichSetsYOnThisTo23( | 18822 static void NamedPropertySetterWhichSetsYOnThisTo23( |
18740 Local<Name> name, Local<Value> value, | 18823 Local<Name> name, Local<Value> value, |
18741 const v8::PropertyCallbackInfo<v8::Value>& info) { | 18824 const v8::PropertyCallbackInfo<v8::Value>& info) { |
18742 if (name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("x")) | 18825 if (name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("x")) |
18743 .FromJust()) { | 18826 .FromJust()) { |
18744 Local<Object>::Cast(info.This()) | 18827 Local<Object>::Cast(info.This()) |
18745 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23)) | 18828 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(23)) |
18746 .FromJust(); | 18829 .FromJust(); |
18747 } | 18830 } |
18748 } | 18831 } |
(...skipping 6312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25061 } | 25144 } |
25062 | 25145 |
25063 TEST(PrivateForApiIsNumber) { | 25146 TEST(PrivateForApiIsNumber) { |
25064 LocalContext context; | 25147 LocalContext context; |
25065 v8::Isolate* isolate = CcTest::isolate(); | 25148 v8::Isolate* isolate = CcTest::isolate(); |
25066 v8::HandleScope scope(isolate); | 25149 v8::HandleScope scope(isolate); |
25067 | 25150 |
25068 // Shouldn't crash. | 25151 // Shouldn't crash. |
25069 v8::Private::ForApi(isolate, v8_str("42")); | 25152 v8::Private::ForApi(isolate, v8_str("42")); |
25070 } | 25153 } |
OLD | NEW |