本文整理汇总了C++中v8::Handle::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::Length方法的具体用法?C++ Handle::Length怎么用?C++ Handle::Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v8::Handle
的用法示例。
在下文中一共展示了Handle::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uint16StrToStr
String uint16StrToStr(v8::Handle<v8::String> toDeserialize)
{
uint16* toReadArray = new uint16[toDeserialize->Length()];
char* binArray = new char[toDeserialize->Length()];
toDeserialize->Write(toReadArray,0, toDeserialize->Length());
for (int s=0; s < toDeserialize->Length(); ++s)
binArray[s] = (char)(toReadArray[s]);
String returner (binArray, toDeserialize->Length());
delete[] toReadArray;
delete[] binArray;
return returner;
}
示例2: jsArrayToJavaArray
jarray TypeConverter::jsArrayToJavaArray(v8::Handle<v8::Array> jsArray)
{
JNIEnv *env = JNIScope::getEnv();
if (env == NULL) {
return NULL;
}
int arrayLength = jsArray->Length();
jobjectArray javaArray = env->NewObjectArray(arrayLength, JNIUtil::objectClass, NULL);
if (javaArray == NULL) {
LOGE(TAG, "unable to create new jobjectArray");
return NULL;
}
for (int i = 0; i < arrayLength; i++) {
v8::Local<v8::Value> element = jsArray->Get(i);
bool isNew;
jobject javaObject = jsValueToJavaObject(element, &isNew);
env->SetObjectArrayElement(javaArray, i, javaObject);
if (isNew) {
env->DeleteLocalRef(javaObject);
}
}
return javaArray;
}
示例3: ASSERT
static String fromV8String(v8::Handle<v8::String> v8String, int length)
{
ASSERT(v8String->Length() == length);
// NOTE: as of now, String(const UChar*, int) performs String::createUninitialized
// anyway, so no need to optimize like we do for AtomicString below.
UChar* buffer;
String result = String::createUninitialized(length, buffer);
v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length);
return result;
}
示例4: Value
static Value v8ValueToValue(v8::Handle<v8::Value> v8Value)
{
v8::HandleScope scope;
if (v8Value->IsArray()) {
List<Value> value;
const v8::Handle<v8::Array> v8Array = v8::Handle<v8::Array>::Cast(v8Value);
const uint32_t size = v8Array->Length();
for (uint32_t i = 0; i < size; ++i) {
if (v8Array->Has(i))
value.append(v8ValueToValue(v8Array->Get(i)));
else
value.append(Value());
}
return Value(value);
} else if (v8Value->IsObject()) {
Map<String, Value> value;
const v8::Handle<v8::Object> v8Object = v8Value->ToObject();
const v8::Handle<v8::Array> props = v8Object->GetPropertyNames();
const uint32_t size = props->Length();
for (uint32_t i = 0; i < size; ++i) {
assert(props->Has(i));
const v8::Handle<v8::Value> name = props->Get(i);
value[String(*v8::String::Utf8Value(name))] = v8ValueToValue(v8Object->Get(name));
}
return Value(value);
} else if (v8Value->IsBoolean()) {
return Value(v8Value->BooleanValue());
} else if (v8Value->IsInt32() || v8Value->IsUint32()) {
return Value(v8Value->Int32Value());
} else if (v8Value->IsNumber()) {
return Value(v8Value->NumberValue());
} else if (v8Value->IsString()) {
return Value(String(*v8::String::Utf8Value(v8Value)));
} else {
error() << "Unexpected v8 value type in JSONParser";
}
// undefined or null?
return Value();
}
示例5: AtomicString
static AtomicString fromV8String(v8::Handle<v8::String> v8String, int length)
{
ASSERT(v8String->Length() == length);
static const int inlineBufferSize = 16;
if (length <= inlineBufferSize) {
UChar inlineBuffer[inlineBufferSize];
v8String->Write(reinterpret_cast<uint16_t*>(inlineBuffer), 0, length);
return AtomicString(inlineBuffer, length);
}
UChar* buffer;
String tmp = String::createUninitialized(length, buffer);
v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length);
return AtomicString(tmp);
}
示例6: GetStringIdentifier
// Helper function to create an NPN String Identifier from a v8 string.
NPIdentifier GetStringIdentifier(v8::Handle<v8::String> str) {
const int kStackBufSize = 100;
int buf_len = str->Length() + 1;
if (buf_len <= kStackBufSize) {
// Use local stack buffer to avoid heap allocations for small strings.
// Here we should only use the stack space for stack_buf when it's used,
// not when we use the heap.
char stack_buf[kStackBufSize];
str->WriteAscii(stack_buf);
return NPN_GetStringIdentifier(stack_buf);
}
scoped_array<char> heap_buf(new char[buf_len]);
str->WriteAscii(heap_buf.get());
return NPN_GetStringIdentifier(heap_buf.get());
}
示例7: jsArrayToJavaDoubleArray
jdoubleArray TypeConverter::jsArrayToJavaDoubleArray(JNIEnv *env, v8::Handle<v8::Array> jsArray)
{
int arrayLength = jsArray->Length();
jdoubleArray javaDoubleArray = env->NewDoubleArray(arrayLength);
if (javaDoubleArray == NULL) {
LOGE(TAG, "unable to create new jdoubleArray");
return NULL;
}
jdouble* doubleBuffer = new jdouble[arrayLength];
for (int i = 0; i < arrayLength; i++) {
v8::Local<v8::Value> element = jsArray->Get(i);
doubleBuffer[i] = TypeConverter::jsNumberToJavaDouble(element->ToNumber());
}
env->SetDoubleArrayRegion(javaDoubleArray, 0, arrayLength, doubleBuffer);
return javaDoubleArray;
}
示例8: origin
v8::Local<v8::Script> V8ScriptRunner::compileScript(v8::Handle<v8::String> code, const String& fileName, const TextPosition& scriptStartPosition, ScriptResource* resource, v8::Isolate* isolate, AccessControlStatus corsStatus)
{
// A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from
// the ScriptResource. If the format changes, this ID should be changed too.
static const unsigned dataTypeID = 0xECC13BD7;
// Very small scripts are not worth the effort to store cached data.
static const int minLengthForCachedData = 1024;
TRACE_EVENT0("v8", "v8.compile");
TRACE_EVENT_SCOPED_SAMPLING_STATE("V8", "V8Compile");
// NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
// 1, whereas v8 starts at 0.
v8::Handle<v8::String> name = v8String(isolate, fileName);
v8::Handle<v8::Integer> line = v8::Integer::New(isolate, scriptStartPosition.m_line.zeroBasedInt());
v8::Handle<v8::Integer> column = v8::Integer::New(isolate, scriptStartPosition.m_column.zeroBasedInt());
v8::Handle<v8::Boolean> isSharedCrossOrigin = corsStatus == SharableCrossOrigin ? v8::True(isolate) : v8::False(isolate);
v8::ScriptOrigin origin(name, line, column, isSharedCrossOrigin);
v8::ScriptCompiler::CompileOptions options = v8::ScriptCompiler::kNoCompileOptions;
OwnPtr<v8::ScriptCompiler::CachedData> cachedData;
if (resource) {
CachedMetadata* cachedMetadata = resource->cachedMetadata(dataTypeID);
if (cachedMetadata) {
// Ownership of the buffer is not transferred to CachedData.
cachedData = adoptPtr(new v8::ScriptCompiler::CachedData(reinterpret_cast<const uint8_t*>(cachedMetadata->data()), cachedMetadata->size()));
} else if (code->Length() >= minLengthForCachedData) {
options = v8::ScriptCompiler::kProduceDataToCache;
}
}
// source takes ownership of cachedData.
v8::ScriptCompiler::Source source(code, origin, cachedData.leakPtr());
v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(isolate, &source, options);
if (options == v8::ScriptCompiler::kProduceDataToCache) {
const v8::ScriptCompiler::CachedData* newCachedData = source.GetCachedData();
if (newCachedData) {
// Ownership of the buffer is not transferred; source's cachedData continues to own it.
resource->setCachedMetadata(dataTypeID, reinterpret_cast<const char*>(newCachedData->data), newCachedData->length);
}
}
return script;
}
示例9: jsArrayToJavaStringArray
jobjectArray TypeConverter::jsArrayToJavaStringArray(JNIEnv *env, v8::Handle<v8::Array> jsArray)
{
int arrayLength = jsArray->Length();
jobjectArray javaArray = env->NewObjectArray(arrayLength, JNIUtil::stringClass, NULL);
if (javaArray == NULL) {
LOGE(TAG, "unable to create new jobjectArray");
return NULL;
}
for (int i = 0; i < arrayLength; i++) {
v8::Local<v8::Value> element = jsArray->Get(i);
jstring javaObject = jsStringToJavaString(env, element->ToString());
env->SetObjectArrayElement(javaArray, i, javaObject);
env->DeleteLocalRef(javaObject);
}
return javaArray;
}
示例10:
std::vector<BaseIndicator *> IndicatorFactory::CreateFromArray(v8::Handle<v8::Array> array)
{
unsigned indicatorCount = array->Length();
std::vector<std::string> indicatorNames;
for (unsigned i = 0; i < indicatorCount; i++)
{
indicatorNames.push_back(std::string(*v8::String::Utf8Value(array->Get(i)->ToString())));
}
std::vector<BaseIndicator *> indicators;
for (unsigned long i = 0; i < indicatorNames.size(); i++)
{
BaseIndicator* indicator = IndicatorFactory::Create(indicatorNames[i]);
indicators.push_back(indicator);
}
return indicators;
}
示例11: v8StringToWebCoreString
StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external)
{
WebCoreStringResource* stringResource = WebCoreStringResource::toStringResource(v8String);
if (stringResource)
return StringTraits<StringType>::fromStringResource(stringResource);
int length = v8String->Length();
if (!length)
return String("");
StringType result(StringTraits<StringType>::fromV8String(v8String, length));
if (external == Externalize && v8String->CanMakeExternal()) {
stringResource = new WebCoreStringResource(result);
if (!v8String->MakeExternal(stringResource)) {
// In case of a failure delete the external resource as it was not used.
delete stringResource;
}
}
return result;
}
示例12: scriptData
PassOwnPtr<v8::ScriptData> V8Proxy::precompileScript(v8::Handle<v8::String> code, CachedScript* cachedScript)
{
// A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from
// the CachedScript. If the format changes, this ID should be changed too.
static const unsigned dataTypeID = 0xECC13BD7;
// Very small scripts are not worth the effort to preparse.
static const int minPreparseLength = 1024;
if (!cachedScript || code->Length() < minPreparseLength)
return 0;
CachedMetadata* cachedMetadata = cachedScript->cachedMetadata(dataTypeID);
if (cachedMetadata)
return v8::ScriptData::New(cachedMetadata->data(), cachedMetadata->size());
OwnPtr<v8::ScriptData> scriptData(v8::ScriptData::PreCompile(code));
cachedScript->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Length());
return scriptData.release();
}
示例13: jsArrayToJavaIntArray
jintArray TypeConverter::jsArrayToJavaIntArray(v8::Handle<v8::Array> jsArray)
{
JNIEnv *env = JNIScope::getEnv();
if (env == NULL) {
return NULL;
}
int arrayLength = jsArray->Length();
jintArray javaIntArray = env->NewIntArray(arrayLength);
if (javaIntArray == NULL) {
LOGE(TAG, "unable to create new jintArray");
return NULL;
}
jint* intBuffer = new jint[arrayLength];
for (int i = 0; i < arrayLength; i++) {
v8::Local<v8::Value> element = jsArray->Get(i);
intBuffer[i] = TypeConverter::jsNumberToJavaInt(element->ToNumber());
}
env->SetIntArrayRegion(javaIntArray, 0, arrayLength, intBuffer);
return javaIntArray;
}
示例14: v8StringToWebCoreString
StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external)
{
WebCoreStringResource* stringResource = WebCoreStringResource::toStringResource(v8String);
if (stringResource)
return StringTraits<StringType>::fromStringResource(stringResource);
int length = v8String->Length();
if (!length) {
// Avoid trying to morph empty strings, as they do not have enough room to contain the external reference.
return StringImpl::empty();
}
StringType result(StringTraits<StringType>::fromV8String(v8String, length));
if (external == Externalize && v8String->CanMakeExternal()) {
stringResource = new WebCoreStringResource(result);
if (!v8String->MakeExternal(stringResource)) {
// In case of a failure delete the external resource as it was not used.
delete stringResource;
}
}
return result;
}
示例15: v8StringToWebCoreString
StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external)
{
{
// This portion of this function is very hot in certain Dromeao benchmarks.
v8::String::Encoding encoding;
v8::String::ExternalStringResourceBase* resource = v8String->GetExternalStringResourceBase(&encoding);
if (LIKELY(!!resource)) {
WebCoreStringResourceBase* base;
if (encoding == v8::String::ONE_BYTE_ENCODING)
base = static_cast<WebCoreStringResource8*>(resource);
else
base = static_cast<WebCoreStringResource16*>(resource);
return StringTraits<StringType>::fromStringResource(base);
}
}
int length = v8String->Length();
if (UNLIKELY(!length))
return StringType("");
bool oneByte = v8String->ContainsOnlyOneByte();
StringType result(oneByte ? StringTraits<StringType>::template fromV8String<V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fromV8String<V8StringTwoBytesTrait>(v8String, length));
if (external != Externalize || !v8String->CanMakeExternal())
return result;
if (result.is8Bit()) {
WebCoreStringResource8* stringResource = new WebCoreStringResource8(result);
if (UNLIKELY(!v8String->MakeExternal(stringResource)))
delete stringResource;
} else {
WebCoreStringResource16* stringResource = new WebCoreStringResource16(result);
if (UNLIKELY(!v8String->MakeExternal(stringResource)))
delete stringResource;
}
return result;
}