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

Unified Diff: src/accessors.cc

Issue 2099983004: Revert of Refactor CreateApiFunction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api-natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index 73665fa036a081fcea2fa192100ba2be6688a7ed..74238eb168e832952a608d24f2da66fffcea172d 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -664,10 +664,29 @@
// Accessors::FunctionPrototype
//
+static Handle<Object> GetFunctionPrototype(Isolate* isolate,
+ Handle<JSFunction> function) {
+ if (!function->has_prototype()) {
+ Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
+ JSFunction::SetPrototype(function, proto);
+ }
+ return Handle<Object>(function->prototype(), isolate);
+}
+
+
+MUST_USE_RESULT static MaybeHandle<Object> SetFunctionPrototype(
+ Isolate* isolate, Handle<JSFunction> function, Handle<Object> value) {
+ JSFunction::SetPrototype(function, value);
+ DCHECK(function->prototype() == *value);
+ return function;
+}
+
+
MaybeHandle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
Handle<Object> prototype) {
- JSFunction::SetPrototype(function, prototype);
- return function;
+ DCHECK(function->IsConstructor());
+ Isolate* isolate = function->GetIsolate();
+ return SetFunctionPrototype(isolate, function, prototype);
}
@@ -678,7 +697,7 @@
HandleScope scope(isolate);
Handle<JSFunction> function =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
- Handle<Object> result = JSFunction::GetPrototype(isolate, function);
+ Handle<Object> result = GetFunctionPrototype(isolate, function);
info.GetReturnValue().Set(Utils::ToLocal(result));
}
@@ -692,7 +711,9 @@
Handle<Object> value = Utils::OpenHandle(*val);
Handle<JSFunction> object =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
- JSFunction::SetPrototype(object, value);
+ if (SetFunctionPrototype(isolate, object, value).is_null()) {
+ isolate->OptionalRescheduleException(false);
+ }
}
« 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