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

Unified Diff: src/accessors.cc

Issue 257423009: Convert function.length to API-style accessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | « src/accessors.h ('k') | src/bootstrapper.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 aa09e3b4ce1600e6ecef6aaf6181ce30f0fe289f..a7340964dcd172ebde31567eee5244531cd2e6d6 100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -889,31 +889,57 @@ Handle<AccessorInfo> Accessors::FunctionPrototypeInfo(
//
-Object* Accessors::FunctionGetLength(Isolate* isolate,
- Object* object,
- void*) {
- JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
- if (function == NULL) return Smi::FromInt(0);
- // Check if already compiled.
- if (function->shared()->is_compiled()) {
- return Smi::FromInt(function->shared()->length());
- }
- // If the function isn't compiled yet, the length is not computed correctly
- // yet. Compile it now and return the right length.
+void Accessors::FunctionLengthGetter(
+ v8::Local<v8::String> name,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
- Handle<JSFunction> function_handle(function);
- if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) {
- return Smi::FromInt(function_handle->shared()->length());
+ Handle<Object> object = Utils::OpenHandle(*info.This());
+ MaybeHandle<JSFunction> maybe_function;
+
+ {
+ DisallowHeapAllocation no_allocation;
+ JSFunction* function = FindInstanceOf<JSFunction>(isolate, *object);
+ if (function != NULL) maybe_function = Handle<JSFunction>(function);
+ }
+
+ int length = 0;
+ Handle<JSFunction> function;
+ if (maybe_function.ToHandle(&function)) {
+ if (function->shared()->is_compiled()) {
+ length = function->shared()->length();
+ } else {
+ // If the function isn't compiled yet, the length is not computed
+ // correctly yet. Compile it now and return the right length.
+ if (Compiler::EnsureCompiled(function, KEEP_EXCEPTION)) {
+ length = function->shared()->length();
+ }
+ if (isolate->has_pending_exception()) {
+ isolate->OptionalRescheduleException(false);
ulan 2014/04/24 10:27:03 I added a test that checks this.
+ }
+ }
}
- return isolate->heap()->exception();
+ Handle<Object> result(Smi::FromInt(length), isolate);
+ info.GetReturnValue().Set(Utils::ToLocal(result));
}
-const AccessorDescriptor Accessors::FunctionLength = {
- FunctionGetLength,
- ReadOnlySetAccessor,
- 0
-};
+void Accessors::FunctionLengthSetter(
+ v8::Local<v8::String> name,
+ v8::Local<v8::Value> val,
+ const v8::PropertyCallbackInfo<void>& info) {
+ // Do nothing.
+}
+
+
+Handle<AccessorInfo> Accessors::FunctionLengthInfo(
+ Isolate* isolate, PropertyAttributes attributes) {
+ return MakeAccessor(isolate,
+ isolate->factory()->length_string(),
+ &FunctionLengthGetter,
+ &FunctionLengthSetter,
+ attributes);
+}
//
« no previous file with comments | « src/accessors.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698