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

Side by Side Diff: src/api-natives.cc

Issue 2107673003: Add an API to create a detached global object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 5 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
OLDNEW
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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 NeanderArray array(list); 532 NeanderArray array(list);
533 array.add(isolate, property); 533 array.add(isolate, property);
534 } 534 }
535 535
536 536
537 Handle<JSFunction> ApiNatives::CreateApiFunction( 537 Handle<JSFunction> ApiNatives::CreateApiFunction(
538 Isolate* isolate, Handle<FunctionTemplateInfo> obj, 538 Isolate* isolate, Handle<FunctionTemplateInfo> obj,
539 Handle<Object> prototype, ApiInstanceType instance_type) { 539 Handle<Object> prototype, ApiInstanceType instance_type) {
540 Handle<SharedFunctionInfo> shared = 540 Handle<SharedFunctionInfo> shared =
541 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj); 541 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj);
542 int map_index =
543 Context::FunctionMapIndex(shared->language_mode(), shared->kind());
544 Handle<Map> initial_map(Map::cast(isolate->native_context()->get(map_index)));
545 return CreateApiFunctionWithMap(isolate, isolate->native_context(), obj,
546 initial_map, prototype, instance_type);
547 }
548
549 Handle<JSFunction> ApiNatives::CreateApiFunctionWithMap(
Toon Verwaest 2016/06/30 14:46:17 I'd prefer it if you wouldn't reuse this function.
550 Isolate* isolate, Handle<Object> context_or_undefined,
551 Handle<FunctionTemplateInfo> obj, Handle<Map> initial_map,
552 Handle<Object> prototype, ApiInstanceType instance_type) {
553 Handle<SharedFunctionInfo> shared =
554 FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj);
542 Handle<JSFunction> result = 555 Handle<JSFunction> result =
543 isolate->factory()->NewFunctionFromSharedFunctionInfo( 556 isolate->factory()->NewFunctionFromSharedFunctionInfo(
544 shared, isolate->native_context()); 557 initial_map, shared, context_or_undefined);
545 558
546 if (obj->remove_prototype()) { 559 if (obj->remove_prototype()) {
547 result->set_map(*isolate->sloppy_function_without_prototype_map()); 560 result->set_map(*isolate->sloppy_function_without_prototype_map());
548 DCHECK(prototype.is_null()); 561 DCHECK(prototype.is_null());
549 DCHECK(result->shared()->IsApiFunction()); 562 DCHECK(result->shared()->IsApiFunction());
550 DCHECK(!result->has_initial_map()); 563 DCHECK(!result->has_initial_map());
551 DCHECK(!result->has_prototype()); 564 DCHECK(!result->has_prototype());
552 DCHECK(!result->IsConstructor()); 565 DCHECK(!result->IsConstructor());
553 return result; 566 return result;
554 } 567 }
555 568
556 // Down from here is only valid for API functions that can be used as a 569 // Down from here is only valid for API functions that can be used as a
557 // constructor (don't set the "remove prototype" flag). 570 // constructor (don't set the "remove prototype" flag).
558 571
559 if (obj->read_only_prototype()) { 572 if (obj->read_only_prototype()) {
560 result->set_map(*isolate->sloppy_function_with_readonly_prototype_map()); 573 result->set_map(*isolate->sloppy_function_with_readonly_prototype_map());
561 } 574 }
562 575
563 if (prototype->IsTheHole(isolate)) { 576 if (context_or_undefined->IsContext()) {
564 prototype = isolate->factory()->NewFunctionPrototype(result); 577 if (prototype->IsTheHole(isolate)) {
578 prototype = isolate->factory()->NewFunctionPrototype(result);
579 } else {
580 JSObject::AddProperty(Handle<JSObject>::cast(prototype),
581 isolate->factory()->constructor_string(), result,
582 DONT_ENUM);
583 }
565 } else { 584 } else {
566 JSObject::AddProperty(Handle<JSObject>::cast(prototype), 585 prototype = isolate->factory()->null_value();
567 isolate->factory()->constructor_string(), result,
568 DONT_ENUM);
569 } 586 }
570 587
571 int internal_field_count = 0; 588 int internal_field_count = 0;
572 if (!obj->instance_template()->IsUndefined(isolate)) { 589 if (!obj->instance_template()->IsUndefined(isolate)) {
573 Handle<ObjectTemplateInfo> instance_template = Handle<ObjectTemplateInfo>( 590 Handle<ObjectTemplateInfo> instance_template = Handle<ObjectTemplateInfo>(
574 ObjectTemplateInfo::cast(obj->instance_template())); 591 ObjectTemplateInfo::cast(obj->instance_template()));
575 internal_field_count = 592 internal_field_count =
576 Smi::cast(instance_template->internal_field_count())->value(); 593 Smi::cast(instance_template->internal_field_count())->value();
577 } 594 }
578 595
(...skipping 21 matching lines...) Expand all
600 instance_size += JSGlobalProxy::kSize; 617 instance_size += JSGlobalProxy::kSize;
601 break; 618 break;
602 default: 619 default:
603 UNREACHABLE(); 620 UNREACHABLE();
604 type = JS_OBJECT_TYPE; // Keep the compiler happy. 621 type = JS_OBJECT_TYPE; // Keep the compiler happy.
605 break; 622 break;
606 } 623 }
607 624
608 Handle<Map> map = 625 Handle<Map> map =
609 isolate->factory()->NewMap(type, instance_size, FAST_HOLEY_SMI_ELEMENTS); 626 isolate->factory()->NewMap(type, instance_size, FAST_HOLEY_SMI_ELEMENTS);
610 JSFunction::SetInitialMap(result, map, Handle<JSObject>::cast(prototype)); 627 JSFunction::SetInitialMap(result, map, prototype);
611 628
612 // Mark as undetectable if needed. 629 // Mark as undetectable if needed.
613 if (obj->undetectable()) { 630 if (obj->undetectable()) {
614 map->set_is_undetectable(); 631 map->set_is_undetectable();
615 } 632 }
616 633
617 // Mark as needs_access_check if needed. 634 // Mark as needs_access_check if needed.
618 if (obj->needs_access_check()) { 635 if (obj->needs_access_check()) {
619 map->set_is_access_check_needed(true); 636 map->set_is_access_check_needed(true);
620 } 637 }
(...skipping 10 matching lines...) Expand all
631 if (!obj->instance_call_handler()->IsUndefined(isolate)) { 648 if (!obj->instance_call_handler()->IsUndefined(isolate)) {
632 map->set_is_callable(); 649 map->set_is_callable();
633 map->set_is_constructor(true); 650 map->set_is_constructor(true);
634 } 651 }
635 652
636 return result; 653 return result;
637 } 654 }
638 655
639 } // namespace internal 656 } // namespace internal
640 } // namespace v8 657 } // namespace v8
OLDNEW
« include/v8.h ('K') | « src/api-natives.h ('k') | src/bootstrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698