Esempio n. 1
0
static void
gum_v8_script_backend_emit_debug_message (const Debug::Message & message)
{
  Isolate * isolate = message.GetIsolate ();
  GumV8ScriptBackend * self = GUM_V8_SCRIPT_BACKEND (isolate->GetData (0));
  GumV8ScriptBackendPrivate * priv = self->priv;
  HandleScope scope (isolate);

  Local<String> json = message.GetJSON ();
  String::Utf8Value json_str (json);

  GUM_V8_SCRIPT_BACKEND_LOCK ();
  GMainContext * context = (priv->debug_handler_context != NULL)
      ? g_main_context_ref (priv->debug_handler_context)
      : NULL;
  GUM_V8_SCRIPT_BACKEND_UNLOCK ();

  if (context == NULL)
    return;

  GumEmitDebugMessageData * d = g_slice_new (GumEmitDebugMessageData);
  d->backend = self;
  g_object_ref (self);
  d->message = g_strdup (*json_str);

  GSource * source = g_idle_source_new ();
  g_source_set_callback (source,
      (GSourceFunc) gum_v8_script_backend_do_emit_debug_message,
      d,
      (GDestroyNotify) gum_emit_debug_message_data_free);
  g_source_attach (source, context);
  g_source_unref (source);

  g_main_context_unref (context);
}
Esempio n. 2
0
void V8DispatchDebugMessages()
{
	Isolate* isolate = Isolate::GetCurrent();
	Persistent<Context> *persistent_contect = (Persistent<Context> *)isolate->GetData(1);
	HandleScope handle_scope(isolate);
	Local<Context> context = Local<Context>::New(isolate, *persistent_contect);
	Context::Scope scope(context);

	Debug::ProcessDebugMessages();
}
Esempio n. 3
0
/* for geomtransform, we don't have the mapObj */
shapeObj *msV8TransformShape(shapeObj *shape, const char* filename)
{
  TryCatch try_catch;
  Isolate *isolate = Isolate::GetCurrent();
  V8Context *v8context = (V8Context*)isolate->GetData();

  HandleScope handle_scope(v8context->isolate);

  /* execution context */
  Local<Context> context = Local<Context>::New(v8context->isolate, v8context->context);
  Context::Scope context_scope(context);
  Handle<Object> global = context->Global();

  Shape* shape_ = new Shape(shape);
  shape_->setLayer(v8context->layer);
  shape_->disableMemoryHandler();
  Handle<Value> ext = External::New(shape_);
  global->Set(String::New("shape"),
              Shape::Constructor()->NewInstance(1, &ext));

  msV8ExecuteScript(filename);
  Handle<Value> value = global->Get(String::New("geomtransform"));
  if (value->IsUndefined()) {
    msDebug("msV8TransformShape: Function 'geomtransform' is missing.\n");
    return NULL;
  }
  Handle<Function> func = Handle<Function>::Cast(value);
  Handle<Value> result = func->Call(global, 0, 0);
  if (result.IsEmpty() && try_catch.HasCaught()) {
    msV8ReportException(&try_catch);
  }

  if (!result.IsEmpty() && result->IsObject()) {
    Handle<Object> obj = result->ToObject();
    if (obj->GetConstructorName()->Equals(String::New("shapeObj"))) {
      Shape* new_shape = ObjectWrap::Unwrap<Shape>(result->ToObject());
      if (shape == new_shape->get()) {
        shapeObj *new_shape_ = (shapeObj *)msSmallMalloc(sizeof(shapeObj));
        msInitShape(new_shape_);
        msCopyShape(shape, new_shape_);
        return new_shape_;
      }
      else {
        new_shape->disableMemoryHandler();
        return new_shape->get();
      }
    }
  }

  return NULL;
}
void SideNotification::Init(Handle<Object> exports){
    Isolate* isolate = Isolate::GetCurrent();
    // Prepare constructor template
    Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate);
    tpl->SetClassName(String::NewFromUtf8(isolate, SideNotification::NAME.c_str()));
    tpl->InstanceTemplate()->SetAccessor(String::NewFromUtf8(isolate, "side"),
                            SideGetter);

    tpl->InstanceTemplate()->SetInternalFieldCount(1);

    JavaScriptMessageProvider* provider=static_cast<JavaScriptMessageProvider*>(isolate->GetData(0));
    provider->setObjectConstructor(SideNotification::NAME, tpl->GetFunction());
    provider->setObjectTemplate(SideNotification::NAME, tpl->InstanceTemplate());
    exports->Set(String::NewFromUtf8(isolate, SideNotification::NAME.c_str()), tpl->GetFunction());
}
Esempio n. 5
0
/* Execute a javascript file */
static Handle<Value> msV8ExecuteScript(const char *path, int throw_exception = MS_FALSE)
{
  char fullpath[MS_MAXPATHLEN];
  map<string, Persistent<Script> >::iterator it;
  Isolate *isolate = Isolate::GetCurrent();
  V8Context *v8context = (V8Context*)isolate->GetData();

  /* construct the path */
  msBuildPath(fullpath, v8context->paths.top().c_str(), path);
  char *filepath = msGetPath((char*)fullpath);
  v8context->paths.push(filepath);
  free(filepath);

  Handle<Script> script;
  it = v8context->scripts.find(fullpath);
  if (it == v8context->scripts.end()) {
    Handle<Value> source = msV8ReadFile(v8context, fullpath);
    Handle<String> script_name = String::New(msStripPath((char*)path));
    script = msV8CompileScript(source->ToString(), script_name);
    if (script.IsEmpty()) {
      v8context->paths.pop();
      if (throw_exception) {
        return ThrowException(String::New("Error compiling script"));
      }
    }
    /* cache the compiled script */
    Persistent<Script> pscript;
    pscript.Reset(isolate, script);
    v8context->scripts[fullpath] = pscript;
  } else {
    script = v8context->scripts[fullpath];
  }

  Handle<Value> result = msV8RunScript(script);
  v8context->paths.pop();
  if (result.IsEmpty() && throw_exception) {
    return ThrowException(String::New("Error running script"));
  }

  return result;
}