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

Unified Diff: src/accessors.cc

Issue 11416353: Object.observe support for Function 'prototype' property (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: More comments Created 8 years 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/objects.cc » ('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 d0287585a5d329f9caa15cdd40d857c089b209e4..efcaf8f2944e79a686399c316bbf491b388de598 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -465,24 +465,46 @@ MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) {
MaybeObject* Accessors::FunctionSetPrototype(JSObject* object,
- Object* value,
+ Object* value_raw,
void*) {
- Heap* heap = object->GetHeap();
- JSFunction* function = FindInstanceOf<JSFunction>(object);
- if (function == NULL) return heap->undefined_value();
- if (!function->should_have_prototype()) {
+ Isolate* isolate = object->GetIsolate();
+ Heap* heap = isolate->heap();
+ JSFunction* function_raw = FindInstanceOf<JSFunction>(object);
+ if (function_raw == NULL) return heap->undefined_value();
+ if (!function_raw->should_have_prototype()) {
// Since we hit this accessor, object will have no prototype property.
return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(),
- value,
+ value_raw,
NONE);
}
- Object* prototype;
- { MaybeObject* maybe_prototype = function->SetPrototype(value);
- if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype;
+ HandleScope scope(isolate);
+ Handle<JSFunction> function(function_raw, isolate);
+ Handle<Object> value(value_raw, isolate);
+
+ Handle<Object> old_value;
+ bool is_observed =
+ FLAG_harmony_observation &&
+ *function == object &&
+ function->map()->is_observed();
+ if (is_observed) {
+ if (function->has_prototype())
+ old_value = handle(function->prototype(), isolate);
+ else
+ old_value = isolate->factory()->NewFunctionPrototype(function);
+ }
+
+ Handle<Object> result;
+ MaybeObject* maybe_result = function->SetPrototype(*value);
+ if (!maybe_result->ToHandle(&result, isolate)) return maybe_result;
+ ASSERT(function->prototype() == *value);
+
+ if (is_observed && !old_value->SameValue(*value)) {
+ JSObject::EnqueueChangeRecord(
+ function, "updated", isolate->factory()->prototype_symbol(), old_value);
}
- ASSERT(function->prototype() == value);
- return function;
+
+ return *function;
}
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698