bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context, const char* worldName, int debugId)
{
    if (!debugData(context)->IsUndefined())
        return false;
    v8::HandleScope scope(context->GetIsolate());
    v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId, context->GetIsolate());
    setDebugData(context, debugData);
    return true;
}
Example #2
0
//Init
void DeviceNode::Init(v8::Handle<v8::Object> exports) {
  Isolate* isolate = exports->GetIsolate();

  // Prepare constructor template
  Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
  tpl->SetClassName(String::NewFromUtf8(isolate, "DeviceNode"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);

  // Prototype
  NODE_SET_PROTOTYPE_METHOD(tpl, "getName", DeviceNode::GetName);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getId", DeviceNode::GetId);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getModel", DeviceNode::GetModel);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getProtocol", DeviceNode::GetProtocol);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getDeviceType", DeviceNode::GetDeviceType);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getLastSentValue", DeviceNode::GetLastSentValue);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getMethods", DeviceNode::GetMethods);
  NODE_SET_PROTOTYPE_METHOD(tpl, "getDimValue", DeviceNode::GetDimValue);
  NODE_SET_PROTOTYPE_METHOD(tpl, "isOn", DeviceNode::IsOn);
  NODE_SET_PROTOTYPE_METHOD(tpl, "isDimmable", DeviceNode::IsDimmable);

  NODE_SET_PROTOTYPE_METHOD(tpl, "turnOff", DeviceNode::TurnOff);
  NODE_SET_PROTOTYPE_METHOD(tpl, "turnOn", DeviceNode::TurnOn);
  NODE_SET_PROTOTYPE_METHOD(tpl, "dim", DeviceNode::Dim);

  constructor.Reset(isolate, tpl->GetFunction());
  exports->Set(String::NewFromUtf8(isolate, "DeviceNode"),
               tpl->GetFunction());
}
Example #3
0
V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context)
    : m_wrapperBoilerplates(context->GetIsolate())
    , m_constructorMap(context->GetIsolate())
    , m_isolate(context->GetIsolate())
    , m_contextHolder(adoptPtr(new gin::ContextHolder(context->GetIsolate())))
    , m_context(m_isolate, context)
    , m_customElementBindings(adoptPtr(new CustomElementBindingMap()))
{
    m_contextHolder->SetContext(context);

    v8::Context::Scope contextScope(context);
    ASSERT(m_errorPrototype.isEmpty());
    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Error")));
    ASSERT(!object.IsEmpty());
    v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype"));
    ASSERT(!prototypeValue.IsEmpty());
    m_errorPrototype.set(m_isolate, prototypeValue);
}
Example #4
0
ScriptState::ScriptState(v8::Handle<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
    : m_isolate(context->GetIsolate())
    , m_context(m_isolate, context)
    , m_world(world)
    , m_perContextData(V8PerContextData::create(context))
{
    ASSERT(m_world);
    m_context.setWeak(this, &weakCallback);
    context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, this);
}
Example #5
0
void DOMWrapperWorld::makeContextWeak(v8::Handle<v8::Context> context)
{
    ASSERT(isIsolatedWorld());
    ASSERT(isolatedWorld(context) == this);
    v8::Isolate* isolate = context->GetIsolate();
    v8::Persistent<v8::Context> persistent = v8::Persistent<v8::Context>::New(isolate, context);
    WeakHandleListener<DOMWrapperWorld>::makeWeak(isolate, persistent, this);
    // Matching deref is in weak callback.
    this->ref();
}
Example #6
0
// The read-eval-execute loop of the shell.
void RunShell(v8::Handle<v8::Context> context) {
  fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion());
  static const int kBufferSize = 256;
  // Enter the execution environment before evaluating any code.
  v8::Context::Scope context_scope(context);
  v8::Local<v8::String> name(
      v8::String::NewFromUtf8(context->GetIsolate(), "(shell)"));
  while (true) {
    char buffer[kBufferSize];
    fprintf(stderr, "> ");
    char* str = fgets(buffer, kBufferSize, stdin);
    if (str == NULL) break;
    v8::HandleScope handle_scope(context->GetIsolate());
    ExecuteString(context->GetIsolate(),
                  v8::String::NewFromUtf8(context->GetIsolate(), str),
                  name,
                  true,
                  true);
  }
  fprintf(stderr, "\n");
}
int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context)
{
    v8::HandleScope scope(context->GetIsolate());
    v8::Handle<v8::Value> data = debugData(context);

    if (!data->IsString())
        return -1;
    v8::String::Utf8Value utf8(data);
    char* comma = strnstr(*utf8, ",", utf8.length());
    if (!comma)
        return -1;
    return atoi(comma + 1);
}
Example #8
0
V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context)
    : m_isolate(context->GetIsolate())
    , m_wrapperBoilerplates(m_isolate)
    , m_constructorMap(m_isolate)
    , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate)))
    , m_context(m_isolate, context)
    , m_activityLogger(0)
    , m_compiledPrivateScript(m_isolate)
{
    m_contextHolder->SetContext(context);

    v8::Context::Scope contextScope(context);
    ASSERT(m_errorPrototype.isEmpty());
    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Error")));
    ASSERT(!object.IsEmpty());
    v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype"));
    ASSERT(!prototypeValue.IsEmpty());
    m_errorPrototype.set(m_isolate, prototypeValue);
}
Example #9
0
      // Registers this module with Node
      static void Register (v8::Handle <v8::Object> target)
      {
         auto isolate = target->GetIsolate ();

         // Prepare constructor template
         auto function_template = v8::FunctionTemplate::New (isolate, Create);
         function_template->SetClassName (v8::String::NewFromUtf8 (isolate, descriptor.GetName ().c_str ()));
         function_template->InstanceTemplate ()->SetInternalFieldCount (1);

         // add GetModuleInfo function
         descriptor.AddFunction ("getModuleInfo", GetModuleInfo, "Retrieves framework information about this module.", NO_PARAMETERS, RETURNS_AN OBJECT);

         // Set up exported function prototypes
         for (auto function : descriptor.GetFunctions ())
         {
            NODE_SET_PROTOTYPE_METHOD (function_template, function.name.c_str (), function.callback);
         }

         constructor.Reset (isolate, function_template->GetFunction ());
         target->Set (v8::String::NewFromUtf8 (isolate, descriptor.GetName ().c_str ()), function_template->GetFunction ());
      }
Example #10
0
CContext::CContext(v8::Handle<v8::Context> context)
{
  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());

  m_context.Reset(context->GetIsolate(), context);
}
Example #11
0
void __registerModule(v8::Handle<v8::Object> target)
{
	v8::Isolate* isolate = target->GetIsolate();
	target->Set(JSTRING("ModuleName"), JSTRING("Example Addon"));
}