// Check if this appmetrics agent native module is loaded via the node-hc command. // This is actually checking if this module has appmetrics/launcher.js as it's grandparent. // For reference: // A locally loaded module would have ancestry like: // ... // ^-- some_module_that_does_require('appmetrics') (grandparent) // ^--- .../node_modules/appmetrics/index.js (parent) // ^-- .../node_modules/appmetrics/appmetrics.node (this) // // A globally loaded module would have ancestry like: // .../node_modules/appmetrics/launcher.js (grandparent) // ^--- .../node_modules/appmetrics/index.js (parent) // ^-- .../node_modules/appmetrics/appmetrics.node (this) // static bool isGlobalAgent(Handle<Object> module) { Nan::HandleScope scope; Local<Value> parent = module->Get(Nan::New<String>("parent").ToLocalChecked()); if (parent->IsObject()) { Local<Value> filename = parent->ToObject()->Get(Nan::New<String>("filename").ToLocalChecked()); if (filename->IsString() && isAppMetricsFile("index.js", toStdString(filename->ToString()))) { Local<Value> grandparent = parent->ToObject()->Get(Nan::New<String>("parent").ToLocalChecked()); Local<Value> gpfilename = grandparent->ToObject()->Get(Nan::New<String>("filename").ToLocalChecked()); if (gpfilename->IsString() && isAppMetricsFile("launcher.js", toStdString(gpfilename->ToString()))) { return true; } } } return false; }
Handle<Value> jsWindow::SetProperty(Local<String> name, Local<Value> value, const AccessorInfo& info) { Handle<Value> val; std::string key = value_to_string(name); vector<string>::iterator it = find(ro_props.begin(), ro_props.end(), key); if (it == ro_props.end()) { props[key] = Persistent<Value>::New(value); val = value; } else if (key == "location" && value->IsString()) { std::string uri = value_to_string(value); if (location->url.tostring() == uri) { // reload } else if (uri == "about:blank") { // assign location->url.protocol = "about"; location->url.host = "blank"; } else { location->url.assign_with_referer(uri); history->push_back(uri); load(uri); } // todo - log the location changes } return val; }
static gboolean gum_kernel_scan_context_emit_match (GumAddress address, gsize size, GumKernelScanContext * self) { ScriptScope scope (self->core->script); auto isolate = self->core->isolate; auto context = isolate->GetCurrentContext (); gboolean proceed = TRUE; auto on_match = Local<Function>::New (isolate, *self->on_match); auto recv = Undefined (isolate); Handle<Value> argv[] = { _gum_v8_uint64_new (address, self->core), Integer::NewFromUnsigned (isolate, size) }; Local<Value> result; if (on_match->Call (context, recv, G_N_ELEMENTS (argv), argv) .ToLocal (&result) && result->IsString ()) { v8::String::Utf8Value str (isolate, result); proceed = strcmp (*str, "stop") != 0; } return proceed; }
static gboolean gum_script_process_handle_module_match (const GumModuleDetails * details, gpointer user_data) { GumScriptMatchContext * ctx = static_cast<GumScriptMatchContext *> (user_data); GumScriptCore * core = ctx->self->core; Isolate * isolate = ctx->isolate; Local<Object> module (Object::New (isolate)); _gum_script_set_ascii (module, "name", details->name, core); _gum_script_set_pointer (module, "base", details->range->base_address, core); _gum_script_set_uint (module, "size", details->range->size, core); _gum_script_set_utf8 (module, "path", details->path, core); Handle<Value> argv[] = { module }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
JNIEXPORT jobject JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeEvalString (JNIEnv *env, jobject self, jstring source, jstring filename) { HandleScope scope(V8Runtime::v8_isolate); titanium::JNIScope jniScope(env); Local<Value> jsSource = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, source); if (jsSource.IsEmpty() || !jsSource->IsString()) { LOGE(TAG, "Error converting Javascript string, aborting evalString"); return NULL; } Local<Value> jsFilename = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, filename); TryCatch tryCatch(V8Runtime::v8_isolate); Local<Script> script = Script::Compile(jsSource.As<String>(), jsFilename.As<String>()); Local<Value> result = script->Run(); if (tryCatch.HasCaught()) { V8Util::openJSErrorDialog(V8Runtime::v8_isolate, tryCatch); V8Util::reportException(V8Runtime::v8_isolate, tryCatch, true); return NULL; } return TypeConverter::jsValueToJavaObject(V8Runtime::v8_isolate, env, result); }
static Local<Value> convert_result(uint64_t result, Local<Value> enc_val) { Local<Value> result_val; if (node::Buffer::HasInstance(enc_val)) { result_val = enc_val; if (node::Buffer::Length(result_val) >= sizeof(uint64_t)) { char* out_buf = node::Buffer::Data(result_val); *(reinterpret_cast<uint64_t*>(&out_buf[0])) = result; } else { Nan::ThrowError("Buffer argument too small"); } } else if (enc_val->IsString()) { node::encoding enc = parse_encoding(enc_val); if (enc == node::BASE64 || enc == node::HEX || enc == node::BINARY || enc == node::BUFFER) { result_val = convert_result(result, enc); } else { Nan::ThrowError("invalid encoding"); } } else { Nan::ThrowTypeError("argument must be a Buffer or string"); } return result_val; }
void encodeArray(bson_buffer *bb, const char *name, const Local<Value> element) { Local<Array> a = Array::Cast(*element); bson_buffer *arr = bson_append_start_array(bb, name); for (int i = 0, l=a->Length(); i < l; i++) { Local<Value> val = a->Get(Number::New(i)); stringstream keybuf; string keyval; keybuf << i << endl; keybuf >> keyval; if (val->IsString()) { encodeString(arr, keyval.c_str(), val); } else if (val->IsInt32()) { encodeInteger(arr, keyval.c_str(), val); } else if (val->IsNumber()) { encodeNumber(arr, keyval.c_str(), val); } else if (val->IsBoolean()) { encodeBoolean(arr, keyval.c_str(), val); } else if (val->IsArray()) { encodeArray(arr, keyval.c_str(), val); } else if (val->IsObject()) { bson bson(encodeObject(val)); bson_append_bson(arr, keyval.c_str(), &bson); bson_destroy(&bson); } } bson_append_finish_object(arr); }
argtokey_callback_t argToKey(const Local<Value> &val, MDB_val &key, bool keyIsUint32) { // Check key type if (keyIsUint32 && !val->IsUint32()) { Nan::ThrowError("Invalid key. keyIsUint32 specified on the database, but the given key was not an unsigned 32-bit integer"); return nullptr; } if (!keyIsUint32 && !val->IsString()) { Nan::ThrowError("Invalid key. String key expected, because keyIsUint32 isn't specified on the database."); return nullptr; } // Handle uint32_t key if (keyIsUint32) { uint32_t *v = new uint32_t; *v = val->Uint32Value(); key.mv_size = sizeof(uint32_t); key.mv_data = v; return ([](MDB_val &key) -> void { delete (uint32_t*)key.mv_data; }); } // Handle string key CustomExternalStringResource::writeTo(val->ToString(), &key); return ([](MDB_val &key) -> void { delete[] (uint16_t*)key.mv_data; }); return nullptr; }
static gboolean gum_v8_process_handle_malloc_range_match (const GumMallocRangeDetails * details, gpointer user_data) { GumV8MatchContext * ctx = static_cast<GumV8MatchContext *> (user_data); GumV8Core * core = ctx->self->core; Isolate * isolate = ctx->isolate; Local<Object> range (Object::New (isolate)); _gum_v8_object_set_pointer (range, "base", details->range->base_address, core); _gum_v8_object_set_uint (range, "size", details->range->size, core); Handle<Value> argv[] = { range }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
void FieldDefn::justificationSetter(Local<String> property, Local<Value> value, const AccessorInfo &info) { HandleScope scope; FieldDefn *def = ObjectWrap::Unwrap<FieldDefn>(info.This()); OGRJustification justification; std::string str = TOSTR(value); if(value->IsString()){ if(str == "Left") { justification = OJLeft; } else if (str == "Right") { justification = OJRight; } else if (str == "Undefined") { justification = OJUndefined; } else { NODE_THROW("Unrecognized justification"); return; } } else if (value->IsNull() || value->IsUndefined()){ justification = OJUndefined; } else { NODE_THROW("justification must be a string or undefined"); return; } def->this_->SetJustify(justification); }
static gboolean gum_script_process_thread_match (const GumThreadDetails * details, gpointer user_data) { GumScriptMatchContext * ctx = static_cast<GumScriptMatchContext *> (user_data); GumScriptCore * core = ctx->self->core; Isolate * isolate = ctx->isolate; if (gum_script_is_ignoring (details->id)) return TRUE; Local<Object> thread (Object::New (isolate)); _gum_script_set (thread, "id", Number::New (isolate, details->id), core); _gum_script_set (thread, "state", String::NewFromOneByte (isolate, reinterpret_cast<const uint8_t *> (gum_script_thread_state_to_string ( details->state))), core); _gum_script_set (thread, "context", _gum_script_cpu_context_new ( &details->cpu_context, ctx->self->core), core); Handle<Value> argv[] = { thread }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
void FieldDefn::nameSetter(Local<String> property, Local<Value> value, const AccessorInfo &info) { HandleScope scope; FieldDefn *def = ObjectWrap::Unwrap<FieldDefn>(info.This()); if(!value->IsString()){ NODE_THROW("Name must be string"); return; } def->this_->SetName(TOSTR(value)); }
Handle<Value> Feature::addAttributes(const Arguments& args) { HandleScope scope; Feature* fp = ObjectWrap::Unwrap<Feature>(args.This()); if (args.Length() > 0 ) { Local<Value> value = args[0]; if (value->IsNull() || value->IsUndefined()) { return ThrowException(Exception::TypeError(String::New("object expected"))); } else { Local<Object> attr = value->ToObject(); try { Local<Array> names = attr->GetPropertyNames(); uint32_t i = 0; uint32_t a_length = names->Length(); boost::scoped_ptr<mapnik::transcoder> tr(new mapnik::transcoder("utf8")); while (i < a_length) { Local<Value> name = names->Get(i)->ToString(); Local<Value> value = attr->Get(name); if (value->IsString()) { UnicodeString ustr = tr->transcode(TOSTR(value)); boost::put(*fp->get(),TOSTR(name),ustr); } else if (value->IsNumber()) { double num = value->NumberValue(); // todo - round if (num == value->IntegerValue()) { int integer = value->IntegerValue(); boost::put(*fp->get(),TOSTR(name),integer); } else { double dub_val = value->NumberValue(); boost::put(*fp->get(),TOSTR(name),dub_val); } } else { std::clog << "unhandled type for property: " << TOSTR(name) << "\n"; } i++; } } catch (const std::exception & ex ) { return ThrowException(Exception::Error( String::New(ex.what()))); } catch (...) { return ThrowException(Exception::Error( String::New("Unknown exception happended - please report bug"))); } } } return Undefined(); }
void Widget::ClassNameSetter(Local<String> name, Local<Value> value, const AccessorInfo& info) { HandleScope scope; if (value->IsString()) { ClutterActor *instance = ObjectWrap::Unwrap<Actor>(info.This())->_actor; ObjectWrap::Unwrap<Widget>(info.This())->hasClassName = TRUE; mx_stylable_set_style_class(MX_STYLABLE(instance), *String::Utf8Value(value->ToString())); mx_stylable_set_style(MX_STYLABLE(instance), mx_style_get_default()); } }
void Msg_Struct::build_http_msg_buffer(Isolate* isolate, v8::Local<v8::Object> object, std::string &str) { std::stringstream stream; for(std::vector<Field_Info>::const_iterator iter = field_vec().begin(); iter != field_vec().end(); iter++) { stream.str(""); stream << "\"" << iter->field_name << "\":"; Local<Value> value = object->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, iter->field_name.c_str(), NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); if(iter->field_type == "int8" || iter->field_type == "int16" || iter->field_type == "int32") { int32_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "int64") { int64_t val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "double") { double val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "bool") { bool val = 0; if (value->IsBoolean()) { val = value->BooleanValue(isolate->GetCurrentContext()).FromJust(); } stream << val << ","; } else if(iter->field_type == "string") { if (value->IsString()) { String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked()); stream << "\"" << ToCString(str) << "\","; } else { stream << "\"\","; } } else { LOG_ERROR("Can not find the field_type:%s, struct_name:%s", iter->field_type.c_str(), struct_name().c_str()); } str += stream.str(); } }
void CanvasRenderingContext2D::SetStrokeStyle(Local<Name> property, Local<Value> value, const PropertyCallbackInfo<void>& info) { if (!value->IsString()) return; auto strokeStyle = ConvertToString(value->ToString()); SkColor strokeColor; if (!TryParseColor(strokeStyle, strokeColor)) return; auto context = ToContext(info); context->myStrokeStyle = strokeStyle; context->myStrokeColor = strokeColor; }
// Check if a global appmetrics agent module is already loaded. // This is actually searching the module cache for a module with filepath // ending .../appmetrics/launcher.js static bool isGlobalAgentAlreadyLoaded(Handle<Object> module) { //Nan::HandleScope scope; Local<Object> cache = getRequireCache(module); Local<Array> props = cache->GetOwnPropertyNames(); if (props->Length() > 0) { for (uint32_t i=0; i<props->Length(); i++) { Local<Value> entry = props->Get(i); if (entry->IsString() && isAppMetricsFile("launcher.js", toStdString(entry->ToString()))) { return true; } } } return false; }
void ContactsPersonProxy::_setEmail(void* userContext, Handle<Value> value) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; if(!value->IsObject()) return; Handle<Object> emailObject = value->ToObject(); Local<Array> emailProperties = emailObject->GetPropertyNames(); for(int i = 0, len = emailProperties->Length(); i < len; i++) { Local<String> allEmailsKey = emailProperties->Get(i)->ToString(); Local<Value> allEmailsValue = emailObject->Get(allEmailsKey); AttributeSubKind::Type subKind = AttributeSubKind::Other; QString allEmailsKeyString = titanium::V8ValueToQString(allEmailsKey).toLower(); if(allEmailsKeyString == "work") { subKind = AttributeSubKind::Work; } else if(allEmailsKeyString == "personal") { subKind = AttributeSubKind::Personal; } else if(allEmailsKeyString == "home") { subKind = AttributeSubKind::Home; } if(!allEmailsValue->IsArray()) return; Local<Array> emails = Local<Array>::Cast(allEmailsValue); for(int i = 0, len = emails->Length(); i < len; i++) { Local<Value> emailValue = emails->Get(Number::New(i)); if(emailValue->IsString() || emailValue->IsNumber()) { obj->setContactDetails(AttributeKind::Email, subKind, emailValue); } else { // Something goes here, throw an error? } } } }
static gboolean gum_v8_module_handle_export_match (const GumExportDetails * details, gpointer user_data) { GumV8ExportsContext * ctx = static_cast<GumV8ExportsContext *> (user_data); Isolate * isolate = ctx->isolate; Local<Context> jc = isolate->GetCurrentContext (); PropertyAttribute attrs = static_cast<PropertyAttribute> (ReadOnly | DontDelete); Local<Object> exp (ctx->exp->Clone ()); if (details->type != GUM_EXPORT_FUNCTION) { Maybe<bool> success = exp->ForceSet (jc, ctx->type, ctx->variable, attrs); g_assert (success.IsJust ()); } Maybe<bool> success = exp->ForceSet (jc, ctx->name, String::NewFromOneByte (isolate, reinterpret_cast<const uint8_t *> (details->name)), attrs); g_assert (success.IsJust ()); success = exp->ForceSet (jc, ctx->address, _gum_v8_native_pointer_new (GSIZE_TO_POINTER (details->address), ctx->self->core), attrs); g_assert (success.IsJust ()); Handle<Value> argv[] = { exp }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
bool JSWrapper::execute( const char *scr, JSWrapperData *data, const char *fileName ) { HandleScope handle_scope( m_isolate ); Local<String> source = String::NewFromUtf8( m_isolate, scr, NewStringType::kNormal ).ToLocalChecked(); ScriptOrigin origin( v8::String::NewFromUtf8( m_isolate, fileName ? fileName : "Unknown" ) ); MaybeLocal<Script> maybeScript = Script::Compile( m_context, source, &origin ); bool success=false; if ( !maybeScript.IsEmpty() ) { Local<Script> script = maybeScript.ToLocalChecked(); MaybeLocal<Value> maybeResult = script->Run(m_context); if ( !maybeResult.IsEmpty() ) { Local<Value> result = maybeResult.ToLocalChecked(); if ( data ) { if ( result->IsNumber() ) data->setNumber( result->ToNumber()->Value() ); else if ( result->IsString() ) { String::Utf8Value utf8( result ); data->setString( *utf8 ); } else if ( result->IsBoolean() ) data->setBoolean( result->ToBoolean()->Value() ); else if ( result->IsObject() ) data->setObject( new JSWrapperObject( m_isolate, result->ToObject() ) ); else if ( result->IsNull() ) data->setNull(); else data->setUndefined(); } success=true; } } return success; }
void FieldDefn::typeSetter(Local<String> property, Local<Value> value, const AccessorInfo &info) { HandleScope scope; FieldDefn *def = ObjectWrap::Unwrap<FieldDefn>(info.This()); if(!value->IsString()){ NODE_THROW("type must be a string"); return; } std::string name = TOSTR(value); int type = getFieldTypeByName(name); if(type < 0){ NODE_THROW("Unrecognized field type"); } else { def->this_->SetType(OGRFieldType(type)); } }
static gboolean gum_v8_process_handle_range_match (const GumRangeDetails * details, gpointer user_data) { GumV8MatchContext * ctx = static_cast<GumV8MatchContext *> (user_data); GumV8Core * core = ctx->self->core; Isolate * isolate = ctx->isolate; char prot_str[4] = "---"; if ((details->prot & GUM_PAGE_READ) != 0) prot_str[0] = 'r'; if ((details->prot & GUM_PAGE_WRITE) != 0) prot_str[1] = 'w'; if ((details->prot & GUM_PAGE_EXECUTE) != 0) prot_str[2] = 'x'; Local<Object> range (Object::New (isolate)); _gum_v8_object_set_pointer (range, "base", details->range->base_address, core); _gum_v8_object_set_uint (range, "size", details->range->size, core); _gum_v8_object_set_ascii (range, "protection", prot_str, core); const GumFileMapping * f = details->file; if (f != NULL) { Local<Object> file (Object::New (isolate)); _gum_v8_object_set_utf8 (file, "path", f->path, core); _gum_v8_object_set_uint (file, "offset", f->offset, core); _gum_v8_object_set (range, "file", file, core); } Handle<Value> argv[] = { range }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } return proceed; }
bool AppjsSyncHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) { if (browser_.get()) { HandleScope scope; Local<Value> argv[1] = { CefStringToV8(arguments[0]->GetStringValue()) }; Handle<Object> window = NativeWindow::GetWindow(browser_)->GetV8Handle();; Local<Function> handler = Local<Function>::Cast(window->Get(String::NewSymbol("onmessage"))); Local<Value> result = handler->Call(window, 1, argv); if (result->IsString()) { char* plain = V8StringToChar(result->ToString()); retval = CefV8Value::CreateString(plain); } } return true; }
static void Set_FontState_face(Local<String> property, Local<Value> value, const AccessorInfo& info) { HandleScope scope; Local<Object> self = info.Holder(); Local<External> wrap = Local<External>::Cast(self->GetInternalField(0)); if (wrap.IsEmpty()) return; FontState *tmp = (FontState *) wrap->Value(); if (tmp == NULL) return; if (!value.IsEmpty() && value->IsString()) { String::Utf8Value utf8_value(value); tmp->setFace(Utf8ToTchar(*utf8_value)); } }
static GetdnsType getGetdnsType(Local<Value> value) { if (value->IsNumber() || value->IsNumberObject()) { return IntType; } else if (value->IsBoolean() || value->IsBooleanObject()) { return BoolType; } else if (value->IsString() || value->IsStringObject()) { return StringType; } else if (value->IsObject()) { // could be a node buffer or array if (node::Buffer::HasInstance(value)) { return BinDataType; } else if (value->IsArray()) { return ListType; } else if (GNUtil::isDictionaryObject(value)) { return DictType; } } return UnknownType; }
bool createTXTRecord(scopedTXTRecord& txtRecord, Local<Object>& object) { HandleScope scope; Local<Array> names = object->GetPropertyNames(); uint32_t length = names->Length(); for (uint32_t index = 0; index<length; ++index) { Local<Value> key = names->Get(index); if (key->IsString()) { // Local<Value> buffer = object->Get(key); Handle<Value> buffer = object->Get(key); String::Utf8Value string_value( buffer->ToString()); // A DNS-SD key is 7-bit ascii String::AsciiValue keyString(key); std::string buf(*keyString, keyString.length()); /* Local<Object> obj; uint8_t valLen = 0; const void *value = NULL; if (Buffer::HasInstance(buffer)) { obj = buffer->ToObject(); valLen = Buffer::Length(obj); value = Buffer::Data(obj); } if (txtRecord.setValue(buf.c_str(), valLen, value) != kDNSServiceErr_NoError) { return false; } */ if (txtRecord.setValue(buf.c_str(), buffer->ToString()->Utf8Length(), *string_value) != kDNSServiceErr_NoError) { return false; } } else { return false; } } return true; }
void ContactsPersonProxy::_setPhone(void* userContext, Handle<Value> value) { ContactsPersonProxy *obj = (ContactsPersonProxy*) userContext; if(!value->IsObject()) return; Handle<Object> phoneObject = value->ToObject(); Local<Array> phoneProperties = phoneObject->GetPropertyNames(); for(int i = 0, len = phoneProperties->Length(); i < len; i++) { Local<String> phoneKey = phoneProperties->Get(i)->ToString(); Local<Value> phoneValue = phoneObject->Get(phoneKey); AttributeSubKind::Type subKind = AttributeSubKind::Other; QString phoneStringValue = titanium::V8ValueToQString(phoneKey); if(phoneStringValue == "home") { subKind = AttributeSubKind::Home; } else if(phoneStringValue == "work") { subKind = AttributeSubKind::Work; } else if(phoneStringValue == "mobile") { subKind = AttributeSubKind::PhoneMobile; } if(!phoneValue->IsArray()) return; Local<Array> phones = Local<Array>::Cast(phoneValue); for(int i = 0, len = phones->Length(); i < len; i++) { Local<Value> currentMessage = phones->Get(Number::New(i)); if(!currentMessage->IsString()) return; obj->setContactDetails(AttributeKind::Phone, subKind, currentMessage); } } }
static gboolean gum_v8_script_handle_thread_match (const GumThreadDetails * details, gpointer user_data) { GumV8MatchContext * ctx = static_cast<GumV8MatchContext *> (user_data); GumV8Core * core = ctx->self->core; Isolate * isolate = ctx->isolate; if (gum_script_backend_is_ignoring (GUM_SCRIPT_BACKEND (core->backend), details->id)) return TRUE; Local<Object> thread (Object::New (isolate)); _gum_v8_object_set (thread, "id", Number::New (isolate, details->id), core); _gum_v8_object_set (thread, "state", String::NewFromOneByte (isolate, (const uint8_t *) _gum_v8_thread_state_to_string (details->state)), core); Local<Object> cpu_context = _gum_v8_cpu_context_new (&details->cpu_context, ctx->self->core); _gum_v8_object_set (thread, "context", cpu_context, core); Handle<Value> argv[] = { thread }; Local<Value> result = ctx->on_match->Call (ctx->receiver, 1, argv); gboolean proceed = TRUE; if (!result.IsEmpty () && result->IsString ()) { String::Utf8Value str (result); proceed = (strcmp (*str, "stop") != 0); } _gum_v8_cpu_context_free_later ( new GumPersistent<Object>::type (isolate, cpu_context), core); return proceed; }
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; } }
void Image::SetSource(Local<String>, Local<Value> val, const AccessorInfo &info) { HandleScope scope; Image *img = ObjectWrap::Unwrap<Image>(info.This()); cairo_status_t status = CAIRO_STATUS_READ_ERROR; // url string if (val->IsString()) { String::AsciiValue src(val); if (img->filename) free(img->filename); img->filename = strdup(*src); // status = img->load(); // Load from assets directory uint8_t* buf; int len; JSG::loadAsset(img->filename, (unsigned char**) &buf, &len); if (buf) { status = img->loadFromBuffer(buf, len); free(buf); } // Buffer } else if (Buffer::HasInstance(val)) { uint8_t *buf = (uint8_t *) Buffer::Data(val->ToObject()); unsigned len = Buffer::Length(val->ToObject()); status = img->loadFromBuffer(buf, len); } // check status if (status) { img->error(Canvas::Error(status)); } else { img->loaded(); } }