void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) { NanScope(); if (returned_value->IsArray()) { Handle<Array> array = Handle<Array>::Cast(returned_value); ctx_w->imports = sass_make_import_list(array->Length()); for (size_t i = 0; i < array->Length(); ++i) { Local<Value> value = array->Get(i); if (!value->IsObject()) continue; Local<Object> object = Local<Object>::Cast(value); char* path = create_string(object->Get(NanNew<String>("file"))); char* contents = create_string(object->Get(NanNew<String>("contents"))); ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } } else if (returned_value->IsObject()) { ctx_w->imports = sass_make_import_list(1); Local<Object> object = Local<Object>::Cast(returned_value); char* path = create_string(object->Get(NanNew<String>("file"))); char* contents = create_string(object->Get(NanNew<String>("contents"))); ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } else { ctx_w->imports = sass_make_import_list(1); ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0); } }
const NdbQueryOperationDef * createNextLevel(QueryOperation *queryOp, Handle<Object> spec, const NdbQueryOperationDef * parent) { DEBUG_MARKER(UDEB_DEBUG); NdbQueryBuilder *builder = queryOp->getBuilder(); Isolate * isolate = Isolate::GetCurrent(); /* Pull values out of the JavaScript object */ Local<Value> v; const NdbDictionary::Table * table = 0; const NdbDictionary::Index * index = 0; int depth = spec->Get(GET_KEY(K_depth))->Int32Value(); v = spec->Get(GET_KEY(K_tableHandler)); if(v->IsObject()) { v = v->ToObject()->Get(GET_KEY(K_dbTable)); if(v->IsObject()) { table = unwrapPointer<const NdbDictionary::Table *>(v->ToObject()); } } bool isPrimaryKey = spec->Get(GET_KEY(K_isPrimaryKey))->BooleanValue(); DEBUG_PRINT("Creating QueryOperationDef at level %d for table: %s", depth, table->getName()); if(! isPrimaryKey) { v = spec->Get(GET_KEY(K_indexHandler)); if(v->IsObject()) { v = v->ToObject()->Get(GET_KEY(K_dbIndex)); if(v->IsObject()) { index = unwrapPointer<const NdbDictionary::Index *> (v->ToObject()); } } assert(index); } v = spec->Get(GET_KEY(K_joinTo)); Array * joinColumns = Array::Cast(*v); /* Build the key */ int nKeyParts = joinColumns->Length(); const NdbQueryOperand * key_parts[nKeyParts+1]; for(int i = 0 ; i < nKeyParts ; i++) { String::Utf8Value column_name(joinColumns->Get(i)); key_parts[i] = builder->linkedValue(parent, *column_name); DEBUG_PRINT_DETAIL("Key part %d: %s", i, *column_name); } key_parts[nKeyParts] = 0; return queryOp->defineOperation(index, table, key_parts); }
const NdbQueryOperationDef * createTopLevelQuery(QueryOperation *queryOp, Handle<Object> spec, Handle<Object> keyBuffer) { DEBUG_MARKER(UDEB_DEBUG); Isolate * isolate = Isolate::GetCurrent(); NdbQueryBuilder *builder = queryOp->getBuilder(); /* Pull values out of the JavaScript object */ Local<Value> v; const Record * keyRecord = 0; const NdbDictionary::Table * table = 0; const NdbDictionary::Index * index = 0; v = spec->Get(GET_KEY(K_keyRecord)); if(v->IsObject()) { keyRecord = unwrapPointer<const Record *>(v->ToObject()); }; v = spec->Get(GET_KEY(K_tableHandler)); if(v->IsObject()) { v = v->ToObject()->Get(GET_KEY(K_dbTable)); if(v->IsObject()) { table = unwrapPointer<const NdbDictionary::Table *>(v->ToObject()); } } bool isPrimaryKey = spec->Get(GET_KEY(K_isPrimaryKey))->BooleanValue(); const char * key_buffer = node::Buffer::Data(keyBuffer); if(! isPrimaryKey) { v = spec->Get(GET_KEY(K_indexHandler)); if(v->IsObject()) { v = v->ToObject()->Get(GET_KEY(K_dbIndex)); if(v->IsObject()) { index = unwrapPointer<const NdbDictionary::Index *> (v->ToObject()); } } assert(index); } /* Build the key */ int nKeyParts = keyRecord->getNoOfColumns(); const NdbQueryOperand * key_parts[nKeyParts+1]; for(int i = 0; i < nKeyParts ; i++) { size_t offset = keyRecord->getColumnOffset(i); size_t length = keyRecord->getValueLength(i, key_buffer + offset); offset += keyRecord->getValueOffset(i); // accounts for length bytes key_parts[i] = builder->constValue(key_buffer + offset, length); } key_parts[nKeyParts] = 0; return queryOp->defineOperation(index, table, key_parts); }
jsvalue JsEngine::ErrorFromV8(TryCatch& trycatch) { jsvalue v; HandleScope scope; Local<Value> exception = trycatch.Exception(); v.type = JSVALUE_TYPE_UNKNOWN_ERROR; v.value.str = 0; v.length = 0; // If this is a managed exception we need to place its ID inside the jsvalue // and set the type JSVALUE_TYPE_MANAGED_ERROR to make sure the CLR side will // throw on it. if (exception->IsObject()) { Local<Object> obj = Local<Object>::Cast(exception); if (obj->InternalFieldCount() == 1) { Local<External> wrap = Local<External>::Cast(obj->GetInternalField(0)); ManagedRef* ref = (ManagedRef*)wrap->Value(); v.type = JSVALUE_TYPE_MANAGED_ERROR; v.length = ref->Id(); return v; } } jserror *error = new jserror(); memset(error, 0, sizeof(jserror)); Local<Message> message = trycatch.Message(); if (!message.IsEmpty()) { error->line = message->GetLineNumber(); error->column = message->GetStartColumn(); error->resource = AnyFromV8(message->GetScriptResourceName()); error->message = AnyFromV8(message->Get()); } if (exception->IsObject()) { Local<Object> obj2 = Local<Object>::Cast(exception); error->type = AnyFromV8(obj2->GetConstructorName()); } error->exception = AnyFromV8(exception); v.type = JSVALUE_TYPE_ERROR; v.value.ptr = error; return v; }
void ParamRsaPSS::FromV8(Local<Value> v8Value) { try { Nan::HandleScope(); if (!v8Value->IsObject()) { THROW_ERROR("Parameter 1 MUST be Object", NULL); } Local<Object> v8Params = v8Value->ToObject(); // Check data if (!check_param_number(v8Params, STR_MGF)) THROW_ERROR("Attribute 'mgf' MUST be NUMBER", NULL); if (!check_param_number(v8Params, STR_SALT_LEN)) THROW_ERROR("Attribute 'saltLen' MUST be NUMBER", NULL); if (!check_param_number(v8Params, STR_HASH_ALG)) THROW_ERROR("Attribute 'hashAlg' MUST be NUMBER", NULL); Free(); Init(); param.sLen = Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_SALT_LEN).ToLocalChecked())).ToLocalChecked()->Uint32Value(); param.mgf = Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_MGF).ToLocalChecked())).ToLocalChecked()->Uint32Value(); param.hashAlg = Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_HASH_ALG).ToLocalChecked())).ToLocalChecked()->Uint32Value(); } CATCH_ERROR; }
bool ArgConverter::TryConvertToJavaLong(const Local<Value>& value, jlong& javaLong) { bool success = false; if (!value.IsEmpty()) { if (value->IsNumber() || value->IsNumberObject()) { javaLong = (jlong)value->IntegerValue(); success = true; } else if (value->IsObject()) { auto obj = Local<Object>::Cast(value); auto isJavaLongValue = obj->GetHiddenValue(V8StringConstants::GetJavaLong()); if (!isJavaLongValue.IsEmpty() && isJavaLongValue->BooleanValue()) { javaLong = (jlong)ConvertToJavaLong(value); success = true; } } } return success; }
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); }
void test_BasicCall() { HandleScope handle_scope; Handle<ObjectTemplate> templ = ObjectTemplate::New(); Handle<FunctionTemplate> fnT = v8::FunctionTemplate::New(AddOne); templ->Set("AddOne", fnT); Persistent<Context> context = Context::New(NULL, templ); Context::Scope context_scope(context); Local<Value> addone = context->Global()->Get(String::New("AddOne")); do_check_true(!addone.IsEmpty()); do_check_true(!addone->IsUndefined()); do_check_true(addone->IsObject()); do_check_true(addone->IsFunction()); Local<Function> fn = addone.As<Function>(); do_check_eq(fn, fnT->GetFunction()); Local<Number> n = Number::New(0.5); Handle<Value> args[] = { n }; Local<Value> v = fn->Call(context->Global(), 1, args); do_check_true(!v.IsEmpty()); do_check_true(v->IsNumber()); Local<Number> n2 = v->ToNumber(); do_check_eq(n2->Value(), 1.5); context.Dispose(); }
bool ValidateOptions(Local<Value> options, Isolate *isolate) { if (!options->IsObject()) { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Options must be an object"))); return false; } return true; }
txn_scope(Local<Value> arg, MDB_env *env) : _env(NULL), _txn(NULL), _readonly(false), _created(false), _commit(false) { if (arg->IsObject()) { _txn = node::ObjectWrap::Unwrap<txn>(arg->ToObject())->_txn; } else { _created = true; mdb_txn_begin(env, NULL, 0, &_txn); } }
Handle<Value> TypedArray::New(GDALDataType type, unsigned int length) { NanEscapableScope(); Handle<Value> val; Handle<Function> constructor; Local<Object> global = NanGetCurrentContext()->Global(); const char *name; switch(type) { case GDT_Byte: name = "Uint8Array"; break; case GDT_Int16: name = "Int16Array"; break; case GDT_UInt16: name = "Uint16Array"; break; case GDT_Int32: name = "Int32Array"; break; case GDT_UInt32: name = "Uint32Array"; break; case GDT_Float32: name = "Float32Array"; break; case GDT_Float64: name = "Float64Array"; break; default: NanThrowError("Unsupported array type"); return NanEscapeScope(NanUndefined()); } // make ArrayBuffer val = global->Get(NanNew("ArrayBuffer")); if(val.IsEmpty() || !val->IsFunction()) { NanThrowError("Error getting ArrayBuffer constructor"); return NanEscapeScope(NanUndefined()); } constructor = val.As<Function>(); Local<Value> size = NanNew<Integer>(length * GDALGetDataTypeSize(type) / 8); Local<Value> array_buffer = constructor->NewInstance(1, &size); if(array_buffer.IsEmpty() || !array_buffer->IsObject()) { NanThrowError("Error allocating ArrayBuffer"); return NanEscapeScope(NanUndefined()); } // make TypedArray val = global->Get(NanNew(name)); if(val.IsEmpty() || !val->IsFunction()) { NanThrowError("Error getting typed array constructor"); return NanEscapeScope(NanUndefined()); } constructor = val.As<Function>(); Local<Object> array = constructor->NewInstance(1, &array_buffer); if(array.IsEmpty() || !array->IsObject()) { NanThrowError("Error creating TypedArray"); return NanEscapeScope(NanUndefined()); } return NanEscapeScope(array); }
Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { Local<Value> proto = InternalObject().Get(String::New("prototype")); if (proto.IsEmpty()) return Local<ObjectTemplate>(); JS_ASSERT(proto->IsObject()); return Local<ObjectTemplate>(reinterpret_cast<ObjectTemplate*>(*proto)); }
Local<Object> Array::CloneElementAt(JSUint32 index) { Local<Value> toBeCloned = Get(index); if (!toBeCloned->IsObject()) { return Local<Object>(); } return toBeCloned->ToObject()->Clone(); }
txn_scope(Local<Value> arg, env *env) : _env(env), _txn(NULL), _readonly(true), _created(false), _commit(false) { if (arg->IsObject()) { _txn = node::ObjectWrap::Unwrap<txn>(arg->ToObject())->_txn; } else { _created = true; _txn = env->require_readlock(); } }
void V8BuilderPolicy::SetDictKeyValue(std::string const & key, type const & var) { Nan::HandleScope scope; Local<Value> object(Nan::New(object_)); assert(object->IsObject()); Local<Object> obj = Local<Object>::Cast(object); assert(obj->IsObject()); obj->Set(Nan::New(key).ToLocalChecked(), Nan::New(var)); }
TaskOptions::TaskOptions(Handle<Object> source) : liveStreaming(NULL) { HandleScope scope; Local<Object> liveStreaming = Local<Object>::Cast(source->Get(String::New("liveStreaming"))); if (!liveStreaming.IsEmpty() && liveStreaming->IsObject()) { this->liveStreaming = new LiveStreamingOptions(liveStreaming); } }
// 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; }
void DBOperationHelper_NonVO(Handle<Object> spec, KeyOperation & op) { HandleScope scope; Local<Value> v; Local<Object> o; setKeysInOp(spec, op); v = spec->Get(HELPER_ROW_BUFFER); if(! v->IsNull()) { o = v->ToObject(); op.row_buffer = V8BINDER_UNWRAP_BUFFER(o); } v = spec->Get(HELPER_ROW_RECORD); if(! v->IsNull()) { o = v->ToObject(); const Record * record = unwrapPointer<const Record *>(o); op.row_record = record; v = spec->Get(HELPER_BLOBS); if(v->IsObject()) { if(op.opcode == 1) { op.nblobs = op.createBlobReadHandles(record); } else { op.nblobs = op.createBlobWriteHandles(v->ToObject(), record); } } } v = spec->Get(HELPER_LOCK_MODE); if(! v->IsNull()) { int intLockMode = v->Int32Value(); op.lmode = static_cast<NdbOperation::LockMode>(intLockMode); } v = spec->Get(HELPER_COLUMN_MASK); if(! v->IsNull()) { Array *maskArray = Array::Cast(*v); for(unsigned int m = 0 ; m < maskArray->Length() ; m++) { Local<Value> colId = maskArray->Get(m); op.useColumn(colId->Int32Value()); } } DEBUG_PRINT("Non-VO %s -- mask: %u lobs: %d", op.getOperationName(), op.u.maskvalue, op.nblobs); }
void TiRootObject::createStringMethods() { Local<Value> str = context_->Global()->Get(String::New("String")); if (!str->IsObject()) { // This should never happen ThrowException(String::New(Ti::Msg::INTERNAL__Global_String_symbol_is_not_an_object)); } Local<Object> strObj = str->ToObject(); const NativeStringInterface* nsi = objectFactory_->getNativeStringInterface(); strObj->Set(String::New("format"), FunctionTemplate::New(nsi->format)->GetFunction()); strObj->Set(String::New("formatCurrency"), FunctionTemplate::New(nsi->formatCurrency)->GetFunction()); strObj->Set(String::New("formatDate"), FunctionTemplate::New(nsi->formatDate)->GetFunction()); strObj->Set(String::New("formatDecimal"), FunctionTemplate::New(nsi->formatDecimal)->GetFunction()); strObj->Set(String::New("formatTime"), FunctionTemplate::New(nsi->formatTime)->GetFunction()); }
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 Image::set_prop(Local<String> property, Local<Value> value, const AccessorInfo& info) { HandleScope scope; Image* im = node::ObjectWrap::Unwrap<Image>(info.Holder()); std::string a = TOSTR(property); if (a == "background") { if (!value->IsObject()) ThrowException(Exception::TypeError( String::New("mapnik.Color expected"))); Local<Object> obj = value->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Color::constructor->HasInstance(obj)) ThrowException(Exception::TypeError(String::New("mapnik.Color expected"))); Color *c = node::ObjectWrap::Unwrap<Color>(obj); im->get()->set_background(*c->get()); } }
void V8Util::reportException(TryCatch &tryCatch, bool showLine) { HandleScope scope; Handle<Message> message = tryCatch.Message(); if (nameSymbol.IsEmpty()) { nameSymbol = SYMBOL_LITERAL("name"); messageSymbol = SYMBOL_LITERAL("message"); } if (showLine) { Handle<Message> message = tryCatch.Message(); if (!message.IsEmpty()) { String::Utf8Value filename(message->GetScriptResourceName()); String::Utf8Value msg(message->Get()); int linenum = message->GetLineNumber(); LOGE(EXC_TAG, "Exception occurred at %s:%i: %s", *filename, linenum, *msg); } } Local<Value> stackTrace = tryCatch.StackTrace(); String::Utf8Value trace(tryCatch.StackTrace()); if (trace.length() > 0 && !stackTrace->IsUndefined()) { LOGD(EXC_TAG, *trace); } else { Local<Value> exception = tryCatch.Exception(); if (exception->IsObject()) { Handle<Object> exceptionObj = exception->ToObject(); Handle<Value> message = exceptionObj->Get(messageSymbol); Handle<Value> name = exceptionObj->Get(nameSymbol); if (!message->IsUndefined() && !name->IsUndefined()) { String::Utf8Value nameValue(name); String::Utf8Value messageValue(message); LOGE(EXC_TAG, "%s: %s", *nameValue, *messageValue); } } else { String::Utf8Value error(exception); LOGE(EXC_TAG, *error); } } }
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; }
void debuggerListener(DebugEvent event, Handle<Object> exec_state, Handle<Object> event_data, Handle<Value> data) { printf("************************ V8 debugger ***********************\r\n"); HandleScope handleScope; Local<String> source = String::New( "temp = function (exec_state) { " " log(WARNING, 'halp now'); " " return serializeJSON(exec_state); " "} " ); Local<Script> code = Script::Compile(source); Local<Value> result = code->Run(); // printV8Value(result, true); assert(result->IsObject()); Local<Object> obj = result->ToObject(); assert(obj->IsFunction()); Local<Function> func = Function::Cast(*obj); Handle<Value> output = Debug::Call(func, exec_state); printV8Value(output, true); printV8Value(exec_state, true); printV8Value(event_data, true); printV8Value(data, true); /* Local<Object> _func = obj->Get(String::New(funcName.c_str()))->ToObject(); assert(_func->IsFunction()); Local<Function> func = Function::Cast(*_func); */ assert(0); }
void append_results(const std::string& data) { { LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::append_results: data("<< data <<")"); } HandleScope scope; // extract executor Local<Context> ctx = v8::Context::GetCurrent(); Local<Value> exec = ctx->Global()->Get(String::New("v8_context")); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::append_results: gets v8_context"); if (exec->IsObject()) { Local<Object> eObj = Local<Object>::Cast(exec); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::append_results: gets v8_context object"); v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(eObj->GetInternalField(0)); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::append_results: gets v8_context wrapper"); webEngine::jsExecutor* jsExec = static_cast<webEngine::jsExecutor*>(wrap->Value()); LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::append_results: gets jsExecutor"); jsExec->append_results(data); } }
Handle<Value> dump_object(const Arguments& args) { Handle<Value> res = Undefined(); string nm; string id; int dp; Local<Context> ctx = v8::Context::GetCurrent(); Local<Value> exec = ctx->Global()->Get(String::New("v8_context")); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::DumpObject: gets v8_context"); if (exec->IsObject()) { Local<Object> eObj = Local<Object>::Cast(exec); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::DumpObject: gets v8_context object"); v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(eObj->GetInternalField(0)); // LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::DumpObject: gets v8_context wrapper"); webEngine::jsExecutor* jsExec = static_cast<webEngine::jsExecutor*>(wrap->Value()); LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), "js::DumpObject: gets jsExecutor"); if (args.Length() > 1) { nm = value_to_string(args[1]); } else { nm = ""; } if (args.Length() > 2) { id = value_to_string(args[2]); } else { id = ""; } if (args.Length() > 3) { dp = args[3]->Int32Value(); } else { dp = 0; } string dat = jsExec->obj_dump(args[0], nm, id, dp, ctx); res = String::New(dat.c_str()); } return res; }
void ReportException(TryCatch &try_catch, bool show_line, std::string& err_msg) { HandleScope scope; if (show_line) DisplayExceptionLine(try_catch, err_msg); String::Utf8Value trace(try_catch.StackTrace()); // range errors have a trace member set to undefined if (trace.length() > 0 && !try_catch.StackTrace()->IsUndefined()) { fprintf(stderr, "%s\n", *trace); err_msg += *trace; err_msg += "\n"; } else { // this really only happens for RangeErrors, since they're the only // kind that won't have all this info in the trace, or when non-Error // objects are thrown manually. Local<Value> er = try_catch.Exception(); bool isErrorObject = er->IsObject() && !(er->ToObject()->Get(String::New("message"))->IsUndefined()) && !(er->ToObject()->Get(String::New("name"))->IsUndefined()); if (isErrorObject) { String::Utf8Value name(er->ToObject()->Get(String::New("name"))); fprintf(stderr, "%s: ", *name); err_msg += *name; err_msg += ": "; } String::Utf8Value msg(!isErrorObject ? er : er->ToObject()->Get(String::New("message"))); fprintf(stderr, "%s\n", *msg); err_msg += *msg; err_msg += "\n"; } fflush(stderr); }
void SerializePart(google::protobuf::Message *message, Handle<Object> src) { Handle<Function> to_array = handle_->GetInternalField(3).As<Function>(); Handle<Array> properties = to_array->Call(src, 0, NULL).As<Array>(); const Reflection *r = message->GetReflection(); for (int i = 0; i < descriptor->field_count(); i++) { Local<Value> value = properties->Get(i); if (value->IsUndefined() || value->IsNull()) continue; const FieldDescriptor* field = descriptor->field(i); if (field->is_repeated()) { if (value->IsArray()) { Handle<Array> array = value.As<Array>(); int length = array->Length(); for (int j = 0; j < length; j++) SerializeField(message, r, field, array->Get(j)); } else if (value->IsObject() && field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && field->message_type()->name().compare(0, 20, "KeyValuePair_String_") == 0) { Local<Object> object = value.As<Object>(); Local<Array> subProperties = object->GetOwnPropertyNames(); int len = subProperties->Length(); for (int keyIdx = 0; keyIdx < len; keyIdx++) { Local<Object> keyValuePair = Object::New(); Local<Value> key = subProperties->Get(keyIdx); keyValuePair->Set(KeySymbol, key); keyValuePair->Set(ValueSymbol, object->Get(key)); SerializeField(message, r, field, keyValuePair); } } } else { SerializeField(message, r, field, value); } } }
Handle<Value> Window(const v8::Arguments& args) { // throw if called without `new' if (!args.IsConstructCall()) return ThrowException(String::New("Cannot call constructor as function")); HandleScope scope; Handle<Value> retval; Local<Context> ctx = v8::Context::GetCurrent(); Local<Value> exec = ctx->Global()->Get(String::New("v8_context")); LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), _T("js::Window: gets v8_context")); if (exec->IsObject()) { Local<Object> eObj = Local<Object>::Cast(exec); v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(eObj->GetInternalField(0)); jsBrowser* jsExec = static_cast<jsBrowser*>(wrap->Value()); LOG4CXX_TRACE(webEngine::iLogger::GetLogger(), _T("js::Window: gets jsBrowser")); jsWindow *p = new jsWindow(jsExec, jsExec->window, jsExec->window); jsExec->register_window(p); retval = v8_wrapper::wrap_object<jsWindow>(p); } return scope.Close(retval); }
void ParamRsaOAEP::FromV8(Local<Value> v8Value) { try { Nan::HandleScope(); if (!v8Value->IsObject()) { THROW_ERROR("Parameter 1 MUST be Object", NULL); } Local<Object> v8Params = v8Value->ToObject(); // Check data if (!check_param_number(v8Params, STR_MGF)) THROW_ERROR("Attribute 'mgf' MUST be NUMBER", NULL); if (!check_param_number(v8Params, STR_SOURCE)) THROW_ERROR("Attribute 'source' MUST be NUMBER", NULL); if (!check_param_number(v8Params, STR_HASH_ALG)) THROW_ERROR("Attribute 'hashAlg' MUST be NUMBER", NULL); if (!(check_param_empty(v8Params, STR_SOURCE_DATA) || check_param_buffer(v8Params, STR_SOURCE_DATA))) THROW_ERROR("Attribute 'iv' MUST be NULL || BUFFER", NULL); Free(); Init(); param.source = Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_SOURCE).ToLocalChecked())).ToLocalChecked()->Uint32Value(); param.mgf= Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_MGF).ToLocalChecked())).ToLocalChecked()->Uint32Value(); param.hashAlg = Nan::To<v8::Number>(v8Params->Get(Nan::New(STR_HASH_ALG).ToLocalChecked())).ToLocalChecked()->Uint32Value(); if (!check_param_empty(v8Params, STR_SOURCE_DATA)) { GET_BUFFER_SMPL(buffer, v8Params->Get(Nan::New(STR_SOURCE_DATA).ToLocalChecked())->ToObject()); param.pSourceData = (CK_BYTE_PTR)malloc(bufferLen * sizeof(CK_BYTE)); memcpy(param.pSourceData, buffer, bufferLen); param.ulSourceDataLen = (CK_ULONG)bufferLen; } } CATCH_ERROR; }