libraries/v8/runtime.cc
// Return the names of the local named properties.
// args[0]: object
Return the names of the local named properties.
args[0]: object
Return the names of the local named properties . args [ 0 ] : object
RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalPropertyNames) {
  HandleScope scope(isolate);
  ASSERT(args.length() == 2);
  if (!args[0]->IsJSObject()) {
    return isolate->heap()->undefined_value();
  }
  CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
  CONVERT_BOOLEAN_ARG_CHECKED(include_symbols, 1);
  PropertyAttributes filter = include_symbols ? NONE : SYMBOLIC;
  if (obj->IsJSGlobalProxy()) {
    if (obj->IsAccessCheckNeeded() &&
        !isolate->MayNamedAccess(*obj,
                                 isolate->heap()->undefined_value(),
                                 v8::ACCESS_KEYS)) {
      isolate->ReportFailedAccessCheck(*obj, v8::ACCESS_KEYS);
      RETURN_IF_SCHEDULED_EXCEPTION(isolate);
      return *isolate->factory()->NewJSArray(0);
    }
    obj = Handle<JSObject>(JSObject::cast(obj->GetPrototype()));
  }
  int length = LocalPrototypeChainLength(*obj);
  ScopedVector<int> local_property_count(length);
  int total_property_count = 0;
  Handle<JSObject> jsproto = obj;
  for (int i = 0; i < length; i++) {
    if (jsproto->IsAccessCheckNeeded() &&
        !isolate->MayNamedAccess(*jsproto,
                                 isolate->heap()->undefined_value(),
                                 v8::ACCESS_KEYS)) {
      isolate->ReportFailedAccessCheck(*jsproto, v8::ACCESS_KEYS);
      RETURN_IF_SCHEDULED_EXCEPTION(isolate);
      return *isolate->factory()->NewJSArray(0);
    }
    int n;
    n = jsproto->NumberOfLocalProperties(filter);
    local_property_count[i] = n;
    total_property_count += n;
    if (i < length - 1) {
      jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
    }
  }
  Handle<FixedArray> names =
      isolate->factory()->NewFixedArray(total_property_count);
  jsproto = obj;
  int proto_with_hidden_properties = 0;
  int next_copy_index = 0;
  for (int i = 0; i < length; i++) {
    jsproto->GetLocalPropertyNames(*names, next_copy_index, filter);
    next_copy_index += local_property_count[i];
    if (jsproto->HasHiddenProperties()) {
      proto_with_hidden_properties++;
    }
    if (i < length - 1) {
      jsproto = Handle<JSObject>(JSObject::cast(jsproto->GetPrototype()));
    }
  }
  if (proto_with_hidden_properties > 0) {
    Handle<FixedArray> old_names = names;
    names = isolate->factory()->NewFixedArray(
        names->length() - proto_with_hidden_properties);
    int dest_pos = 0;
    for (int i = 0; i < total_property_count; i++) {
      Object* name = old_names->get(i);
      if (name == isolate->heap()->hidden_string()) {
        continue;
      }
      names->set(dest_pos++, name);
    }
  }
  return *isolate->factory()->NewJSArrayWithElements(names);
}
RUNTIME_FUNCTION ( MaybeObject * , Runtime_GetLocalPropertyNames ) { HandleScope scope ( isolate ) ; ASSERT ( args . length ( ) == 2 ) ; if ( ! args [ 0 ] -> IsJSObject ( ) ) { return isolate -> heap ( ) -> undefined_value ( ) ; } CONVERT_ARG_HANDLE_CHECKED ( JSObject , obj , 0 ) ; CONVERT_BOOLEAN_ARG_CHECKED ( include_symbols , 1 ) ; PropertyAttributes filter = include_symbols ? NONE : SYMBOLIC ; if ( obj -> IsJSGlobalProxy ( ) ) { if ( obj -> IsAccessCheckNeeded ( ) && ! isolate -> MayNamedAccess ( * obj , isolate -> heap ( ) -> undefined_value ( ) , v8 :: ACCESS_KEYS ) ) { isolate -> ReportFailedAccessCheck ( * obj , v8 :: ACCESS_KEYS ) ; RETURN_IF_SCHEDULED_EXCEPTION ( isolate ) ; return * isolate -> factory ( ) -> NewJSArray ( 0 ) ; } obj = Handle < JSObject > ( JSObject :: cast ( obj -> GetPrototype ( ) ) ) ; } int length = LocalPrototypeChainLength ( * obj ) ; ScopedVector < int > local_property_count ( length ) ; int total_property_count = 0 ; Handle < JSObject > jsproto = obj ; for ( int i = 0 ; i < length ; i ++ ) { if ( jsproto -> IsAccessCheckNeeded ( ) && ! isolate -> MayNamedAccess ( * jsproto , isolate -> heap ( ) -> undefined_value ( ) , v8 :: ACCESS_KEYS ) ) { isolate -> ReportFailedAccessCheck ( * jsproto , v8 :: ACCESS_KEYS ) ; RETURN_IF_SCHEDULED_EXCEPTION ( isolate ) ; return * isolate -> factory ( ) -> NewJSArray ( 0 ) ; } int n ; n = jsproto -> NumberOfLocalProperties ( filter ) ; local_property_count [ i ] = n ; total_property_count += n ; if ( i < length - 1 ) { jsproto = Handle < JSObject > ( JSObject :: cast ( jsproto -> GetPrototype ( ) ) ) ; } } Handle < FixedArray > names = isolate -> factory ( ) -> NewFixedArray ( total_property_count ) ; jsproto = obj ; int proto_with_hidden_properties = 0 ; int next_copy_index = 0 ; for ( int i = 0 ; i < length ; i ++ ) { jsproto -> GetLocalPropertyNames ( * names , next_copy_index , filter ) ; next_copy_index += local_property_count [ i ] ; if ( jsproto -> HasHiddenProperties ( ) ) { proto_with_hidden_properties ++ ; } if ( i < length - 1 ) { jsproto = Handle < JSObject > ( JSObject :: cast ( jsproto -> GetPrototype ( ) ) ) ; } } if ( proto_with_hidden_properties > 0 ) { Handle < FixedArray > old_names = names ; names = isolate -> factory ( ) -> NewFixedArray ( names -> length ( ) - proto_with_hidden_properties ) ; int dest_pos = 0 ; for ( int i = 0 ; i < total_property_count ; i ++ ) { Object * name = old_names -> get ( i ) ; if ( name == isolate -> heap ( ) -> hidden_string ( ) ) { continue ; } names -> set ( dest_pos ++ , name ) ; } } return * isolate -> factory ( ) -> NewJSArrayWithElements ( names ) ; }
Return the names of the local named properties.
Return the names of the local named properties .
// Skip the global proxy as it has no properties and always delegates to the // real global object. // Only collect names if access is permitted. // Find the number of objects making up this. // Find the number of local properties for each of the objects. // Only collect names if access is permitted. // Allocate an array with storage for all the property names. // Get the property names. // Filter out name of hidden properties object.