Exemple #1
0
 public void Copy(BufferInstance targetBuffer, int targetStart, int sourceStart)
 {
     Copy(targetBuffer, targetStart, sourceStart, Limit - Offset);
 }
Exemple #2
0
 public void Copy(BufferInstance targetBuffer, int targetStart, int sourceStart, int sourceEnd)
 {
     int len = sourceEnd - sourceStart;
     if (targetStart < targetBuffer.Offset || targetStart + len > targetBuffer.Limit)
         throw new JavaScriptException(Engine, "RangeError", "target index out of range");
     if (sourceStart < Offset || sourceEnd > Limit || sourceEnd < sourceStart)
         throw new JavaScriptException(Engine, "RangeError", "source index out of range");
     for (int i = sourceStart, j = targetStart; i < sourceEnd; ++i, ++j) {
         targetBuffer.Buffer[j] = Buffer[i];
     }
 }
Exemple #3
0
 public void Copy(BufferInstance targetBuffer, int targetStart)
 {
     Copy(targetBuffer, targetStart, 0);
 }
Exemple #4
0
 public void Copy(BufferInstance targetBuffer)
 {
     Copy(targetBuffer, 0);
 }
Exemple #5
0
 public object ReadFileSync(string path, [DefaultParameterValue(null)] ObjectInstance options = null) {
     if (!AllowSync)
         throw new JavaScriptException(Engine, "Error", "synchronous operations are not permitted");
     try {
         string encoding = options != null ? options.GetPropertyValue("encoding") as string : null;
         byte[] b = File.ReadAllBytes(CheckPath(path));
         object result = new BufferInstance(Context, Context.Buffer.Constructor.InstancePrototype, b, 0, b.Length);
         if (encoding != null) {
             result = (result as BufferInstance).toString(encoding);
         }
         return result;
     } catch (Exception ex) {
         throw new JavaScriptException(Engine, "Error", ex.Message);
     }
 }
Exemple #6
0
 private void ReadFileAsync(object arguments) {
     object[] args = arguments as object[];
     FunctionInstance callback = null;
     ObjectInstance options = null;
     try {
         object[] readArgs = args[1] as object[];
         if (readArgs.Length >= 2) {
             options = readArgs[0] as ObjectInstance;
             callback = readArgs[1] as FunctionInstance;
         } else if (readArgs.Length >= 1) {
             if (readArgs[0] is FunctionInstance) {
                 callback = readArgs[0] as FunctionInstance;
             }
         }
         string path = CheckPath(args[0] as string);
         string encoding = options != null ? options.GetPropertyValue("encoding") as string : null;
         byte[] b = File.ReadAllBytes(path);
         object result = new BufferInstance(Context, Context.Buffer.Constructor.InstancePrototype, b, 0, b.Length);
         if (encoding != null) {
             result = (result as BufferInstance).toString(encoding);
         }
         if (callback != null)
             Context.NextTick(callback.Bind(this, null, result));
     } catch (Exception ex) {
         if (callback != null)
             Context.NextTick(callback.Bind(this, Engine.Error.Construct(ex.Message)));
     }
 }
Exemple #7
0
 public string Write(BufferInstance buffer)
 {
     try {
         int charCount = Decoder.GetCharCount(buffer.Buffer, buffer.Offset, buffer.Limit - buffer.Offset, false);
         char[] chars = new char[charCount];
         int n = Decoder.GetChars(buffer.Buffer, buffer.Offset, buffer.Limit - buffer.Offset, chars, 0, false);
         return new string(chars, 0, n);
     } catch (Exception ex) {
         throw new JavaScriptException(Engine, "Error", ex.Message);
     }
 }