本文整理汇总了C++中js::MutableHandle::set方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandle::set方法的具体用法?C++ MutableHandle::set怎么用?C++ MutableHandle::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::MutableHandle
的用法示例。
在下文中一共展示了MutableHandle::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: protoVal
void
WorkerDebuggerGlobalScope::CreateSandbox(JSContext* aCx, const nsAString& aName,
JS::Handle<JSObject*> aPrototype,
JS::MutableHandle<JSObject*> aResult,
ErrorResult& aRv)
{
mWorkerPrivate->AssertIsOnWorkerThread();
aResult.set(nullptr);
JS::Rooted<JS::Value> protoVal(aCx);
protoVal.setObjectOrNull(aPrototype);
JS::Rooted<JSObject*> sandbox(aCx,
SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::WorkerDebuggerSandbox,
protoVal));
if (!sandbox) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
if (!JS_WrapObject(aCx, &sandbox)) {
aRv.NoteJSContextException(aCx);
return;
}
aResult.set(sandbox);
}
示例2: AssertIsOnOwningThread
void
IDBIndex::GetKeyPath(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv)
{
AssertIsOnOwningThread();
if (!mCachedKeyPath.isUndefined()) {
MOZ_ASSERT(mRooted);
JS::ExposeValueToActiveJS(mCachedKeyPath);
aResult.set(mCachedKeyPath);
return;
}
MOZ_ASSERT(!mRooted);
aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (mCachedKeyPath.isGCThing()) {
mozilla::HoldJSObjects(this);
mRooted = true;
}
JS::ExposeValueToActiveJS(mCachedKeyPath);
aResult.set(mCachedKeyPath);
}
示例3: TestJsval
/* jsval testJsval (in jsval a, in jsval b); */
NS_IMETHODIMP nsXPCTestParams::TestJsval(JS::Handle<JS::Value> a,
JS::MutableHandle<JS::Value> b,
JS::MutableHandle<JS::Value> _retval)
{
_retval.set(b);
b.set(a);
return NS_OK;
}
示例4: name
void
WebGLContext::GetExtension(JSContext* cx,
const nsAString& wideName,
JS::MutableHandle<JSObject*> retval,
dom::CallerType callerType,
ErrorResult& rv)
{
retval.set(nullptr);
if (IsContextLost())
return;
NS_LossyConvertUTF16toASCII name(wideName);
WebGLExtensionID ext = WebGLExtensionID::Unknown;
// step 1: figure what extension is wanted
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
WebGLExtensionID extension = WebGLExtensionID(i);
if (CompareWebGLExtensionName(name, GetExtensionString(extension))) {
ext = extension;
break;
}
}
if (ext == WebGLExtensionID::Unknown)
return;
// step 2: check if the extension is supported
if (!IsExtensionSupported(callerType, ext))
return;
// step 3: if the extension hadn't been previously been created, create it now, thus enabling it
WebGLExtensionBase* extObj = EnableSupportedExtension(callerType, ext);
if (!extObj)
return;
// Step 4: Enable any implied extensions.
switch (ext) {
case WebGLExtensionID::OES_texture_float:
EnableSupportedExtension(callerType,
WebGLExtensionID::WEBGL_color_buffer_float);
break;
case WebGLExtensionID::OES_texture_half_float:
EnableSupportedExtension(callerType,
WebGLExtensionID::EXT_color_buffer_half_float);
break;
default:
break;
}
retval.set(WebGLObjectAsJSObject(cx, extObj, rv));
}
示例5: switch
void
WebGLExtensionMOZDebug::GetParameter(JSContext* cx, GLenum pname,
JS::MutableHandle<JS::Value> retval,
ErrorResult& er) const
{
const auto& gl = mContext->gl;
gl->MakeCurrent();
switch (pname) {
case LOCAL_GL_EXTENSIONS:
{
nsString ret;
if (!gl->IsCoreProfile()) {
const auto rawExts = (const char*)gl->fGetString(LOCAL_GL_EXTENSIONS);
ret = NS_ConvertUTF8toUTF16(rawExts);
} else {
const auto& numExts = gl->GetIntAs<GLuint>(LOCAL_GL_NUM_EXTENSIONS);
for (GLuint i = 0; i < numExts; i++) {
const auto rawExt = (const char*)gl->fGetStringi(LOCAL_GL_EXTENSIONS,
i);
if (i > 0) {
ret.AppendLiteral(" ");
}
ret.Append(NS_ConvertUTF8toUTF16(rawExt));
}
}
retval.set(StringValue(cx, ret, er));
return;
}
case LOCAL_GL_RENDERER:
case LOCAL_GL_VENDOR:
case LOCAL_GL_VERSION:
{
const auto raw = (const char*)gl->fGetString(pname);
retval.set(StringValue(cx, NS_ConvertUTF8toUTF16(raw), er));
return;
}
case 0x10000: // "WSI_INFO"
{
nsCString info;
gl->GetWSIInfo(&info);
retval.set(StringValue(cx, NS_ConvertUTF8toUTF16(info), er));
return;
}
default:
mContext->ErrorInvalidEnumArg("MOZ_debug.getParameter", "pname", pname);
retval.set(JS::NullValue());
return;
}
}
示例6:
void
WaveShaperNode::GetCurve(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval)
{
// Let's return a null value if the list is empty.
if (mCurve.IsEmpty()) {
aRetval.set(nullptr);
return;
}
MOZ_ASSERT(mCurve.Length() >= 2);
aRetval.set(Float32Array::Create(aCx, this, mCurve.Length(),
mCurve.Elements()));
}
示例7: JS_FreezeObject
nsresult
DOMCameraCapabilities::ParameterListToNewArray(JSContext* aCx,
JS::MutableHandle<JSObject*> aArray,
uint32_t aKey,
ParseItemAndAddFunc aParseItemAndAdd)
{
NS_ENSURE_TRUE(mCamera, NS_ERROR_NOT_AVAILABLE);
const char* value = mCamera->GetParameterConstChar(aKey);
if (!value) {
// in case we get nonsense data back
aArray.set(nullptr);
return NS_OK;
}
aArray.set(JS_NewArrayObject(aCx, 0, nullptr));
if (!aArray) {
return NS_ERROR_OUT_OF_MEMORY;
}
const char* p = value;
uint32_t index = 0;
nsresult rv;
char* q;
while (p) {
/**
* In C's string.h, strchr() is declared as returning 'char*'; in C++'s
* cstring, it is declared as returning 'const char*', _except_ in MSVC,
* where the C version is declared to return const like the C++ version.
*
* Unfortunately, for both cases, strtod() and strtol() take a 'char**' as
* the end-of-conversion pointer, so we need to cast away strchr()'s
* const-ness here to make the MSVC build everything happy.
*/
q = const_cast<char*>(strchr(p, ','));
if (q != p) { // skip consecutive delimiters, just in case
rv = aParseItemAndAdd(aCx, aArray, index, p, &q);
NS_ENSURE_SUCCESS(rv, rv);
++index;
}
p = q;
if (p) {
++p;
}
}
return JS_FreezeObject(aCx, aArray) ? NS_OK : NS_ERROR_FAILURE;
}
示例8: AssertIsOnOwningThread
void
IDBCursor::GetPrimaryKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv)
{
AssertIsOnOwningThread();
if (!mHaveValue) {
aResult.setUndefined();
return;
}
if (!mHaveCachedPrimaryKey) {
if (!mRooted) {
mozilla::HoldJSObjects(this);
mRooted = true;
}
const Key& key =
(mType == Type_ObjectStore || mType == Type_ObjectStoreKey) ?
mKey :
mPrimaryKey;
MOZ_ASSERT(!key.IsUnset());
aRv = key.ToJSVal(aCx, mCachedPrimaryKey);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mHaveCachedPrimaryKey = true;
}
JS::ExposeValueToActiveJS(mCachedPrimaryKey);
aResult.set(mCachedPrimaryKey);
}
示例9: getPrototypeIfOrdinary
bool BaseDOMProxyHandler::getPrototypeIfOrdinary(
JSContext* cx, JS::Handle<JSObject*> proxy, bool* isOrdinary,
JS::MutableHandle<JSObject*> proto) const {
*isOrdinary = true;
proto.set(GetStaticPrototype(proxy));
return true;
}
示例10: result
void
FileReader::GetResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv)
{
JS::Rooted<JS::Value> result(aCx);
if (mDataFormat == FILE_AS_ARRAYBUFFER) {
if (mReadyState == DONE && mResultArrayBuffer) {
result.setObject(*mResultArrayBuffer);
} else {
result.setNull();
}
if (!JS_WrapValue(aCx, &result)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
aResult.set(result);
return;
}
nsString tmpResult = mResult;
if (!xpc::StringToJsval(aCx, tmpResult, aResult)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
}
示例11: StartConsuming
void FetchStreamReader::StartConsuming(JSContext* aCx, JS::HandleObject aStream,
JS::MutableHandle<JSObject*> aReader,
ErrorResult& aRv) {
MOZ_DIAGNOSTIC_ASSERT(!mReader);
MOZ_DIAGNOSTIC_ASSERT(aStream);
aRv.MightThrowJSException();
// Here, by spec, we can pick any global we want. Just to avoid extra
// cross-compartment steps, we want to create the reader in the same
// compartment of the owning Fetch Body object.
// The same global will be used to retrieve data from this reader.
JSAutoRealm ar(aCx, mGlobal->GetGlobalJSObject());
JS::Rooted<JSObject*> reader(
aCx, JS::ReadableStreamGetReader(aCx, aStream,
JS::ReadableStreamReaderMode::Default));
if (!reader) {
aRv.StealExceptionFromJSContext(aCx);
CloseAndRelease(aCx, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mReader = reader;
aReader.set(reader);
aRv = mPipeOut->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
示例12: ac
void
TextEncoder::Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
nsAutoCString utf8;
nsresult rv;
const Encoding* ignored;
Tie(rv, ignored) = UTF_8_ENCODING->Encode(aString, utf8);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
JSAutoCompartment ac(aCx, aObj);
JSObject* outView = Uint8Array::Create(
aCx, utf8.Length(), reinterpret_cast<const uint8_t*>(utf8.BeginReading()));
if (!outView) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
aRetval.set(outView);
}
示例13: getPropertyWrapper
JSBool JavaObject::getPropertyWrapper(JSContext* ctx, JS::Handle<JSObject*> obj,
JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) {
jsval rval;
JSBool result = JavaObject::getProperty(ctx, obj.get(), id.get(), &rval);
vp.set(rval);
return result;
}
示例14: reader
void
FetchStreamReader::StartConsuming(JSContext* aCx,
JS::HandleObject aStream,
JS::MutableHandle<JSObject*> aReader,
ErrorResult& aRv)
{
MOZ_DIAGNOSTIC_ASSERT(!mReader);
MOZ_DIAGNOSTIC_ASSERT(aStream);
JS::Rooted<JSObject*> reader(aCx,
JS::ReadableStreamGetReader(aCx, aStream,
JS::ReadableStreamReaderMode::Default));
if (!reader) {
aRv.StealExceptionFromJSContext(aCx);
CloseAndRelease(aCx, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mReader = reader;
aReader.set(reader);
aRv = mPipeOut->AsyncWait(this, 0, 0, mOwningEventTarget);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
示例15: switch
void
WebGLExtensionDisjointTimerQuery::GetQueryObjectEXT(JSContext* cx,
WebGLTimerQuery* query,
GLenum pname,
JS::MutableHandle<JS::Value> retval)
{
if (mIsLost)
return;
if (!mContext->ValidateObject("getQueryObjectEXT", query))
return;
if (query == mActiveQuery.get()) {
mContext->ErrorInvalidOperation("getQueryObjectEXT: Query must not be"
" active.");
}
mContext->MakeContextCurrent();
// XXX: Note that the query result *may change* within the same task!
// This does not follow the specification, which states that all calls
// checking query results must return the same value until the event loop
// is empty.
switch (pname) {
case LOCAL_GL_QUERY_RESULT_EXT: {
GLuint64 result = 0;
mContext->GL()->fGetQueryObjectui64v(query->mGLName,
LOCAL_GL_QUERY_RESULT_EXT,
&result);
retval.set(JS::NumberValue(result));
break;
}
case LOCAL_GL_QUERY_RESULT_AVAILABLE_EXT: {
GLuint avail = 0;
mContext->GL()->fGetQueryObjectuiv(query->mGLName,
LOCAL_GL_QUERY_RESULT_AVAILABLE_EXT,
&avail);
bool canBeAvailable = query->CanBeAvailable() || gfxPrefs::WebGLImmediateQueries();
retval.set(JS::BooleanValue(bool(avail) && canBeAvailable));
break;
}
default:
mContext->ErrorInvalidEnumInfo("getQueryObjectEXT: Invalid query"
" property.", pname);
break;
}
}