本文整理汇总了C++中v8::Handle::IsStringObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::IsStringObject方法的具体用法?C++ Handle::IsStringObject怎么用?C++ Handle::IsStringObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v8::Handle
的用法示例。
在下文中一共展示了Handle::IsStringObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TRI_ObjectToCharacter
char TRI_ObjectToCharacter (v8::Handle<v8::Value> value, bool& error) {
error = false;
if (! value->IsString() && ! value->IsStringObject()) {
error = true;
return '\0';
}
TRI_Utf8ValueNFC sep(TRI_UNKNOWN_MEM_ZONE, value->ToString());
if (*sep == 0 || sep.length() != 1) {
error = true;
return '\0';
}
return (*sep)[0];
}
示例2: isLegacyTargetOriginDesignation
static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value)
{
if (value->IsString() || value->IsStringObject())
return true;
return false;
}
示例3: AddValue
static int V8ToVPack(BuilderContext& context,
v8::Handle<v8::Value> const parameter,
std::string const& attributeName, bool inObject) {
if (parameter->IsNull() || parameter->IsUndefined()) {
AddValue(context, attributeName, inObject,
VPackValue(VPackValueType::Null));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsBoolean()) {
AddValue(context, attributeName, inObject,
VPackValue(parameter->ToBoolean()->Value()));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsNumber()) {
if (parameter->IsInt32()) {
AddValue(context, attributeName, inObject,
VPackValue(parameter->ToInt32()->Value()));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsUint32()) {
AddValue(context, attributeName, inObject,
VPackValue(parameter->ToUint32()->Value()));
return TRI_ERROR_NO_ERROR;
}
AddValue(context, attributeName, inObject,
VPackValue(parameter->ToNumber()->Value()));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsString()) {
v8::String::Utf8Value str(parameter->ToString());
if (*str == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
AddValuePair(context, attributeName, inObject, VPackValuePair(*str, str.length(), VPackValueType::String));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsArray()) {
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(parameter);
AddValue(context, attributeName, inObject,
VPackValue(VPackValueType::Array));
uint32_t const n = array->Length();
for (uint32_t i = 0; i < n; ++i) {
v8::Handle<v8::Value> value = array->Get(i);
if (value->IsUndefined()) {
// ignore array values which are undefined
continue;
}
if (++context.level > MaxLevels) {
// too much recursion
return TRI_ERROR_BAD_PARAMETER;
}
int res = V8ToVPack<performAllChecks>(context, value, NoAttribute, false);
--context.level;
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
}
if (!context.keepTopLevelOpen || context.level > 0) {
context.builder.close();
}
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsObject()) {
if (performAllChecks) {
if (parameter->IsBooleanObject()) {
AddValue(context, attributeName, inObject,
VPackValue(v8::Handle<v8::BooleanObject>::Cast(parameter)
->BooleanValue()));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsNumberObject()) {
AddValue(context, attributeName, inObject,
VPackValue(v8::Handle<v8::NumberObject>::Cast(parameter)
->NumberValue()));
return TRI_ERROR_NO_ERROR;
}
if (parameter->IsStringObject()) {
v8::String::Utf8Value str(parameter->ToString());
if (*str == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
//.........这里部分代码省略.........
示例4: FillShapeValueJson
static int FillShapeValueJson (v8::Isolate* isolate,
VocShaper* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Value> const json,
size_t level,
set<int>& seenHashes,
vector<v8::Handle<v8::Object>>& seenObjects,
bool create) {
v8::HandleScope scope(isolate);
if (json->IsRegExp() || json->IsFunction() || json->IsExternal()) {
LOG_TRACE("shaper failed because regexp/function/external/date object cannot be converted");
return TRI_ERROR_BAD_PARAMETER;
}
if (json->IsNull() || json->IsUndefined()) {
return FillShapeValueNull(shaper, dst);
}
if (json->IsBoolean()) {
return FillShapeValueBoolean(shaper, dst, json->ToBoolean());
}
if (json->IsBooleanObject()) {
return FillShapeValueBoolean(shaper, dst, v8::Handle<v8::BooleanObject>::Cast(json));
}
if (json->IsNumber()) {
return FillShapeValueNumber(shaper, dst, json->ToNumber());
}
if (json->IsNumberObject()) {
return FillShapeValueNumber(shaper, dst, v8::Handle<v8::NumberObject>::Cast(json));
}
if (json->IsString()) {
return FillShapeValueString(shaper, dst, json->ToString());
}
if (json->IsStringObject()) {
return FillShapeValueString(shaper, dst, v8::Handle<v8::StringObject>::Cast(json)->ValueOf());
}
else if (json->IsArray()) {
return FillShapeValueList(isolate, shaper, dst, v8::Handle<v8::Array>::Cast(json), level, seenHashes, seenObjects, create);
}
if (json->IsObject()) {
v8::Handle<v8::Object> o = json->ToObject();
v8::Handle<v8::String> toJsonString = TRI_V8_PAIR_STRING("toJSON", 6);
if (o->Has(toJsonString)) {
v8::Handle<v8::Value> func = o->Get(toJsonString);
if (func->IsFunction()) {
v8::Handle<v8::Function> toJson = v8::Handle<v8::Function>::Cast(func);
v8::Handle<v8::Value> args;
v8::Handle<v8::Value> result = toJson->Call(o, 0, &args);
if (! result.IsEmpty()) {
return FillShapeValueString(shaper, dst, result->ToString());
}
}
}
// fall-through intentional
// check for cycles
int hash = o->GetIdentityHash();
if (seenHashes.find(hash) != seenHashes.end()) {
for (auto it = seenObjects.begin(); it != seenObjects.end(); ++it) {
if (json->StrictEquals(*it)) {
return TRI_ERROR_ARANGO_SHAPER_FAILED;
}
}
}
else {
seenHashes.insert(hash);
}
seenObjects.push_back(o);
int res = FillShapeValueArray(isolate, shaper, dst, json->ToObject(), level, seenHashes, seenObjects, create);
seenObjects.pop_back();
// cannot remove hash value from seenHashes because multiple objects might have the same
// hash values (collisions)
return res;
}
LOG_TRACE("shaper failed to convert object");
return TRI_ERROR_BAD_PARAMETER;
}
示例5: value
/**
* Cast an ecmascript value to a PHP runtime value
*
* @note The value cannot be const, as retrieving properties
* from arrays and objects cannot be done on const values
*
* @param input the value to cast
* @return Php::Value
*/
Php::Value value(v8::Handle<v8::Value> input)
{
// if we received an invalid input we simply return an empty PHP value
if (input.IsEmpty()) return nullptr;
// as is typical in javascript, a value can be of many types
// check the type of value that we have received so we can cast
if (input->IsBoolean()) return input->BooleanValue();
if (input->IsBooleanObject()) return input->BooleanValue();
if (input->IsInt32()) return input->Int32Value();
if (input->IsNumber()) return input->NumberValue();
if (input->IsNumberObject()) return input->NumberValue();
if (input->IsNull()) return nullptr;
if (input->IsUndefined()) return nullptr;
// special treatment for string-like types
// TODO: javascript dates might possibly be cast to a DateTime object
if (input->IsString() || input->IsStringObject() || input->IsRegExp())
{
// create the utf8 value (the only way to retrieve the content)
v8::String::Utf8Value utf8(input->ToString());
// and create the value to return
return {*utf8, utf8.length()};
}
// it could be callable too
if (input->IsFunction())
{
// create the function as a pointer that can be captured
auto function = std::make_shared<Stack<v8::Function>>(input.As<v8::Function>());
// the result to return
Php::Function result([function](Php::Parameters ¶ms) {
// create a "scope", so variables get destructed, retrieve the context and "enter" it
v8::HandleScope scope(Isolate::get());
v8::Local<v8::Context> context((*function)->CreationContext());
v8::Context::Scope contextScope(context);
// catch any errors that occur while either compiling or running the script
v8::TryCatch catcher;
// create a new array with parameters
std::vector<v8::Local<v8::Value>> array;
array.reserve(params.size());
// iterate over all the given parameters and add them to the arrau
for (auto ¶m: params) array.push_back(value(param));
// now we can actually call the function
v8::Local<v8::Value> result((*function)->Call(context->Global(), array.size(), array.data()));
// did we catch an exception?
if (catcher.HasCaught())
{
// retrieve the message describing the problem
v8::Local<v8::Message> message(catcher.Message());
v8::Local<v8::String> description(message->Get());
// convert the description to utf so we can dump it
v8::String::Utf8Value string(description);
// pass this exception on to PHP userspace
throw Php::Exception(std::string(*string, string.length()));
}
// convert the result to a PHP value and return it
return value(result);
});
// now return the result
return result;
}
// or perhaps an object
if (input->IsObject())
{
// retrieve the object and the first internal field
auto object = input.As<v8::Object>();
// does the object have internal fields?
if (object->InternalFieldCount())
{
// retrieve the field
auto field = object->GetInternalField(0);
// does it have an internal field and is it external? we are converting back
// an original PHP object, just retrieve the original thing that came from PHP
if (!field.IsEmpty() && field->IsExternal())
{
// the PHP value is stored in the first internal field,
//.........这里部分代码省略.........
示例6: FillShapeValueJson
static bool FillShapeValueJson (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Value> json,
set<int>& seenHashes,
vector< v8::Handle<v8::Object> >& seenObjects) {
if (json->IsObject()) {
v8::Handle<v8::Object> o = json->ToObject();
int hash = o->GetIdentityHash();
if (seenHashes.find(hash) != seenHashes.end()) {
LOG_TRACE("found hash %d", hash);
for (vector< v8::Handle<v8::Object> >::iterator i = seenObjects.begin(); i != seenObjects.end(); ++i) {
if (json->StrictEquals(*i)) {
LOG_TRACE("found duplicate for hash %d", hash);
return FillShapeValueNull(shaper, dst);
}
}
seenObjects.push_back(o);
}
else {
seenHashes.insert(hash);
seenObjects.push_back(o);
}
}
if (json->IsNull()) {
return FillShapeValueNull(shaper, dst);
}
if (json->IsBoolean()) {
return FillShapeValueBoolean(shaper, dst, json->ToBoolean());
}
if (json->IsBooleanObject()) {
v8::Handle<v8::BooleanObject> bo = v8::Handle<v8::BooleanObject>::Cast(json);
return FillShapeValueBoolean(shaper, dst, bo);
}
if (json->IsNumber()) {
return FillShapeValueNumber(shaper, dst, json->ToNumber());
}
if (json->IsNumberObject()) {
v8::Handle<v8::NumberObject> no = v8::Handle<v8::NumberObject>::Cast(json);
return FillShapeValueNumber(shaper, dst, no);
}
if (json->IsString()) {
return FillShapeValueString(shaper, dst, json->ToString());
}
if (json->IsStringObject()) {
v8::Handle<v8::StringObject> so = v8::Handle<v8::StringObject>::Cast(json);
return FillShapeValueString(shaper, dst, so->StringValue());
}
if (json->IsArray()) {
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(json);
return FillShapeValueList(shaper, dst, array, seenHashes, seenObjects);
}
if (json->IsObject()) {
return FillShapeValueArray(shaper, dst, json->ToObject(), seenHashes, seenObjects);
}
return false;
}