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

Side by Side Diff: src/accessors.cc

Issue 2095953002: Refactor CreateApiFunction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Create the template instantiation cache early enough 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
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | 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 // 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/accessors.h" 5 #include "src/accessors.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/contexts.h" 8 #include "src/contexts.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/execution.h" 10 #include "src/execution.h"
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 STATIC_CHAR_VECTOR("eval_from_function_name"))); 657 STATIC_CHAR_VECTOR("eval_from_function_name")));
658 return MakeAccessor(isolate, name, &ScriptEvalFromFunctionNameGetter, nullptr, 658 return MakeAccessor(isolate, name, &ScriptEvalFromFunctionNameGetter, nullptr,
659 attributes); 659 attributes);
660 } 660 }
661 661
662 662
663 // 663 //
664 // Accessors::FunctionPrototype 664 // Accessors::FunctionPrototype
665 // 665 //
666 666
667 static Handle<Object> GetFunctionPrototype(Isolate* isolate, 667 MaybeHandle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
668 Handle<JSFunction> function) { 668 Handle<Object> prototype) {
669 if (!function->has_prototype()) { 669 JSFunction::SetPrototype(function, prototype);
670 Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
671 JSFunction::SetPrototype(function, proto);
672 }
673 return Handle<Object>(function->prototype(), isolate);
674 }
675
676
677 MUST_USE_RESULT static MaybeHandle<Object> SetFunctionPrototype(
678 Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) {
679 JSFunction::SetPrototype(function, value);
680 DCHECK(function->prototype() == *value);
681 return function; 670 return function;
682 } 671 }
683 672
684 673
685 MaybeHandle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
686 Handle<Object> prototype) {
687 DCHECK(function->IsConstructor());
688 Isolate* isolate = function->GetIsolate();
689 return SetFunctionPrototype(isolate, function, prototype);
690 }
691
692
693 void Accessors::FunctionPrototypeGetter( 674 void Accessors::FunctionPrototypeGetter(
694 v8::Local<v8::Name> name, 675 v8::Local<v8::Name> name,
695 const v8::PropertyCallbackInfo<v8::Value>& info) { 676 const v8::PropertyCallbackInfo<v8::Value>& info) {
696 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 677 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
697 HandleScope scope(isolate); 678 HandleScope scope(isolate);
698 Handle<JSFunction> function = 679 Handle<JSFunction> function =
699 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); 680 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
700 Handle<Object> result = GetFunctionPrototype(isolate, function); 681 Handle<Object> result = JSFunction::GetPrototype(isolate, function);
701 info.GetReturnValue().Set(Utils::ToLocal(result)); 682 info.GetReturnValue().Set(Utils::ToLocal(result));
702 } 683 }
703 684
704 685
705 void Accessors::FunctionPrototypeSetter( 686 void Accessors::FunctionPrototypeSetter(
706 v8::Local<v8::Name> name, 687 v8::Local<v8::Name> name,
707 v8::Local<v8::Value> val, 688 v8::Local<v8::Value> val,
708 const v8::PropertyCallbackInfo<void>& info) { 689 const v8::PropertyCallbackInfo<void>& info) {
709 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); 690 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
710 HandleScope scope(isolate); 691 HandleScope scope(isolate);
711 Handle<Object> value = Utils::OpenHandle(*val); 692 Handle<Object> value = Utils::OpenHandle(*val);
712 Handle<JSFunction> object = 693 Handle<JSFunction> object =
713 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder())); 694 Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
714 if (SetFunctionPrototype(isolate, object, value).is_null()) { 695 JSFunction::SetPrototype(object, value);
715 isolate->OptionalRescheduleException(false);
716 }
717 } 696 }
718 697
719 698
720 Handle<AccessorInfo> Accessors::FunctionPrototypeInfo( 699 Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
721 Isolate* isolate, PropertyAttributes attributes) { 700 Isolate* isolate, PropertyAttributes attributes) {
722 return MakeAccessor(isolate, 701 return MakeAccessor(isolate,
723 isolate->factory()->prototype_string(), 702 isolate->factory()->prototype_string(),
724 &FunctionPrototypeGetter, 703 &FunctionPrototypeGetter,
725 &FunctionPrototypeSetter, 704 &FunctionPrototypeSetter,
726 attributes); 705 attributes);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 Isolate* isolate = name->GetIsolate(); 1142 Isolate* isolate = name->GetIsolate();
1164 Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport, 1143 Handle<AccessorInfo> info = MakeAccessor(isolate, name, &ModuleGetExport,
1165 &ModuleSetExport, attributes); 1144 &ModuleSetExport, attributes);
1166 info->set_data(Smi::FromInt(index)); 1145 info->set_data(Smi::FromInt(index));
1167 return info; 1146 return info;
1168 } 1147 }
1169 1148
1170 1149
1171 } // namespace internal 1150 } // namespace internal
1172 } // namespace v8 1151 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698