Skip to content
Permalink
Browse files

Exposing APIs to store/get host data

This is implemented by using internal property (EmbedderData). Currently
it is used for TypedArray/ArrayBuffer. It may expand in future.
  • Loading branch information...
akroshg committed Mar 5, 2019
1 parent 1736e5b commit 62d3d1163777f80abb46e3556028244a8b107916
@@ -1949,6 +1949,30 @@ CHAKRA_API
JsExternalizeArrayBuffer(
_In_ JsValueRef arrayBuffer);

/// <summary>
/// Get host embedded data from the current object
/// </summary>
/// <param name="instance">Js object from which an embedder data to be fetched</param>
/// <param name="embedderData">An embedder data to be returned, it will be nullptr if not found</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code
/// otherwise.
/// </returns>
CHAKRA_API
JsGetEmbedderData(_In_ JsValueRef instance, _Out_ JsValueRef* embedderData);

/// <summary>
/// Set host embedded data on the current object
/// </summary>
/// <param name="instance">Js object from which an embedder data to be fetched</param>
/// <param name="embedderData">An embedder data to be set on the passed object</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code
/// otherwise.
/// </returns>
CHAKRA_API
JsSetEmbedderData(_In_ JsValueRef instance, _In_ JsValueRef embedderData);

#ifdef _WIN32
#include "ChakraCoreWindows.h"
#endif // _WIN32
@@ -497,6 +497,63 @@ JsSetArrayBufferExtraInfo(
END_JSRT_NO_EXCEPTION
}


CHAKRA_API
JsGetEmbedderData(
_In_ JsValueRef instance,
_Out_ JsValueRef* embedderData)
{
VALIDATE_JSREF(instance);
PARAM_NOT_NULL(embedderData);
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext* scriptContext) -> JsErrorCode {
Js::RecyclableObject* object = Js::JavascriptOperators::TryFromVar<Js::RecyclableObject>(instance);
if (!object)
{
return JsErrorInvalidArgument;
}

// Right now we know that we support these many. Lets find out if
// there are more.
Assert(Js::TypedArrayBase::Is(object->GetTypeId()) ||
object->GetTypeId() == Js::TypeIds_ArrayBuffer ||
object->GetTypeId() == Js::TypeIds_DataView ||
object->GetTypeId() == Js::TypeIds_SharedArrayBuffer);

if (!object->GetInternalProperty(object, Js::InternalPropertyIds::EmbedderData, embedderData, nullptr, scriptContext))
{
*embedderData = nullptr;
}
return JsNoError;
});
}

CHAKRA_API
JsSetEmbedderData(_In_ JsValueRef instance, _In_ JsValueRef embedderData)
{
VALIDATE_JSREF(instance);
return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext* scriptContext) -> JsErrorCode {
Js::RecyclableObject* object = Js::JavascriptOperators::TryFromVar<Js::RecyclableObject>(instance);
if (!object)
{
return JsErrorInvalidArgument;
}

// Right now we know that we support these many. Lets find out if
// there are more.
Assert(Js::TypedArrayBase::Is(object->GetTypeId()) ||
object->GetTypeId() == Js::TypeIds_ArrayBuffer ||
object->GetTypeId() == Js::TypeIds_DataView ||
object->GetTypeId() == Js::TypeIds_SharedArrayBuffer);

if (!object->SetInternalProperty(Js::InternalPropertyIds::EmbedderData, embedderData, Js::PropertyOperationFlags::PropertyOperation_None, nullptr))
{
return JsErrorInvalidArgument;
}

return JsNoError;
});
}

CHAKRA_API
JsExternalizeArrayBuffer(
_In_ JsValueRef arrayBufferVar)
@@ -134,6 +134,8 @@
JsGetIteratorPrototype
JsGetPropertyIdSymbolIterator
JsGetWeakReferenceValue
JsGetEmbedderData
JsSetEmbedderData
JsHasOwnProperty
JsHasOwnItem
JsIsCallable
@@ -26,4 +26,6 @@ INTERNALPROPERTY(CachedUDateFormat) // Used to store cached UDateF
INTERNALPROPERTY(CachedUPluralRules) // Used to store cached UPluralRules objects for Intl.PluralRules
INTERNALPROPERTY(RevocableProxy) // Internal slot for [[RevokableProxy]] for revocable proxy in ES6
INTERNALPROPERTY(MutationBp) // Used to store strong reference to the mutation breakpoint object
INTERNALPROPERTY(EmbedderData) // Holds embedder data here.

#undef INTERNALPROPERTY

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -809,6 +809,16 @@ namespace Js
mutationBpValue = nullptr;
}

Var embedderData = nullptr;
if (this->GetInternalProperty(this, InternalPropertyIds::EmbedderData, &embedderData, nullptr, this->GetScriptContext()))
{
this->SetInternalProperty(InternalPropertyIds::EmbedderData, nullptr, PropertyOperation_Force, nullptr);
}
else
{
embedderData = nullptr;
}

// If value of TypeOfPrototypeObjectDictionary was set undefined above, reset it to nullptr so we don't type cast it wrongly to TypeTransitionMap* or we don't marshal the non-Var dictionary below
Var typeTransitionMap = nullptr;
if (this->GetInternalProperty(this, InternalPropertyIds::TypeOfPrototypeObjectDictionary, &typeTransitionMap, nullptr, this->GetScriptContext()))
@@ -832,6 +842,10 @@ namespace Js
{
this->SetInternalProperty(InternalPropertyIds::MutationBp, mutationBpValue, PropertyOperation_Force, nullptr);
}
if (embedderData)
{
this->SetInternalProperty(InternalPropertyIds::EmbedderData, embedderData, PropertyOperation_Force, nullptr);
}
}
}

0 comments on commit 62d3d11

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.