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

Side by Side Diff: src/runtime.cc

Issue 7324027: Fix: FunctionTemplate::SetPrototypeAttributes broke prototype object (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-api.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 ASSERT(fun->should_have_prototype()); 1953 ASSERT(fun->should_have_prototype());
1954 Object* obj; 1954 Object* obj;
1955 { MaybeObject* maybe_obj = 1955 { MaybeObject* maybe_obj =
1956 Accessors::FunctionSetPrototype(fun, args[1], NULL); 1956 Accessors::FunctionSetPrototype(fun, args[1], NULL);
1957 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 1957 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
1958 } 1958 }
1959 return args[0]; // return TOS 1959 return args[0]; // return TOS
1960 } 1960 }
1961 1961
1962 1962
1963 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetReadOnlyPrototype) {
1964 NoHandleAllocation ha;
1965 RUNTIME_ASSERT(args.length() == 1);
1966 CONVERT_CHECKED(JSFunction, function, args[0]);
1967
1968 MaybeObject* maybe_name =
1969 isolate->heap()->AllocateStringFromAscii(CStrVector("prototype"));
1970 String* name;
1971 if (!maybe_name->To(&name)) return maybe_name;
1972
1973 if (function->HasFastProperties()) {
1974 // Construct a new field descriptor with updated attributes.
1975 DescriptorArray* instance_desc = function->map()->instance_descriptors();
1976 int index = instance_desc->Search(name);
1977 ASSERT(index != DescriptorArray::kNotFound);
1978 PropertyDetails details(instance_desc->GetDetails(index));
1979 CallbacksDescriptor new_desc(name,
1980 instance_desc->GetValue(index),
1981 static_cast<PropertyAttributes>(details.attributes() | READ_ONLY),
1982 details.index());
1983 // Construct a new field descriptors array containing the new descriptor.
1984 Object* descriptors_unchecked;
1985 { MaybeObject* maybe_descriptors_unchecked =
1986 instance_desc->CopyInsert(&new_desc, REMOVE_TRANSITIONS);
1987 if (!maybe_descriptors_unchecked->ToObject(&descriptors_unchecked)) {
1988 return maybe_descriptors_unchecked;
1989 }
1990 }
1991 DescriptorArray* new_descriptors =
1992 DescriptorArray::cast(descriptors_unchecked);
1993 // Create a new map featuring the new field descriptors array.
1994 Object* map_unchecked;
1995 { MaybeObject* maybe_map_unchecked = function->map()->CopyDropDescriptors();
1996 if (!maybe_map_unchecked->ToObject(&map_unchecked)) {
1997 return maybe_map_unchecked;
1998 }
1999 }
2000 Map* new_map = Map::cast(map_unchecked);
2001 new_map->set_instance_descriptors(new_descriptors);
2002 function->set_map(new_map);
2003 } else { // Dictionary properties.
2004 // Directly manipulate the property details.
2005 int entry = function->property_dictionary()->FindEntry(name);
2006 ASSERT(entry != StringDictionary::kNotFound);
2007 PropertyDetails details = function->property_dictionary()->DetailsAt(entry);
2008 PropertyDetails new_details(
2009 static_cast<PropertyAttributes>(details.attributes() | READ_ONLY),
2010 details.type(),
2011 details.index());
2012 function->property_dictionary()->DetailsAtPut(entry, new_details);
2013 }
2014 return function;
2015 }
2016
2017
1963 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionIsAPIFunction) { 2018 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionIsAPIFunction) {
1964 NoHandleAllocation ha; 2019 NoHandleAllocation ha;
1965 ASSERT(args.length() == 1); 2020 ASSERT(args.length() == 1);
1966 2021
1967 CONVERT_CHECKED(JSFunction, f, args[0]); 2022 CONVERT_CHECKED(JSFunction, f, args[0]);
1968 return f->shared()->IsApiFunction() ? isolate->heap()->true_value() 2023 return f->shared()->IsApiFunction() ? isolate->heap()->true_value()
1969 : isolate->heap()->false_value(); 2024 : isolate->heap()->false_value();
1970 } 2025 }
1971 2026
1972 2027
(...skipping 10697 matching lines...) Expand 10 before | Expand all | Expand 10 after
12670 } else { 12725 } else {
12671 // Handle last resort GC and make sure to allow future allocations 12726 // Handle last resort GC and make sure to allow future allocations
12672 // to grow the heap without causing GCs (if possible). 12727 // to grow the heap without causing GCs (if possible).
12673 isolate->counters()->gc_last_resort_from_js()->Increment(); 12728 isolate->counters()->gc_last_resort_from_js()->Increment();
12674 isolate->heap()->CollectAllGarbage(false); 12729 isolate->heap()->CollectAllGarbage(false);
12675 } 12730 }
12676 } 12731 }
12677 12732
12678 12733
12679 } } // namespace v8::internal 12734 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698