OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api-natives.h" | 5 #include "src/api-natives.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
9 #include "src/lookup.h" | 9 #include "src/lookup.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 Handle<JSObject> result; | 293 Handle<JSObject> result; |
294 uint32_t serial_number = | 294 uint32_t serial_number = |
295 static_cast<uint32_t>(Smi::cast(info->serial_number())->value()); | 295 static_cast<uint32_t>(Smi::cast(info->serial_number())->value()); |
296 if (serial_number) { | 296 if (serial_number) { |
297 // Probe cache. | 297 // Probe cache. |
298 auto cache = isolate->template_instantiations_cache(); | 298 auto cache = isolate->template_instantiations_cache(); |
299 int entry = cache->FindEntry(serial_number); | 299 int entry = cache->FindEntry(serial_number); |
300 if (entry != UnseededNumberDictionary::kNotFound) { | 300 if (entry != UnseededNumberDictionary::kNotFound) { |
301 Object* boilerplate = cache->ValueAt(entry); | 301 Object* boilerplate = cache->ValueAt(entry); |
302 result = handle(JSObject::cast(boilerplate), isolate); | 302 result = handle(JSObject::cast(boilerplate), isolate); |
303 ASSIGN_RETURN_ON_EXCEPTION( | 303 return isolate->factory()->CopyJSObject(result); |
304 isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject); | |
305 return result; | |
306 } | 304 } |
307 } | 305 } |
308 // Enter a new scope. Recursion could otherwise create a lot of handles. | 306 // Enter a new scope. Recursion could otherwise create a lot of handles. |
309 HandleScope scope(isolate); | 307 HandleScope scope(isolate); |
310 auto constructor = handle(info->constructor(), isolate); | 308 auto constructor = handle(info->constructor(), isolate); |
311 Handle<JSFunction> cons; | 309 Handle<JSFunction> cons; |
312 if (constructor->IsUndefined()) { | 310 if (constructor->IsUndefined()) { |
313 cons = isolate->object_function(); | 311 cons = isolate->object_function(); |
314 } else { | 312 } else { |
315 auto cons_templ = Handle<FunctionTemplateInfo>::cast(constructor); | 313 auto cons_templ = Handle<FunctionTemplateInfo>::cast(constructor); |
316 ASSIGN_RETURN_ON_EXCEPTION( | 314 ASSIGN_RETURN_ON_EXCEPTION( |
317 isolate, cons, InstantiateFunction(isolate, cons_templ), JSFunction); | 315 isolate, cons, InstantiateFunction(isolate, cons_templ), JSFunction); |
318 } | 316 } |
319 auto object = isolate->factory()->NewJSObject(cons); | 317 auto object = isolate->factory()->NewJSObject(cons); |
320 ASSIGN_RETURN_ON_EXCEPTION( | 318 ASSIGN_RETURN_ON_EXCEPTION( |
321 isolate, result, | 319 isolate, result, |
322 ConfigureInstance(isolate, object, info, is_hidden_prototype), | 320 ConfigureInstance(isolate, object, info, is_hidden_prototype), |
323 JSFunction); | 321 JSFunction); |
324 // TODO(dcarney): is this necessary? | 322 // TODO(dcarney): is this necessary? |
325 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); | 323 JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); |
326 | 324 |
327 if (serial_number) { | 325 if (serial_number) { |
328 CacheTemplateInstantiation(isolate, serial_number, result); | 326 CacheTemplateInstantiation(isolate, serial_number, result); |
329 ASSIGN_RETURN_ON_EXCEPTION( | 327 result = isolate->factory()->CopyJSObject(result); |
330 isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject); | |
331 } | 328 } |
332 return scope.CloseAndEscape(result); | 329 return scope.CloseAndEscape(result); |
333 } | 330 } |
334 | 331 |
335 | 332 |
336 MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, | 333 MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, |
337 Handle<FunctionTemplateInfo> data, | 334 Handle<FunctionTemplateInfo> data, |
338 Handle<Name> name) { | 335 Handle<Name> name) { |
339 uint32_t serial_number = | 336 uint32_t serial_number = |
340 static_cast<uint32_t>(Smi::cast(data->serial_number())->value()); | 337 static_cast<uint32_t>(Smi::cast(data->serial_number())->value()); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 map->set_is_callable(); | 618 map->set_is_callable(); |
622 map->set_is_constructor(true); | 619 map->set_is_constructor(true); |
623 } | 620 } |
624 | 621 |
625 DCHECK(result->shared()->IsApiFunction()); | 622 DCHECK(result->shared()->IsApiFunction()); |
626 return result; | 623 return result; |
627 } | 624 } |
628 | 625 |
629 } // namespace internal | 626 } // namespace internal |
630 } // namespace v8 | 627 } // namespace v8 |
OLD | NEW |