本文整理汇总了C++中JavascriptString类的典型用法代码示例。如果您正苦于以下问题:C++ JavascriptString类的具体用法?C++ JavascriptString怎么用?C++ JavascriptString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JavascriptString类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetScriptContext
PropertyQueryFlags JavascriptStringObject::GetPropertyQuery(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext)
{
BOOL result;
if (GetPropertyBuiltIns(propertyId, value, requestContext, &result))
{
return JavascriptConversion::BooleanToPropertyQueryFlags(result);
}
if (JavascriptConversion::PropertyQueryFlagsToBoolean(DynamicObject::GetPropertyQuery(originalInstance, propertyId, value, info, requestContext)))
{
return PropertyQueryFlags::Property_Found;
}
// For NumericPropertyIds check that index is less than JavascriptString length
ScriptContext*scriptContext = GetScriptContext();
uint32 index;
if (scriptContext->IsNumericPropertyId(propertyId, &index))
{
JavascriptString* str = this->InternalUnwrap();
str = JavascriptString::FromVar(CrossSite::MarshalVar(requestContext, str, scriptContext));
return JavascriptConversion::BooleanToPropertyQueryFlags(str->GetItemAt(index, value));
}
*value = requestContext->GetMissingPropertyResult();
return PropertyQueryFlags::Property_NotFound;
}
示例2: GetScriptContext
BOOL JavascriptStringObject::GetProperty(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext)
{
BOOL result;
if (GetPropertyBuiltIns(propertyId, value, requestContext, &result))
{
return result;
}
if (DynamicObject::GetProperty(originalInstance, propertyId, value, info, requestContext))
{
return true;
}
// For NumericPropertyIds check that index is less than JavascriptString length
ScriptContext*scriptContext = GetScriptContext();
uint32 index;
if (scriptContext->IsNumericPropertyId(propertyId, &index))
{
JavascriptString* str = JavascriptString::FromVar(CrossSite::MarshalVar(requestContext, this->InternalUnwrap()));
return str->GetItemAt(index, value);
}
*value = requestContext->GetMissingPropertyResult();
return false;
}
示例3: EngineInterfaceObject_CommonFunctionProlog
Var EngineInterfaceObject::Entry_TagPublicLibraryCode(RecyclableObject *function, CallInfo callInfo, ...)
{
EngineInterfaceObject_CommonFunctionProlog(function, callInfo);
if (callInfo.Count >= 2 && JavascriptFunction::Is(args.Values[1]))
{
JavascriptFunction* func = JavascriptFunction::FromVar(args.Values[1]);
func->GetFunctionProxy()->SetIsPublicLibraryCode();
if (callInfo.Count >= 3 && JavascriptString::Is(args.Values[2]))
{
JavascriptString* customFunctionName = JavascriptString::FromVar(args.Values[2]);
// tagPublicFunction("Intl.Collator", Collator); in Intl.js calls TagPublicLibraryCode the expected name is Collator so we need to calculate the offset
const wchar_t * shortName = wcsrchr(customFunctionName->GetString(), L'.');
uint shortNameOffset = 0;
if (shortName != nullptr)
{
// JavascriptString length is bounded by uint max
shortName++;
shortNameOffset = static_cast<uint>(shortName - customFunctionName->GetString());
}
func->GetFunctionProxy()->EnsureDeserialized()->SetDisplayName(customFunctionName->GetString(), customFunctionName->GetLength(), shortNameOffset);
}
return func;
}
return scriptContext->GetLibrary()->GetUndefined();
}
示例4: EngineInterfaceObject_CommonFunctionProlog
Var JsBuiltInEngineInterfaceExtensionObject::EntryJsBuiltIn_RegisterChakraLibraryFunction(RecyclableObject* function, CallInfo callInfo, ...)
{
EngineInterfaceObject_CommonFunctionProlog(function, callInfo);
AssertOrFailFast(args.Info.Count >= 3 && JavascriptString::Is(args.Values[1]) && JavascriptFunction::Is(args.Values[2]));
JavascriptLibrary * library = scriptContext->GetLibrary();
// retrieves arguments
JavascriptString* methodName = JavascriptString::FromVar(args.Values[1]);
JavascriptFunction* func = JavascriptFunction::FromVar(args.Values[2]);
// Set the function's display name, as the function we pass in argument are anonym.
func->GetFunctionProxy()->SetIsPublicLibraryCode();
func->GetFunctionProxy()->EnsureDeserialized()->SetDisplayName(methodName->GetString(), methodName->GetLength(), 0);
DynamicObject* chakraLibraryObject = GetPrototypeFromName(PropertyIds::__chakraLibrary, scriptContext);
PropertyIds functionIdentifier = JavascriptOperators::GetPropertyId(methodName, scriptContext);
// Link the function to __chakraLibrary.
ScriptFunction* scriptFunction = library->CreateScriptFunction(func->GetFunctionProxy());
scriptFunction->GetFunctionProxy()->SetIsJsBuiltInCode();
Assert(scriptFunction->HasFunctionBody());
scriptFunction->GetFunctionBody()->SetJsBuiltInForceInline();
scriptFunction->SetPropertyWithAttributes(PropertyIds::name, methodName, PropertyConfigurable, nullptr);
library->AddMember(chakraLibraryObject, functionIdentifier, scriptFunction);
//Don't need to return anything
return library->GetUndefined();
}
示例5: GetItem
BOOL JavascriptStringObject::GetItem(Var originalInstance, uint32 index, Var* value, ScriptContext* requestContext)
{
JavascriptString* str = JavascriptString::FromVar(CrossSite::MarshalVar(requestContext, this->InternalUnwrap()));
if (str->GetItemAt(index, value))
{
return true;
}
return DynamicObject::GetItem(originalInstance, index, value, requestContext);
}
示例6: PROBE_STACK
Var JavascriptStringIterator::EntryNext(RecyclableObject* function, CallInfo callInfo, ...)
{
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
ARGUMENTS(args, callInfo);
ScriptContext* scriptContext = function->GetScriptContext();
JavascriptLibrary* library = scriptContext->GetLibrary();
Assert(!(callInfo.Flags & CallFlags_New));
Var thisObj = args[0];
if (!JavascriptStringIterator::Is(thisObj))
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_This_NeedStringIterator, L"String Iterator.prototype.next");
}
JavascriptStringIterator* iterator = JavascriptStringIterator::FromVar(thisObj);
JavascriptString* string = iterator->m_string;
if (string == nullptr)
{
return library->CreateIteratorResultObjectUndefinedTrue();
}
charcount_t length = string->GetLength();
charcount_t index = iterator->m_nextIndex;
if (index >= length)
{
// Nulling out the m_string field is important so that the iterator
// does not keep the string alive after iteration is completed.
iterator->m_string = nullptr;
return library->CreateIteratorResultObjectUndefinedTrue();
}
wchar_t chFirst = string->GetItem(index);
Var result;
if (index + 1 == string->GetLength() ||
!NumberUtilities::IsSurrogateLowerPart(chFirst) ||
!NumberUtilities::IsSurrogateUpperPart(string->GetItem(index + 1)))
{
result = scriptContext->GetLibrary()->GetCharStringCache().GetStringForChar(chFirst);
iterator->m_nextIndex += 1;
}
else
{
result = JavascriptString::SubstringCore(string, index, 2, scriptContext);
iterator->m_nextIndex += 2;
}
return library->CreateIteratorResultObjectValueFalse(result);
}
示例7: GetItemQuery
PropertyQueryFlags JavascriptStringObject::GetItemQuery(Var originalInstance, uint32 index, Var* value, ScriptContext* requestContext)
{
Var strObject = CrossSite::MarshalVar(requestContext,
this->InternalUnwrap(), this->GetScriptContext());
JavascriptString* str = JavascriptString::FromVar(strObject);
if (str->GetItemAt(index, value))
{
return PropertyQueryFlags::Property_Found;
}
return DynamicObject::GetItemQuery(originalInstance, index, value, requestContext);
}
示例8: ConvertStringToInt64
int64 ConvertStringToInt64(Var string, ScriptContext* scriptContext)
{
JavascriptString* str = JavascriptString::FromVar(string);
charcount_t length = str->GetLength();
const char16* buf = str->GetString();
int radix = 10;
if (length >= 2 && buf[0] == '0' && buf[1] == 'x')
{
radix = 16;
}
return (int64)_wcstoui64(buf, nullptr, radix);
}
示例9: Assert
HRESULT JavascriptError::GetRuntimeError(RecyclableObject* errorObject, __out_opt LPCWSTR * pMessage)
{
// Only report the error number if it is a runtime error
HRESULT hr = JSERR_UncaughtException;
ScriptContext* scriptContext = errorObject->GetScriptContext();
// This version needs to be called in script.
Assert(scriptContext->GetThreadContext()->IsScriptActive());
Var number = JavascriptOperators::GetProperty(errorObject, Js::PropertyIds::number, scriptContext, NULL);
if (TaggedInt::Is(number))
{
hr = TaggedInt::ToInt32(number);
}
else if (JavascriptNumber::Is_NoTaggedIntCheck(number))
{
hr = (HRESULT)JavascriptNumber::GetValue(number);
}
if (!FAILED(hr))
{
hr = E_FAIL;
}
if (pMessage != NULL)
{
*pMessage = _u(""); // default to have IE load the error message, by returning empty-string
// The description property always overrides any error message
Var description = Js::JavascriptOperators::GetProperty(errorObject, Js::PropertyIds::description, scriptContext, NULL);
if (JavascriptString::Is(description))
{
// Always report the description to IE if it is a string, even if the user sets it
JavascriptString * messageString = JavascriptString::FromVar(description);
*pMessage = messageString->GetSz();
}
else if (Js::JavascriptError::Is(errorObject) && Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage != nullptr)
{
// use the runtime error message
*pMessage = Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage;
}
else if (FACILITY_CONTROL == HRESULT_FACILITY(hr))
{
// User might have create it's own Error object with JS error code, try to load the
// resource string from the HResult by returning null;
*pMessage = nullptr;
}
}
// If neither the description or original runtime error message is set, and there are no error message.
// Then just return false and we will report Uncaught exception to IE.
return hr;
}
示例10: GetLibrary
BOOL JavascriptBoolean::GetDiagValueString(StringBuilder<ArenaAllocator>* stringBuilder, ScriptContext* requestContext)
{
if (this->GetValue())
{
JavascriptString* trueDisplayString = GetLibrary()->GetTrueDisplayString();
stringBuilder->Append(trueDisplayString->GetString(), trueDisplayString->GetLength());
}
else
{
JavascriptString* falseDisplayString = GetLibrary()->GetFalseDisplayString();
stringBuilder->Append(falseDisplayString->GetString(), falseDisplayString->GetLength());
}
return TRUE;
}
示例11: PROBE_STACK
// Symbol.for as described in ES 2015
Var JavascriptSymbol::EntryFor(RecyclableObject* function, CallInfo callInfo, ...)
{
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
ARGUMENTS(args, callInfo);
AssertMsg(args.Info.Count, "Should always have implicit 'this'.");
ScriptContext* scriptContext = function->GetScriptContext();
JavascriptLibrary* library = scriptContext->GetLibrary();
Assert(!(callInfo.Flags & CallFlags_New));
JavascriptString* key;
if (args.Info.Count > 1)
{
key = JavascriptConversion::ToString(args[1], scriptContext);
}
else
{
key = library->GetUndefinedDisplayString();
}
// Search the global symbol registration map for a symbol with description equal to the string key.
// The map can only have one symbol with that description so if we found a symbol, that is the registered
// symbol for the string key.
const Js::PropertyRecord* propertyRecord = scriptContext->GetThreadContext()->GetSymbolFromRegistrationMap(key->GetString(), key->GetLength());
// If we didn't find a PropertyRecord in the map, we'll create a new symbol with description equal to the key string.
// This is the only place we add new PropertyRecords to the map, so we should never have multiple PropertyRecords in the
// map with the same string key value (since we would return the one we found above instead of creating a new one).
if (propertyRecord == nullptr)
{
propertyRecord = scriptContext->GetThreadContext()->AddSymbolToRegistrationMap(key->GetString(), key->GetLength());
}
Assert(propertyRecord != nullptr);
return library->CreateSymbol(propertyRecord);
}
示例12: while
Var ForInObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId)
{
JavascriptEnumerator *pEnumerator = currentEnumerator;
PropertyRecord const * propRecord;
PropertyAttributes attributes = PropertyNone;
while (true)
{
propertyId = Constants::NoProperty;
currentIndex = pEnumerator->GetCurrentAndMoveNext(propertyId, &attributes);
#if ENABLE_COPYONACCESS_ARRAY
JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(currentIndex);
#endif
if (currentIndex)
{
if (firstPrototype == nullptr)
{
// We are calculating correct shadowing for non-enumerable properties of the child object, we will receive
// both enumerable and non-enumerable properties from GetCurrentAndMoveNext so we need to check before we simply
// return here. If this property is non-enumerable we're going to skip it.
if (!(attributes & PropertyEnumerable))
{
continue;
}
// There are no prototype that has enumerable properties,
// don't need to keep track of the propertyIds we visited.
return currentIndex;
}
// Property Id does not exist.
if (propertyId == Constants::NoProperty)
{
if (!JavascriptString::Is(currentIndex)) //This can be undefined
{
continue;
}
JavascriptString *pString = JavascriptString::FromVar(currentIndex);
if (VirtualTableInfo<Js::PropertyString>::HasVirtualTable(pString))
{
// If we have a property string, it is assumed that the propertyId is being
// kept alive with the object
PropertyString * propertyString = (PropertyString *)pString;
propertyId = propertyString->GetPropertyRecord()->GetPropertyId();
}
else
{
ScriptContext* scriptContext = pString->GetScriptContext();
scriptContext->GetOrAddPropertyRecord(pString->GetString(), pString->GetLength(), &propRecord);
propertyId = propRecord->GetPropertyId();
// We keep the track of what is enumerated using a bit vector of propertyID.
// so the propertyId can't be collected until the end of the for in enumerator
// Keep a list of the property string.
newPropertyStrings.Prepend(GetScriptContext()->GetRecycler(), propRecord);
}
}
//check for shadowed property
if (TestAndSetEnumerated(propertyId) //checks if the property is already enumerated or not
&& (attributes & PropertyEnumerable))
{
return currentIndex;
}
}
else
{
if (object == baseObject)
{
if (firstPrototype == nullptr)
{
return NULL;
}
object = firstPrototype;
}
else
{
//walk the prototype chain
object = object->GetPrototype();
if ((object == NULL) || (JavascriptOperators::GetTypeId(object) == TypeIds_Null))
{
return NULL;
}
}
do
{
if (!GetCurrentEnumerator())
{
return nullptr;
}
pEnumerator = currentEnumerator;
if (!VirtualTableInfo<Js::NullEnumerator>::HasVirtualTable(pEnumerator))
{
break;
}
//walk the prototype chain
object = object->GetPrototype();
//.........这里部分代码省略.........
示例13: while
JavascriptString * ForInObjectEnumerator::MoveAndGetNext(PropertyId& propertyId)
{
PropertyRecord const * propRecord;
PropertyAttributes attributes = PropertyNone;
while (true)
{
propertyId = Constants::NoProperty;
JavascriptString * currentIndex = enumerator.MoveAndGetNext(propertyId, &attributes);
// The object type may have changed and we may not be able to use Jit fast path anymore.
// canUseJitFastPath is determined in ForInObjectEnumerator::Initialize, once we decide we can't use
// Jit fast path we will never go back to use fast path so && with current value - if it's already
// false we don't call CanUseJITFastPath()
this->canUseJitFastPath = this->canUseJitFastPath && enumerator.CanUseJITFastPath();
if (currentIndex)
{
if (this->shadowData == nullptr)
{
// There are no prototype that has enumerable properties,
// don't need to keep track of the propertyIds we visited.
// We have asked for enumerable properties only, so don't need to check the attribute returned.
Assert(attributes & PropertyEnumerable);
return currentIndex;
}
// Property Id does not exist.
if (propertyId == Constants::NoProperty)
{
if (VirtualTableInfo<Js::PropertyString>::HasVirtualTable(currentIndex))
{
// If we have a property string, it is assumed that the propertyId is being
// kept alive with the object
PropertyString * propertyString = (PropertyString *)currentIndex;
propertyId = propertyString->GetPropertyRecord()->GetPropertyId();
}
else
{
ScriptContext* scriptContext = currentIndex->GetScriptContext();
scriptContext->GetOrAddPropertyRecord(currentIndex->GetString(), currentIndex->GetLength(), &propRecord);
propertyId = propRecord->GetPropertyId();
// We keep the track of what is enumerated using a bit vector of propertyID.
// so the propertyId can't be collected until the end of the for in enumerator
// Keep a list of the property string.
this->shadowData->newPropertyStrings.Prepend(GetScriptContext()->GetRecycler(), propRecord);
}
}
if (TestAndSetEnumerated(propertyId) //checks if the property is already enumerated or not
&& (attributes & PropertyEnumerable))
{
return currentIndex;
}
}
else
{
if (this->shadowData == nullptr)
{
Assert(!this->enumeratingPrototype);
return nullptr;
}
RecyclableObject * object;
if (!this->enumeratingPrototype)
{
this->enumeratingPrototype = true;
object = this->shadowData->firstPrototype;
this->shadowData->currentObject = object;
}
else
{
//walk the prototype chain
object = this->shadowData->currentObject->GetPrototype();
this->shadowData->currentObject = object;
if ((object == nullptr) || (JavascriptOperators::GetTypeId(object) == TypeIds_Null))
{
return nullptr;
}
}
do
{
if (!InitializeCurrentEnumerator(object))
{
return nullptr;
}
if (!enumerator.IsNullEnumerator())
{
break;
}
//walk the prototype chain
object = object->GetPrototype();
this->shadowData->currentObject = object;
//.........这里部分代码省略.........