| Index: runtime/bin/file.cc
 | 
| diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
 | 
| index a4721cc63b5e3c8bc8ae4e7a32b4eda1e812f0fe..874e1538341b71b44785d5d0e392481dbe23443b 100644
 | 
| --- a/runtime/bin/file.cc
 | 
| +++ b/runtime/bin/file.cc
 | 
| @@ -8,6 +8,7 @@
 | 
|  #include "bin/dartutils.h"
 | 
|  #include "bin/embedded_dart_io.h"
 | 
|  #include "bin/io_buffer.h"
 | 
| +#include "bin/namespace.h"
 | 
|  #include "bin/utils.h"
 | 
|  #include "include/dart_api.h"
 | 
|  #include "include/dart_tools_api.h"
 | 
| @@ -25,8 +26,9 @@ static File* GetFile(Dart_NativeArguments args) {
 | 
|    File* file;
 | 
|    Dart_Handle dart_this = ThrowIfError(Dart_GetNativeArgument(args, 0));
 | 
|    ASSERT(Dart_IsInstance(dart_this));
 | 
| -  ThrowIfError(Dart_GetNativeInstanceField(dart_this, kFileNativeFieldIndex,
 | 
| -                                           reinterpret_cast<intptr_t*>(&file)));
 | 
| +  Dart_Handle result = Dart_GetNativeInstanceField(
 | 
| +      dart_this, kFileNativeFieldIndex, reinterpret_cast<intptr_t*>(&file));
 | 
| +  ASSERT(!Dart_IsError(result));
 | 
|    return file;
 | 
|  }
 | 
|  
 | 
| @@ -70,9 +72,10 @@ void FUNCTION_NAME(File_SetPointer)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
|    const char* filename =
 | 
| -      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  int64_t mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
 | 
| +      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  int64_t mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
 | 
|    File::DartFileOpenMode dart_file_mode =
 | 
|        static_cast<File::DartFileOpenMode>(mode);
 | 
|    File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode);
 | 
| @@ -80,7 +83,7 @@ void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
 | 
|    // reading. This is to prevent the opening of directories as
 | 
|    // files. Directories can be opened for reading using the posix
 | 
|    // 'open' call.
 | 
| -  File* file = File::Open(filename, file_mode);
 | 
| +  File* file = File::Open(namespc, filename, file_mode);
 | 
|    if (file != NULL) {
 | 
|      Dart_SetReturnValue(args,
 | 
|                          Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
 | 
| @@ -90,9 +93,10 @@ void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
|    const char* filename =
 | 
| -      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  bool exists = File::Exists(filename);
 | 
| +      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  bool exists = File::Exists(namespc, filename);
 | 
|    Dart_SetReturnValue(args, Dart_NewBoolean(exists));
 | 
|  }
 | 
|  
 | 
| @@ -312,8 +316,9 @@ void FUNCTION_NAME(File_Length)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) {
 | 
| -  const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  int64_t return_value = File::LengthFromPath(path);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* path = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  int64_t return_value = File::LengthFromPath(namespc, path);
 | 
|    if (return_value >= 0) {
 | 
|      Dart_SetReturnValue(args, Dart_NewInteger(return_value));
 | 
|    } else {
 | 
| @@ -322,8 +327,9 @@ void FUNCTION_NAME(File_LengthFromPath)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) {
 | 
| -  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  int64_t return_value = File::LastModified(name);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  int64_t return_value = File::LastModified(namespc, name);
 | 
|    if (return_value >= 0) {
 | 
|      Dart_SetReturnValue(args,
 | 
|                          Dart_NewInteger(return_value * kMillisecondsPerSecond));
 | 
| @@ -333,20 +339,22 @@ void FUNCTION_NAME(File_LastModified)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_SetLastModified)(Dart_NativeArguments args) {
 | 
| -  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
|    int64_t millis;
 | 
| -  if (!DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &millis)) {
 | 
| +  if (!DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &millis)) {
 | 
|      Dart_ThrowException(DartUtils::NewDartArgumentError(
 | 
|          "The second argument must be a 64-bit int."));
 | 
|    }
 | 
| -  if (!File::SetLastModified(name, millis)) {
 | 
| +  if (!File::SetLastModified(namespc, name, millis)) {
 | 
|      Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|    }
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_LastAccessed)(Dart_NativeArguments args) {
 | 
| -  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  int64_t return_value = File::LastAccessed(name);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  int64_t return_value = File::LastAccessed(namespc, name);
 | 
|    if (return_value >= 0) {
 | 
|      Dart_SetReturnValue(args,
 | 
|                          Dart_NewInteger(return_value * kMillisecondsPerSecond));
 | 
| @@ -356,13 +364,14 @@ void FUNCTION_NAME(File_LastAccessed)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_SetLastAccessed)(Dart_NativeArguments args) {
 | 
| -  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* name = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
|    int64_t millis;
 | 
| -  if (!DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &millis)) {
 | 
| +  if (!DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 2), &millis)) {
 | 
|      Dart_ThrowException(DartUtils::NewDartArgumentError(
 | 
|          "The second argument must be a 64-bit int."));
 | 
|    }
 | 
| -  if (!File::SetLastAccessed(name, millis)) {
 | 
| +  if (!File::SetLastAccessed(namespc, name, millis)) {
 | 
|      Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|    }
 | 
|  }
 | 
| @@ -401,8 +410,9 @@ void FUNCTION_NAME(File_Lock)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) {
 | 
| -  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  bool result = File::Create(str);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  bool result = File::Create(namespc, str);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -411,13 +421,14 @@ void FUNCTION_NAME(File_Create)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) {
 | 
| -  if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
 | 
| -      Dart_IsString(Dart_GetNativeArgument(args, 1))) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  if (Dart_IsString(Dart_GetNativeArgument(args, 1)) &&
 | 
| +      Dart_IsString(Dart_GetNativeArgument(args, 2))) {
 | 
|      const char* name =
 | 
| -        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -    const char* target =
 | 
|          DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| -    if (!File::CreateLink(name, target)) {
 | 
| +    const char* target =
 | 
| +        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
 | 
| +    if (!File::CreateLink(namespc, name, target)) {
 | 
|        Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|      }
 | 
|    } else {
 | 
| @@ -428,10 +439,11 @@ void FUNCTION_NAME(File_CreateLink)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) {
 | 
| -  if (Dart_IsString(Dart_GetNativeArgument(args, 0))) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  if (Dart_IsString(Dart_GetNativeArgument(args, 1))) {
 | 
|      const char* name =
 | 
| -        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -    const char* target = File::LinkTarget(name);
 | 
| +        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +    const char* target = File::LinkTarget(namespc, name);
 | 
|      if (target == NULL) {
 | 
|        Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|      } else {
 | 
| @@ -445,8 +457,9 @@ void FUNCTION_NAME(File_LinkTarget)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) {
 | 
| -  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  bool result = File::Delete(str);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  bool result = File::Delete(namespc, str);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -455,8 +468,9 @@ void FUNCTION_NAME(File_Delete)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) {
 | 
| -  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  bool result = File::DeleteLink(str);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  bool result = File::DeleteLink(namespc, str);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -465,11 +479,12 @@ void FUNCTION_NAME(File_DeleteLink)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
|    const char* old_path =
 | 
| -      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  const char* new_path =
 | 
|        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| -  bool result = File::Rename(old_path, new_path);
 | 
| +  const char* new_path =
 | 
| +      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
 | 
| +  bool result = File::Rename(namespc, old_path, new_path);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -478,11 +493,12 @@ void FUNCTION_NAME(File_Rename)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_RenameLink)(Dart_NativeArguments args) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
|    const char* old_path =
 | 
| -      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  const char* new_path =
 | 
|        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| -  bool result = File::RenameLink(old_path, new_path);
 | 
| +  const char* new_path =
 | 
| +      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
 | 
| +  bool result = File::RenameLink(namespc, old_path, new_path);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -491,11 +507,12 @@ void FUNCTION_NAME(File_RenameLink)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Copy)(Dart_NativeArguments args) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
|    const char* old_path =
 | 
| -      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  const char* new_path =
 | 
|        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| -  bool result = File::Copy(old_path, new_path);
 | 
| +  const char* new_path =
 | 
| +      DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
 | 
| +  bool result = File::Copy(namespc, old_path, new_path);
 | 
|    if (result) {
 | 
|      Dart_SetReturnValue(args, Dart_NewBoolean(result));
 | 
|    } else {
 | 
| @@ -504,8 +521,9 @@ void FUNCTION_NAME(File_Copy)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) {
 | 
| -  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -  const char* path = File::GetCanonicalPath(str);
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  const char* str = DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| +  const char* path = File::GetCanonicalPath(namespc, str);
 | 
|    if (path != NULL) {
 | 
|      Dart_SetReturnValue(args, DartUtils::NewString(path));
 | 
|    } else {
 | 
| @@ -530,13 +548,14 @@ void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) {
 | 
| -  if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
 | 
| -      Dart_IsBoolean(Dart_GetNativeArgument(args, 1))) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  if (Dart_IsString(Dart_GetNativeArgument(args, 1)) &&
 | 
| +      Dart_IsBoolean(Dart_GetNativeArgument(args, 2))) {
 | 
|      const char* str =
 | 
| -        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| +        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
|      bool follow_links =
 | 
| -        DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 1));
 | 
| -    File::Type type = File::GetType(str, follow_links);
 | 
| +        DartUtils::GetBooleanValue(Dart_GetNativeArgument(args, 2));
 | 
| +    File::Type type = File::GetType(namespc, str, follow_links);
 | 
|      Dart_SetReturnValue(args, Dart_NewInteger(static_cast<int>(type)));
 | 
|    } else {
 | 
|      Dart_Handle err = DartUtils::NewDartArgumentError(
 | 
| @@ -546,12 +565,13 @@ void FUNCTION_NAME(File_GetType)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) {
 | 
| -  if (Dart_IsString(Dart_GetNativeArgument(args, 0))) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  if (Dart_IsString(Dart_GetNativeArgument(args, 1))) {
 | 
|      const char* path =
 | 
| -        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| +        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
|  
 | 
|      int64_t stat_data[File::kStatSize];
 | 
| -    File::Stat(path, stat_data);
 | 
| +    File::Stat(namespc, path, stat_data);
 | 
|      if (stat_data[File::kType] == File::kDoesNotExist) {
 | 
|        Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|      } else {
 | 
| @@ -584,13 +604,14 @@ void FUNCTION_NAME(File_Stat)(Dart_NativeArguments args) {
 | 
|  }
 | 
|  
 | 
|  void FUNCTION_NAME(File_AreIdentical)(Dart_NativeArguments args) {
 | 
| -  if (Dart_IsString(Dart_GetNativeArgument(args, 0)) &&
 | 
| -      Dart_IsString(Dart_GetNativeArgument(args, 1))) {
 | 
| +  Namespace* namespc = Namespace::GetNamespace(args, 0);
 | 
| +  if (Dart_IsString(Dart_GetNativeArgument(args, 1)) &&
 | 
| +      Dart_IsString(Dart_GetNativeArgument(args, 2))) {
 | 
|      const char* path_1 =
 | 
| -        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
 | 
| -    const char* path_2 =
 | 
|          DartUtils::GetStringValue(Dart_GetNativeArgument(args, 1));
 | 
| -    File::Identical result = File::AreIdentical(path_1, path_2);
 | 
| +    const char* path_2 =
 | 
| +        DartUtils::GetStringValue(Dart_GetNativeArgument(args, 2));
 | 
| +    File::Identical result = File::AreIdentical(namespc, path_1, path_2);
 | 
|      if (result == File::kError) {
 | 
|        Dart_SetReturnValue(args, DartUtils::NewDartOSError());
 | 
|      } else {
 | 
| @@ -616,402 +637,413 @@ static int64_t CObjectInt32OrInt64ToInt64(CObject* cobject) {
 | 
|    return result;
 | 
|  }
 | 
|  
 | 
| -File* CObjectToFilePointer(CObject* cobject) {
 | 
| +static File* CObjectToFilePointer(CObject* cobject) {
 | 
|    CObjectIntptr value(cobject);
 | 
|    return reinterpret_cast<File*>(value.Value());
 | 
|  }
 | 
|  
 | 
| +static Namespace* CObjectToNamespacePointer(CObject* cobject) {
 | 
| +  CObjectIntptr value(cobject);
 | 
| +  return reinterpret_cast<Namespace*>(value.Value());
 | 
| +}
 | 
| +
 | 
|  CObject* File::ExistsRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filename(request[0]);
 | 
| -    bool result = File::Exists(filename.CString());
 | 
| -    return CObject::Bool(result);
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filename(request[1]);
 | 
| +  return CObject::Bool(File::Exists(namespc, filename.CString()));
 | 
|  }
 | 
|  
 | 
|  CObject* File::CreateRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filename(request[0]);
 | 
| -    bool result = File::Create(filename.CString());
 | 
| -    if (result) {
 | 
| -      return CObject::True();
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectString filename(request[1]);
 | 
| +  return File::Create(namespc, filename.CString()) ? CObject::True()
 | 
| +                                                   : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::OpenRequest(const CObjectArray& request) {
 | 
| -  File* file = NULL;
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsInt32()) {
 | 
| -    CObjectString filename(request[0]);
 | 
| -    CObjectInt32 mode(request[1]);
 | 
| -    File::DartFileOpenMode dart_file_mode =
 | 
| -        static_cast<File::DartFileOpenMode>(mode.Value());
 | 
| -    File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode);
 | 
| -    file = File::Open(filename.CString(), file_mode);
 | 
| -    if (file != NULL) {
 | 
| -      return new CObjectIntptr(
 | 
| -          CObject::NewIntptr(reinterpret_cast<intptr_t>(file)));
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 3) || !request[1]->IsString() ||
 | 
| +      !request[2]->IsInt32()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filename(request[1]);
 | 
| +  CObjectInt32 mode(request[2]);
 | 
| +  File::DartFileOpenMode dart_file_mode =
 | 
| +      static_cast<File::DartFileOpenMode>(mode.Value());
 | 
| +  File::FileOpenMode file_mode = File::DartModeToFileMode(dart_file_mode);
 | 
| +  File* file = File::Open(namespc, filename.CString(), file_mode);
 | 
| +  if (file == NULL) {
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  return new CObjectIntptr(
 | 
| +      CObject::NewIntptr(reinterpret_cast<intptr_t>(file)));
 | 
|  }
 | 
|  
 | 
|  CObject* File::DeleteRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filename(request[0]);
 | 
| -    bool result = File::Delete(filename.CString());
 | 
| -    if (result) {
 | 
| -      return CObject::True();
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::False();
 | 
|    }
 | 
| -  return CObject::False();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::False();
 | 
| +  }
 | 
| +  CObjectString filename(request[1]);
 | 
| +  return File::Delete(namespc, filename.CString()) ? CObject::True()
 | 
| +                                                   : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::RenameRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsString()) {
 | 
| -    CObjectString old_path(request[0]);
 | 
| -    CObjectString new_path(request[1]);
 | 
| -    bool completed = File::Rename(old_path.CString(), new_path.CString());
 | 
| -    if (completed) {
 | 
| -      return CObject::True();
 | 
| -    }
 | 
| -    return CObject::NewOSError();
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 3) || !request[1]->IsString() ||
 | 
| +      !request[2]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString old_path(request[1]);
 | 
| +  CObjectString new_path(request[2]);
 | 
| +  return File::Rename(namespc, old_path.CString(), new_path.CString())
 | 
| +             ? CObject::True()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::CopyRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsString()) {
 | 
| -    CObjectString old_path(request[0]);
 | 
| -    CObjectString new_path(request[1]);
 | 
| -    bool completed = File::Copy(old_path.CString(), new_path.CString());
 | 
| -    if (completed) {
 | 
| -      return CObject::True();
 | 
| -    }
 | 
| -    return CObject::NewOSError();
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 3) || !request[1]->IsString() ||
 | 
| +      !request[2]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectString old_path(request[1]);
 | 
| +  CObjectString new_path(request[2]);
 | 
| +  return File::Copy(namespc, old_path.CString(), new_path.CString())
 | 
| +             ? CObject::True()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::ResolveSymbolicLinksRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filename(request[0]);
 | 
| -    const char* result = File::GetCanonicalPath(filename.CString());
 | 
| -    if (result != NULL) {
 | 
| -      CObject* path = new CObjectString(CObject::NewString(result));
 | 
| -      return path;
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filename(request[1]);
 | 
| +  const char* result = File::GetCanonicalPath(namespc, filename.CString());
 | 
| +  if (result == NULL) {
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  return new CObjectString(CObject::NewString(result));
 | 
|  }
 | 
|  
 | 
|  CObject* File::CloseRequest(const CObjectArray& request) {
 | 
| -  intptr_t return_value = -1;
 | 
| -  if ((request.Length() == 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    return_value = 0;
 | 
| -    // We have retained a reference to the file here. Therefore the file's
 | 
| -    // destructor can't be running. Since no further requests are dispatched by
 | 
| -    // the Dart code after an async close call, this Close() can't be racing
 | 
| -    // with any other call on the file. We don't do an extra Release(), and we
 | 
| -    // don't delete the weak persistent handle. The file is closed here, but the
 | 
| -    // memory will be cleaned up when the finalizer runs.
 | 
| -    ASSERT(!file->IsClosed());
 | 
| -    file->Close();
 | 
| -  }
 | 
| -  return new CObjectIntptr(CObject::NewIntptr(return_value));
 | 
| +  if ((request.Length() != 1) || !request[0]->IsIntptr()) {
 | 
| +    return new CObjectIntptr(CObject::NewIntptr(-1));
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  // We have retained a reference to the file here. Therefore the file's
 | 
| +  // destructor can't be running. Since no further requests are dispatched by
 | 
| +  // the Dart code after an async close call, this Close() can't be racing
 | 
| +  // with any other call on the file. We don't do an extra Release(), and we
 | 
| +  // don't delete the weak persistent handle. The file is closed here, but the
 | 
| +  // memory will be cleaned up when the finalizer runs.
 | 
| +  ASSERT(!file->IsClosed());
 | 
| +  file->Close();
 | 
| +  return new CObjectIntptr(CObject::NewIntptr(0));
 | 
|  }
 | 
|  
 | 
|  CObject* File::PositionRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if (!file->IsClosed()) {
 | 
| -      intptr_t return_value = file->Position();
 | 
| -      if (return_value >= 0) {
 | 
| -        return new CObjectIntptr(CObject::NewIntptr(return_value));
 | 
| -      } else {
 | 
| -        return CObject::NewOSError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::FileClosedError();
 | 
| -    }
 | 
| +  if ((request.Length() != 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  const intptr_t return_value = file->Position();
 | 
| +  if (return_value < 0) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectIntptr(CObject::NewIntptr(return_value));
 | 
|  }
 | 
|  
 | 
|  CObject* File::SetPositionRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 2) && request[1]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t position = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        if (file->SetPosition(position)) {
 | 
| -          return CObject::True();
 | 
| -        } else {
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  const int64_t position = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  return file->SetPosition(position) ? CObject::True() : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::TruncateRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 2) && request[1]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        if (file->Truncate(length)) {
 | 
| -          return CObject::True();
 | 
| -        } else {
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  const int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  if (file->Truncate(length)) {
 | 
| +    return CObject::True();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::LengthRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if (!file->IsClosed()) {
 | 
| -      int64_t return_value = file->Length();
 | 
| -      if (return_value >= 0) {
 | 
| -        return new CObjectInt64(CObject::NewInt64(return_value));
 | 
| -      } else {
 | 
| -        return CObject::NewOSError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::FileClosedError();
 | 
| -    }
 | 
| +  if ((request.Length() != 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  const int64_t return_value = file->Length();
 | 
| +  if (return_value < 0) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectInt64(CObject::NewInt64(return_value));
 | 
|  }
 | 
|  
 | 
|  CObject* File::LengthFromPathRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filepath(request[0]);
 | 
| -    int64_t return_value = File::LengthFromPath(filepath.CString());
 | 
| -    if (return_value >= 0) {
 | 
| -      return new CObjectInt64(CObject::NewInt64(return_value));
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filepath(request[1]);
 | 
| +  const int64_t return_value =
 | 
| +      File::LengthFromPath(namespc, filepath.CString());
 | 
| +  if (return_value < 0) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectInt64(CObject::NewInt64(return_value));
 | 
|  }
 | 
|  
 | 
|  CObject* File::LastAccessedRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filepath(request[0]);
 | 
| -    int64_t return_value = File::LastAccessed(filepath.CString());
 | 
| -    if (return_value >= 0) {
 | 
| -      return new CObjectIntptr(
 | 
| -          CObject::NewInt64(return_value * kMillisecondsPerSecond));
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filepath(request[1]);
 | 
| +  const int64_t return_value = File::LastAccessed(namespc, filepath.CString());
 | 
| +  if (return_value < 0) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectIntptr(
 | 
| +      CObject::NewInt64(return_value * kMillisecondsPerSecond));
 | 
|  }
 | 
|  
 | 
|  CObject* File::SetLastAccessedRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsInt32OrInt64()) {
 | 
| -    CObjectString filepath(request[0]);
 | 
| -    const int64_t millis = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -    if (File::SetLastAccessed(filepath.CString(), millis)) {
 | 
| -      return CObject::Null();
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 3) || !request[1]->IsString() ||
 | 
| +      !request[2]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filepath(request[1]);
 | 
| +  const int64_t millis = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| +  return File::SetLastAccessed(namespc, filepath.CString(), millis)
 | 
| +             ? CObject::Null()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::LastModifiedRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString filepath(request[0]);
 | 
| -    int64_t return_value = File::LastModified(filepath.CString());
 | 
| -    if (return_value >= 0) {
 | 
| -      return new CObjectIntptr(
 | 
| -          CObject::NewInt64(return_value * kMillisecondsPerSecond));
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filepath(request[1]);
 | 
| +  const int64_t return_value = File::LastModified(namespc, filepath.CString());
 | 
| +  if (return_value < 0) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectIntptr(
 | 
| +      CObject::NewInt64(return_value * kMillisecondsPerSecond));
 | 
|  }
 | 
|  
 | 
|  CObject* File::SetLastModifiedRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsInt32OrInt64()) {
 | 
| -    CObjectString filepath(request[0]);
 | 
| -    const int64_t millis = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -    if (File::SetLastModified(filepath.CString(), millis)) {
 | 
| -      return CObject::Null();
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 3) || !request[1]->IsString() ||
 | 
| +      !request[2]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString filepath(request[1]);
 | 
| +  const int64_t millis = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| +  return File::SetLastModified(namespc, filepath.CString(), millis)
 | 
| +             ? CObject::Null()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::FlushRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if (!file->IsClosed()) {
 | 
| -      if (file->Flush()) {
 | 
| -        return CObject::True();
 | 
| -      } else {
 | 
| -        return CObject::NewOSError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::FileClosedError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  return file->Flush() ? CObject::True() : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::ReadByteRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if (!file->IsClosed()) {
 | 
| -      uint8_t buffer;
 | 
| -      int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
 | 
| -      if (bytes_read > 0) {
 | 
| -        return new CObjectIntptr(CObject::NewIntptr(buffer));
 | 
| -      } else if (bytes_read == 0) {
 | 
| -        return new CObjectIntptr(CObject::NewIntptr(-1));
 | 
| -      } else {
 | 
| -        return CObject::NewOSError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::FileClosedError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  uint8_t buffer;
 | 
| +  const int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1);
 | 
| +  if (bytes_read < 0) {
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  if (bytes_read == 0) {
 | 
| +    return new CObjectIntptr(CObject::NewIntptr(-1));
 | 
| +  }
 | 
| +  return new CObjectIntptr(CObject::NewIntptr(buffer));
 | 
|  }
 | 
|  
 | 
|  CObject* File::WriteByteRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 2) && request[1]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t byte = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        uint8_t buffer = static_cast<uint8_t>(byte & 0xff);
 | 
| -        bool success = file->WriteFully(reinterpret_cast<void*>(&buffer), 1);
 | 
| -        if (success) {
 | 
| -          return new CObjectInt64(CObject::NewInt64(1));
 | 
| -        } else {
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  const int64_t byte = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  uint8_t buffer = static_cast<uint8_t>(byte & 0xff);
 | 
| +  return file->WriteFully(reinterpret_cast<void*>(&buffer), 1)
 | 
| +             ? new CObjectInt64(CObject::NewInt64(1))
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::ReadRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 2) && request[1]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
 | 
| -        ASSERT(io_buffer != NULL);
 | 
| -        uint8_t* data = io_buffer->value.as_external_typed_data.data;
 | 
| -        int64_t bytes_read = file->Read(data, length);
 | 
| -        if (bytes_read >= 0) {
 | 
| -          CObjectExternalUint8Array* external_array =
 | 
| -              new CObjectExternalUint8Array(io_buffer);
 | 
| -          external_array->SetLength(bytes_read);
 | 
| -          CObjectArray* result = new CObjectArray(CObject::NewArray(2));
 | 
| -          result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
 | 
| -          result->SetAt(1, external_array);
 | 
| -          return result;
 | 
| -        } else {
 | 
| -          CObject::FreeIOBufferData(io_buffer);
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  const int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
 | 
| +  ASSERT(io_buffer != NULL);
 | 
| +  uint8_t* data = io_buffer->value.as_external_typed_data.data;
 | 
| +  const int64_t bytes_read = file->Read(data, length);
 | 
| +  if (bytes_read < 0) {
 | 
| +    CObject::FreeIOBufferData(io_buffer);
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  CObjectExternalUint8Array* external_array =
 | 
| +      new CObjectExternalUint8Array(io_buffer);
 | 
| +  external_array->SetLength(bytes_read);
 | 
| +  CObjectArray* result = new CObjectArray(CObject::NewArray(2));
 | 
| +  result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
 | 
| +  result->SetAt(1, external_array);
 | 
| +  return result;
 | 
|  }
 | 
|  
 | 
|  CObject* File::ReadIntoRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 2) && request[1]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
 | 
| -        ASSERT(io_buffer != NULL);
 | 
| -        uint8_t* data = io_buffer->value.as_external_typed_data.data;
 | 
| -        int64_t bytes_read = file->Read(data, length);
 | 
| -        if (bytes_read >= 0) {
 | 
| -          CObjectExternalUint8Array* external_array =
 | 
| -              new CObjectExternalUint8Array(io_buffer);
 | 
| -          external_array->SetLength(bytes_read);
 | 
| -          CObjectArray* result = new CObjectArray(CObject::NewArray(3));
 | 
| -          result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
 | 
| -          result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read)));
 | 
| -          result->SetAt(2, external_array);
 | 
| -          return result;
 | 
| -        } else {
 | 
| -          CObject::FreeIOBufferData(io_buffer);
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  const int64_t length = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
 | 
| +  ASSERT(io_buffer != NULL);
 | 
| +  uint8_t* data = io_buffer->value.as_external_typed_data.data;
 | 
| +  const int64_t bytes_read = file->Read(data, length);
 | 
| +  if (bytes_read < 0) {
 | 
| +    CObject::FreeIOBufferData(io_buffer);
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectExternalUint8Array* external_array =
 | 
| +      new CObjectExternalUint8Array(io_buffer);
 | 
| +  external_array->SetLength(bytes_read);
 | 
| +  CObjectArray* result = new CObjectArray(CObject::NewArray(3));
 | 
| +  result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
 | 
| +  result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read)));
 | 
| +  result->SetAt(2, external_array);
 | 
| +  return result;
 | 
|  }
 | 
|  
 | 
|  static int SizeInBytes(Dart_TypedData_Type type) {
 | 
| @@ -1039,180 +1071,189 @@ static int SizeInBytes(Dart_TypedData_Type type) {
 | 
|  }
 | 
|  
 | 
|  CObject* File::WriteFromRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 4) &&
 | 
| -        (request[1]->IsTypedData() || request[1]->IsArray()) &&
 | 
| -        request[2]->IsInt32OrInt64() && request[3]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t start = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| -        int64_t end = CObjectInt32OrInt64ToInt64(request[3]);
 | 
| -        int64_t length = end - start;
 | 
| -        uint8_t* buffer_start;
 | 
| -        if (request[1]->IsTypedData()) {
 | 
| -          CObjectTypedData typed_data(request[1]);
 | 
| -          start = start * SizeInBytes(typed_data.Type());
 | 
| -          length = length * SizeInBytes(typed_data.Type());
 | 
| -          buffer_start = typed_data.Buffer() + start;
 | 
| -        } else {
 | 
| -          CObjectArray array(request[1]);
 | 
| -          buffer_start = Dart_ScopeAllocate(length);
 | 
| -          for (int i = 0; i < length; i++) {
 | 
| -            if (array[i + start]->IsInt32OrInt64()) {
 | 
| -              int64_t value = CObjectInt32OrInt64ToInt64(array[i + start]);
 | 
| -              buffer_start[i] = static_cast<uint8_t>(value & 0xFF);
 | 
| -            } else {
 | 
| -              // Unsupported type.
 | 
| -              return CObject::IllegalArgumentError();
 | 
| -            }
 | 
| -          }
 | 
| -          start = 0;
 | 
| -        }
 | 
| -        bool success =
 | 
| -            file->WriteFully(reinterpret_cast<void*>(buffer_start), length);
 | 
| -        if (success) {
 | 
| -          return new CObjectInt64(CObject::NewInt64(length));
 | 
| -        } else {
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 4) ||
 | 
| +      (!request[1]->IsTypedData() && !request[1]->IsArray()) ||
 | 
| +      !request[2]->IsInt32OrInt64() || !request[3]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
| +  }
 | 
| +  int64_t start = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| +  int64_t end = CObjectInt32OrInt64ToInt64(request[3]);
 | 
| +  int64_t length = end - start;
 | 
| +  uint8_t* buffer_start;
 | 
| +  if (request[1]->IsTypedData()) {
 | 
| +    CObjectTypedData typed_data(request[1]);
 | 
| +    start = start * SizeInBytes(typed_data.Type());
 | 
| +    length = length * SizeInBytes(typed_data.Type());
 | 
| +    buffer_start = typed_data.Buffer() + start;
 | 
| +  } else {
 | 
| +    CObjectArray array(request[1]);
 | 
| +    buffer_start = Dart_ScopeAllocate(length);
 | 
| +    for (int i = 0; i < length; i++) {
 | 
| +      if (array[i + start]->IsInt32OrInt64()) {
 | 
| +        int64_t value = CObjectInt32OrInt64ToInt64(array[i + start]);
 | 
| +        buffer_start[i] = static_cast<uint8_t>(value & 0xFF);
 | 
|        } else {
 | 
| -        return CObject::FileClosedError();
 | 
| +        // Unsupported type.
 | 
| +        return CObject::IllegalArgumentError();
 | 
|        }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
|      }
 | 
| +    start = 0;
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return file->WriteFully(reinterpret_cast<void*>(buffer_start), length)
 | 
| +             ? new CObjectInt64(CObject::NewInt64(length))
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::CreateLinkRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() != 2) || !request[0]->IsString() ||
 | 
| -      !request[1]->IsString()) {
 | 
| +  if ((request.Length() != 3) || !request[0]->IsIntptr()) {
 | 
|      return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  CObjectString link_name(request[0]);
 | 
| -  CObjectString target_name(request[1]);
 | 
| -  if (File::CreateLink(link_name.CString(), target_name.CString())) {
 | 
| -    return CObject::True();
 | 
| -  } else {
 | 
| -    return CObject::NewOSError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString() || !request[2]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| +  CObjectString link_name(request[1]);
 | 
| +  CObjectString target_name(request[2]);
 | 
| +  return File::CreateLink(namespc, link_name.CString(), target_name.CString())
 | 
| +             ? CObject::True()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::DeleteLinkRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString link_path(request[0]);
 | 
| -    bool result = File::DeleteLink(link_path.CString());
 | 
| -    if (result) {
 | 
| -      return CObject::True();
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() != 2) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectString link_path(request[1]);
 | 
| +  return File::DeleteLink(namespc, link_path.CString()) ? CObject::True()
 | 
| +                                                        : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::RenameLinkRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsString()) {
 | 
| -    CObjectString old_path(request[0]);
 | 
| -    CObjectString new_path(request[1]);
 | 
| -    bool completed = File::RenameLink(old_path.CString(), new_path.CString());
 | 
| -    if (completed) {
 | 
| -      return CObject::True();
 | 
| -    }
 | 
| -    return CObject::NewOSError();
 | 
| +  if ((request.Length() != 3) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString() || !request[2]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectString old_path(request[1]);
 | 
| +  CObjectString new_path(request[2]);
 | 
| +  return File::RenameLink(namespc, old_path.CString(), new_path.CString())
 | 
| +             ? CObject::True()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  CObject* File::LinkTargetRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    CObjectString link_path(request[0]);
 | 
| -    const char* target = File::LinkTarget(link_path.CString());
 | 
| -    if (target != NULL) {
 | 
| -      CObject* result = new CObjectString(CObject::NewString(target));
 | 
| -      return result;
 | 
| -    } else {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| +  if ((request.Length() != 2) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString link_path(request[1]);
 | 
| +  const char* target = File::LinkTarget(namespc, link_path.CString());
 | 
| +  if (target == NULL) {
 | 
| +    return CObject::NewOSError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  return new CObjectString(CObject::NewString(target));
 | 
|  }
 | 
|  
 | 
|  CObject* File::TypeRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsBool()) {
 | 
| -    CObjectString path(request[0]);
 | 
| -    CObjectBool follow_links(request[1]);
 | 
| -    File::Type type = File::GetType(path.CString(), follow_links.Value());
 | 
| -    return new CObjectInt32(CObject::NewInt32(type));
 | 
| +  if ((request.Length() != 3) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString() || !request[2]->IsBool()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  CObjectString path(request[1]);
 | 
| +  CObjectBool follow_links(request[2]);
 | 
| +  File::Type type =
 | 
| +      File::GetType(namespc, path.CString(), follow_links.Value());
 | 
| +  return new CObjectInt32(CObject::NewInt32(type));
 | 
|  }
 | 
|  
 | 
|  CObject* File::IdenticalRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 2) && request[0]->IsString() &&
 | 
| -      request[1]->IsString()) {
 | 
| -    CObjectString path1(request[0]);
 | 
| -    CObjectString path2(request[1]);
 | 
| -    File::Identical result =
 | 
| -        File::AreIdentical(path1.CString(), path2.CString());
 | 
| -    if (result == File::kError) {
 | 
| -      return CObject::NewOSError();
 | 
| -    } else if (result == File::kIdentical) {
 | 
| -      return CObject::True();
 | 
| -    } else {
 | 
| -      return CObject::False();
 | 
| -    }
 | 
| +  if ((request.Length() != 3) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if (!request[1]->IsString() || !request[2]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  CObjectString path1(request[1]);
 | 
| +  CObjectString path2(request[2]);
 | 
| +  File::Identical result =
 | 
| +      File::AreIdentical(namespc, path1.CString(), path2.CString());
 | 
| +  if (result == File::kError) {
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  return (result == File::kIdentical) ? CObject::True() : CObject::False();
 | 
|  }
 | 
|  
 | 
|  CObject* File::StatRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() == 1) && request[0]->IsString()) {
 | 
| -    int64_t data[File::kStatSize];
 | 
| -    CObjectString path(request[0]);
 | 
| -    File::Stat(path.CString(), data);
 | 
| -    if (data[File::kType] == File::kDoesNotExist) {
 | 
| -      return CObject::NewOSError();
 | 
| -    }
 | 
| -    CObjectArray* result = new CObjectArray(CObject::NewArray(File::kStatSize));
 | 
| -    for (int i = 0; i < File::kStatSize; ++i) {
 | 
| -      result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i])));
 | 
| -    }
 | 
| -    CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2));
 | 
| -    wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess)));
 | 
| -    wrapper->SetAt(1, result);
 | 
| -    return wrapper;
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  Namespace* namespc = CObjectToNamespacePointer(request[0]);
 | 
| +  RefCntReleaseScope<Namespace> rs(namespc);
 | 
| +  if ((request.Length() != 2) || !request[1]->IsString()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  int64_t data[File::kStatSize];
 | 
| +  CObjectString path(request[1]);
 | 
| +  File::Stat(namespc, path.CString(), data);
 | 
| +  if (data[File::kType] == File::kDoesNotExist) {
 | 
| +    return CObject::NewOSError();
 | 
| +  }
 | 
| +  CObjectArray* result = new CObjectArray(CObject::NewArray(File::kStatSize));
 | 
| +  for (int i = 0; i < File::kStatSize; ++i) {
 | 
| +    result->SetAt(i, new CObjectInt64(CObject::NewInt64(data[i])));
 | 
| +  }
 | 
| +  CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2));
 | 
| +  wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess)));
 | 
| +  wrapper->SetAt(1, result);
 | 
| +  return wrapper;
 | 
|  }
 | 
|  
 | 
|  CObject* File::LockRequest(const CObjectArray& request) {
 | 
| -  if ((request.Length() >= 1) && request[0]->IsIntptr()) {
 | 
| -    File* file = CObjectToFilePointer(request[0]);
 | 
| -    RefCntReleaseScope<File> rs(file);
 | 
| -    if ((request.Length() == 4) && request[1]->IsInt32OrInt64() &&
 | 
| -        request[2]->IsInt32OrInt64() && request[3]->IsInt32OrInt64()) {
 | 
| -      if (!file->IsClosed()) {
 | 
| -        int64_t lock = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| -        int64_t start = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| -        int64_t end = CObjectInt32OrInt64ToInt64(request[3]);
 | 
| -        if (file->Lock(static_cast<File::LockType>(lock), start, end)) {
 | 
| -          return CObject::True();
 | 
| -        } else {
 | 
| -          return CObject::NewOSError();
 | 
| -        }
 | 
| -      } else {
 | 
| -        return CObject::FileClosedError();
 | 
| -      }
 | 
| -    } else {
 | 
| -      return CObject::IllegalArgumentError();
 | 
| -    }
 | 
| +  if ((request.Length() < 1) || !request[0]->IsIntptr()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  File* file = CObjectToFilePointer(request[0]);
 | 
| +  RefCntReleaseScope<File> rs(file);
 | 
| +  if ((request.Length() != 4) || !request[1]->IsInt32OrInt64() ||
 | 
| +      !request[2]->IsInt32OrInt64() || !request[3]->IsInt32OrInt64()) {
 | 
| +    return CObject::IllegalArgumentError();
 | 
| +  }
 | 
| +  if (file->IsClosed()) {
 | 
| +    return CObject::FileClosedError();
 | 
|    }
 | 
| -  return CObject::IllegalArgumentError();
 | 
| +  const int64_t lock = CObjectInt32OrInt64ToInt64(request[1]);
 | 
| +  const int64_t start = CObjectInt32OrInt64ToInt64(request[2]);
 | 
| +  const int64_t end = CObjectInt32OrInt64ToInt64(request[3]);
 | 
| +  return file->Lock(static_cast<File::LockType>(lock), start, end)
 | 
| +             ? CObject::True()
 | 
| +             : CObject::NewOSError();
 | 
|  }
 | 
|  
 | 
|  }  // namespace bin
 | 
| 
 |