コード例 #1
0
ファイル: addon.cpp プロジェクト: cuongquay/uWebSockets
 NativeString(const Local<Value> &value)
 {
     if (value->IsUndefined()) {
         data = nullptr;
         length = 0;
     } else if (value->IsString()) {
         utf8Value = new (utf8ValueMemory) String::Utf8Value(value);
         data = (**utf8Value);
         length = utf8Value->length();
     } else if (node::Buffer::HasInstance(value)) {
         data = node::Buffer::Data(value);
         length = node::Buffer::Length(value);
     } else if (value->IsTypedArray()) {
         Local<ArrayBufferView> arrayBuffer = Local<ArrayBufferView>::Cast(value);
         ArrayBuffer::Contents contents = arrayBuffer->Buffer()->GetContents();
         length = contents.ByteLength();
         data = (char *) contents.Data();
     } else {
         static char empty[] = "";
         data = empty;
         length = 0;
     }
 }
コード例 #2
0
ファイル: mod_v8.cpp プロジェクト: alepharchives/ULib
   HandleScope handle_scope;

   // Enter the created context for compiling and running the script.
   Context::Scope context_scope(context);

   // Create a string containing the JavaScript source code.
   Handle<String> source = String::New(U_STRING_TO_PARAM(x));

   // Compile the source code.
   TryCatch tryCatch;

   Handle<Script> script = Script::Compile(source);

   if (script.IsEmpty())
      {
      String::Utf8Value error(tryCatch.Exception());

      (void) x.replace(*error, error.length());

      return;
      }

   // Run the script
   Handle<Value> result = script->Run();

   if (result.IsEmpty())
      {
      String::Utf8Value error (tryCatch.Exception());

      (void) x.replace(*error, error.length());