Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index e8c38385ea29e2330345bf8cabc115f6518432f0..e79bc9d6d8c3f95153ce43d19c47a72c2ada4534 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -9299,6 +9299,30 @@ void JSFunction::MarkInOptimizationQueue() { |
| } |
| +Handle<JSFunction> JSFunction::CloneClosure(Handle<JSFunction> function) { |
| + Isolate* isolate = function->GetIsolate(); |
| + Handle<Map> map(function->map()); |
| + Handle<SharedFunctionInfo> shared(function->shared()); |
| + Handle<Context> context(function->context()); |
| + Handle<JSFunction> clone = |
| + isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
| + |
| + if (shared->bound()) { |
| + clone->set_function_bindings(function->function_bindings()); |
| + } |
| + |
| + // In typical case, __proto__ of ``function`` is the default Function |
| + // prototype, which means that SetPrototype below is a no-op. |
|
Toon Verwaest
2014/08/21 11:32:28
Now this comment is a bit off
|
| + // In rare cases when that is not true, we mutate the clone's __proto__. |
| + Handle<Object> original_prototype(map->prototype(), isolate); |
| + if (*original_prototype != clone->map()->prototype()) { |
| + JSObject::SetPrototype(clone, original_prototype, false).Assert(); |
| + } |
| + |
| + return clone; |
| +} |
| + |
| + |
| void SharedFunctionInfo::AddToOptimizedCodeMap( |
| Handle<SharedFunctionInfo> shared, |
| Handle<Context> native_context, |