Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOT FOR CHECK IN] Design Feedback for PreparedJavaScriptStore #3650

Closed
wants to merge 1 commit into from

Conversation

hansenyy
Copy link
Contributor

@hansenyy hansenyy commented Nov 12, 2019

This PR is intended as a way to get some design feedback while I working on redesigning the PreparedJavaScriptStore (used to be called PreparedScriptStore). The only projects building at the moment are the JSI projects (except for JSI.Desktop.UnitTests).

Iteration 1:

Make Chakra and ChakraCore based jsi::Runtimes into a proper class hierarchy. ChakraCoreRuntime is the jsi::Runtime based on ChakraCore, ChakraRtRuntime is the jsi::Runtime based on Chakra, and both jsi::Runtimes derive from CharkraRuntime. The name "ChakraRtRuntime" comes from the header that gets #included by jsrt.h when USE_EDGEMODE_JSRT is #defined.

There are still some macro guarding in code. Most of them are in ChakraObjectRef.h/cpp and all have comments explaining why they are there. The rest are used to make sure that, when a specific engine is used, only the corresponding jsi::Runtime is available.

I also tried to simplify the PreparedJavaScriptStore interface.Originally I wanted to also supply a prototype implementation of PreparedJavaScriptStore as part of iteration 1, but I ran into some design problem here. I would very much appreciate some feedback here.

Microsoft Reviewers: Open in CodeFlow

commit 1d3cdc8
Merge: 62fe483 a5f5255
Author: Yichen Yao <[email protected]>
Date:   Tue Nov 12 10:50:06 2019 -0800

    Merge branch 'master' into RevampPreparedScriptStore

commit 62fe483
Author: Yichen Yao <[email protected]>
Date:   Mon Nov 11 15:41:34 2019 -0800

    Introduce ChakraRtRuntime.

commit 9cbfa71
Author: Yichen Yao <[email protected]>
Date:   Mon Nov 11 14:32:21 2019 -0800

    Finish up ChakraCoreRuntime.

commit 77d1f11
Author: Yichen Yao <[email protected]>
Date:   Wed Nov 6 17:52:34 2019 -0800

    Get rid of ScriptStore and refactor bytecode execution.

commit 9acd7da
Author: Yichen Yao <[email protected]>
Date:   Tue Nov 5 16:27:41 2019 -0800

    Refactor ChakraRuntime.

commit 6fd2719
Author: Yichen Yao <[email protected]>
Date:   Mon Nov 4 18:20:31 2019 -0800

    Clean up ChakraRuntimeArgs.h

commit 472b6fb
Merge: c2a47e5 8b87988
Author: Yichen Yao <[email protected]>
Date:   Fri Nov 1 17:24:21 2019 -0700

    Merge branch 'master' into RevampPreparedScriptStore

commit c2a47e5
Author: Yichen Yao <[email protected]>
Date:   Fri Nov 1 17:18:37 2019 -0700

    Introduce ChakraCoreRuntime.
@ghost ghost added the vnext label Nov 12, 2019
@@ -9,33 +9,45 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)ByteArrayBuffer.h">
Copy link
Contributor Author

@hansenyy hansenyy Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[](start = 4, length = 66)

(nit) I will alphabetize this later. #Resolved


assert(
static_cast<unsigned long long>(bytecodeSize) <=
static_cast<unsigned long long>((std::numeric_limits<size_t>::max)()));
Copy link
Contributor Author

@hansenyy hansenyy Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are plenty of places where we are checking for overflow/underflow before an integer conversion. It would be nice to implement and use something like boost::numeric_cast. In my opinion it would be nice to just use boost::numeric_cast instead of implementing our own. Thoughts? #Resolved

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a dependency on boost. I would just use their version.


In reply to: 345396549 [](ancestors = 345396549)

/**
* TODO (yicyao)
*/
class PreparedJavaScriptStore {
Copy link
Contributor Author

@hansenyy hansenyy Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PreparedJavaScriptStore [](start = 6, length = 23)

I would appreciate some design feedback/suggestions here. Here are the problems that I find with the architecture proposed in this PR:

  1. For now, let's assume that a user of ReactNative passes a RuntimeHolderLazyInit (see RuntimeHolder.h) as part of DevSettings. Consider a sample implementation of ChakraCoreJsiHolder. In order to construct a ChakraCoreRuntime, one need to be able to construct a ChakraCoreRuntimeArgs. In order to construct a ChakraCoreRuntimeArgs, one need to be able to construct a PreparedJavaScriptStore. A PreparedJavaScriptStore for ChakraCore will need to know about ChakraCorePreparedJavaScript. This means that we need to expose ChakraCoreJsiHolder, ChakraCoreRuntimeArgs, and ChakraCorePreparedJavaScript to the user of react native. This seems just bad.

  2. Since every engine is different, each engine's PreparedJavaScript will likely be different, and for each engine, we might want different PreparedJavaScriptStore that cache/read PreparedJavaScript in different ways. We run into this combinatorial explosion. I think breaking this interface up into something that handles caching and reading and something that handles interpreting the structure of PreparedJavaScript may help with this. I am not sure where version checking would fit here though. #Resolved

Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #2, I agree that it feels like there are two components. Things like writing bytecode to disk would be shared between different runtimes, but generating information about things like versioning or creating the actual bytecode would be runtime specific.

For versioning, you could have the runtime give you something like a hash. E.g. for Chakra, you could combine all the normal fields about version with a Chakra specific magic number or something.

Maybe you could add an interface like PreparedScriptWriter that could output a buffer and a runtime hash?


In reply to: 345402558 [](ancestors = 345402558)

Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1 looks ok. If Engine supports various options, they should all be exposed to the user.
For common path, we should just have a good default options.


In reply to: 345472382 [](ancestors = 345472382,345402558)

using ChakraRuntime::ChakraRuntime;
~ChakraRtRuntime() noexcept = default;

#pragma region Functions_inherited_from_Runtime
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pragma region [](start = 0, length = 14)

nit: I think pragma region is useful for large spans of code, but it seems a bit overkill here. What about a comment that just says "Runtime" and "ChakraRuntime" above the block of functions? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally using comments in ChakraRuntime.h until the span got too large. That's when I switch to #pragma region and ended up copying those here. I'll change these to comments.


In reply to: 345415851 [](ancestors = 345415851)


std::unique_ptr<facebook::jsi::Runtime> makeChakraRtRuntime(const std::shared_ptr<ChakraRtRuntimeArgs> &args) noexcept {
auto runtime = std::make_unique<ChakraRtRuntime>(args);
runtime->Initialize();
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize [](start = 11, length = 10)

Why don't we do this in the ctor if we want to do this after building anyway? The main place I've seen two-phase intiaalization be useful is for cases where we want to delay init because something is expensive, or offer flow control to handle failure. #ByDesign

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also let us get rid of the factory, unless we wanted it for a specific reason.


In reply to: 345416842 [](ancestors = 345416842)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize() need to invoke EvaluateJavaScriptSimple, a virtual function, on a bootstrap bundle for implementing HostObjects. Since virtual dispatch does not work in constructors, we need a separate Initialize step.


In reply to: 345417135 [](ancestors = 345417135,345416842)

@NickGerleman
Copy link
Collaborator

NickGerleman commented Nov 12, 2019

It feels like there are multiple independent changes happening here. When we check this in, could we split it into separate PRs? #Resolved

private:
// We override the following because ChakraCore (unlike Chakra) offers
// weak reference semantics.
facebook::jsi::WeakObject createWeakObject(const facebook::jsi::Object &obj) override;
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override [](start = 79, length = 8)

Should these be protected instead of private? #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is inheriting from ChakraCoreRuntime right now so I don't think there is any reason for making members protected. If we need change this to protected in the future, we'll do it then.


In reply to: 345443262 [](ancestors = 345443262)

private:
// Only ChakraCore supports weak reference semantics, so ChakraRtRuntime
// WeakObjects are in fact strong references.
facebook::jsi::WeakObject createWeakObject(const facebook::jsi::Object &obj) override;
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override [](start = 79, length = 8)

protected? #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment.


In reply to: 345444502 [](ancestors = 345444502)


private:
// Only ChakraCore supports weak reference semantics, so ChakraRtRuntime
// WeakObjects are in fact strong references.
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WeakObjects are in fact strong references [](start = 5, length = 41)

This worries me a lot, since it seems like we can silently keep objects alive too long and create leaks or hard to debug issues. Do we know if this is used? If not could we maybe terminate() or provide some behavior to make it clear something bad may happen? #Resolved

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like existing behavior. Do we have a bug tracking this?


In reply to: 345444948 [](ancestors = 345444948)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have a but tracking this at the moment. I'll create a issue.


In reply to: 345450009 [](ancestors = 345450009,345444948)


#pragma endregion Functions_inherited_from_ChakraRuntime

// Both sourceCode and sourceUrl must be UTF-16 encoded and null-terminated.
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both sourceCode and sourceUrl must be UTF-16 encoded and null-terminated. [](start = 5, length = 73)

nit: not sure if this is worth documenting. Seems implied already by the types. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove.


In reply to: 345445687 [](ancestors = 345445687)

@NickGerleman
Copy link
Collaborator

NickGerleman commented Nov 12, 2019

It's a bit hard to review the chanegs from ChakraRuntime to ChakraCoreRuntime as is. In the future, would you be able to follow a pattern of

  1. First commit that just copies the original file to the new file
  2. Second commit with the actual changes

This lets the reviewer see diffs of what has actually changed. #Resolved

@NickGerleman
Copy link
Collaborator

Nevermind. It looks like putting this through a diff tool doesn't given anything too useful.


In reply to: 553116750 [](ancestors = 553116750)


namespace Microsoft::JSI {

struct ChakraRuntimeArgs;

class ChakraPreparedJavaScript : public facebook::jsi::PreparedJavaScript {
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChakraPreparedJavaScript [](start = 6, length = 24)

nit: This header seems to be getting big. Would this be better in its own file? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Will fix this in a future iteration.


In reply to: 345451951 [](ancestors = 345451951)

}

private:
std::string m_sourceUrl;
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_sourceUrl [](start = 14, length = 11)

nit: If we're going to offer these with direct access, should we just make them public and const? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Will make the appropriate change.


In reply to: 345453590 [](ancestors = 345453590)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providing getters is better


In reply to: 345474793 [](ancestors = 345474793,345453590)


// The returned std::shared_ptr<const facebook::jsi::PreparedJavaScript>
// points to a ChakraPreparedJavaScript and must only be used while this
// ChakraRuntime is still alive.
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alive [](start = 28, length = 5)

I'm a bit confused by this comment. Would you be able to clarify? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ChakraCoreRuntime,, the ChakraPreparedJavaScript returned by prepareJavaScript holds a ChakraCoreByteCodeBuffer, which in turns holds a ChakraObjectRef. (We do so to avoid copying bytecode from JS engined owned memory to RN owned memory.) So the returned ChakraPreparedJavaScript must only be used while the ChakraCoreRuntime that created it is still alive.


In reply to: 345454257 [](ancestors = 345454257)

/**
* TODO (yicyao)
*/
std::unique_ptr<PreparedJavaScriptStore> m_preparedJsStore{nullptr};
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique_ptr [](start = 7, length = 10)

Will we need to share the script store ever with something outside the runtime? Wondering if this should be ref counted. #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether we need ref counting here or not. Let's keep this a unique_ptr for now and change it to a shared_ptr if needed in the future.


In reply to: 345456324 [](ancestors = 345456324)

struct ChakraRuntimeArgs {
bool enableJITCompilation{true};
public:
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 1, length = 6)

nit: public is implied for struct #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to explicitly state the accessibly of members. If people feel strongly about this I can remove it.


In reply to: 345457882 [](ancestors = 345457882)

/**
* @brief ChakraRuntime's policy for allocating executable pages.
*/
ExecutablePageAllocationPolicy m_executablePageAllocationPolicy{ExecutablePageAllocationPolicy::EnableAll};
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_ [](start = 33, length = 2)

nit: I usually don't see the "m_" prefix for structs, only for private class members #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong preferences here so if people do not like the "m_" prefix I can remove them.


In reply to: 345458052 [](ancestors = 345458052)

}

if (m_args->m_memoryTracker) {
std::shared_ptr<facebook::react::MemoryTracker> &memoryTracker = m_args->m_memoryTracker;
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr< [](start = 4, length = 16)

This is super super nitty, but this might be clearer as a ref to the underlying MemoryTracker instead of a ref to the shared_ptr. #Resolved

@@ -560,7 +534,9 @@ facebook::jsi::Value ChakraRuntime::call(
std::vector<ChakraObjectRef> argRefs = ToChakraObjectRefs(args, count);

std::vector<JsValueRef> argsWithThis = ConstructJsFunctionArguments(thisRef, argRefs);
assert(argsWithThis.size() <= (std::numeric_limits<unsigned short>::max)());
assert(
static_cast<unsigned long long>(argsWithThis.size()) <=
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsigned long long [](start = 18, length = 18)

nit: I think "long" and "long long" can confuse folks occasionally. What about uint64_t? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes uint64_t works here. But then if we can use numeric_cast we can get rid of this altogether.


In reply to: 345460001 [](ancestors = 345460001)

" return new Proxy(target, handler)\n"
"}";

constexpr const char *const g_proxyConstructorBootstrapFuncName = "$$ChakraRuntimeProxyConstructor$$";
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

g_proxyConstructorBootstrapFuncName [](start = 28, length = 35)

nit: we should keep these in their original position. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert this.


In reply to: 345462359 [](ancestors = 345462359)

*/
class PreparedJavaScriptStore {
public:
virtual ~PreparedJavaScriptStore() = 0;
Copy link
Collaborator

@NickGerleman NickGerleman Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 [](start = 39, length = 1)

should this be default? #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Will fix this.


In reply to: 345464888 [](ancestors = 345464888)

@hansenyy
Copy link
Contributor Author

Next time I'll try to do what you suggested here.


In reply to: 553116750 [](ancestors = 553116750)

@hansenyy
Copy link
Contributor Author

For check in I will likely be splitting this change into two: one for introducing the class hierarchy, one for redesigning PreparedScriptStore. But I thought I would send out a change with both so that people can get a feel of the entire architecture. If this ended up being the opposite of helpful please let me know.


In reply to: 553096653 [](ancestors = 553096653)


namespace Microsoft::JSI {

class ChakraCoreRuntime : public ChakraRuntime {
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChakraCoreRuntime [](start = 6, length = 17)

Please add comments why do we have ChakraRuntime and ChakraCoreRuntime. #Resolved


#pragma once

#ifdef CHAKRACORE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHAKRACORE [](start = 7, length = 10)

Add comment why this is needed


namespace Microsoft::JSI {

class ChakraCoreRuntime : public ChakraRuntime {
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChakraCoreRuntime [](start = 6, length = 17)

Should this be final? #Resolved


class ChakraCoreRuntime : public ChakraRuntime {
public:
ChakraCoreRuntime(const std::shared_ptr<ChakraCoreRuntimeArgs> &args) noexcept;
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr & [](start = 26, length = 40)

(nit) Since this is a constructor, would it make sense to pass by std::shared_ptr&&? #Resolved


#pragma region Functions_inherited_from_ChakraRuntime

facebook::jsi::Value EvaluateJavaScriptSimple(
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EvaluateJavaScriptSimple [](start = 23, length = 24)

Why "Simple"? Please add comment #Resolved


std::string description() override;

private:
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this inside of inherited from Jsi Runtime region? #Resolved

private:
// We override the following because ChakraCore (unlike Chakra) offers
// weak reference semantics.
facebook::jsi::WeakObject createWeakObject(const facebook::jsi::Object &obj) override;
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createWeakObject [](start = 28, length = 16)

Similar to comments on other code reviews, can we do "MakeWeakObject"? this would be consistent with Mso::Make and std::make_*

Or this is overridden method we can't change? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a overriden method that we cannot change.


In reply to: 345519532 [](ancestors = 345519532)


using WeakChakraPointerValue = ChakraPointerValueTemplate<JsWeakRef>;

// source must be a JS ArrayBuffer or JS ExternalArrayBuffer. sourceUrl must
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s [](start = 64, length = 1)

(nit) start new line #Resolved


using WeakChakraPointerValue = ChakraPointerValueTemplate<JsWeakRef>;

// source must be a JS ArrayBuffer or JS ExternalArrayBuffer. sourceUrl must
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [](start = 2, length = 2)

(nit) please use doxygen style comments, eg //!


// In-proc debugging helpers
void ProcessDebuggerCommandQueue();
static void CALLBACK ProcessDebuggerCommandQueueCallback(void *callbackState);
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CALLBACK [](start = 14, length = 8)

OOC why is this needed? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass a callback of this signature to ChakraCoreDebugger API when setting up direct debugging.


In reply to: 345520533 [](ancestors = 345520533)


// In-proc debugging helpers
void ProcessDebuggerCommandQueue();
static void CALLBACK ProcessDebuggerCommandQueueCallback(void *callbackState);
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void * [](start = 59, length = 6)

Can't we pass something else besides void*? If this is id, it could be intptr_t #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and all the other functions with the CALLBACK macro prefix are passed to ChakraCore APIs, as a result their signatures can't be changed.


In reply to: 345520788 [](ancestors = 345520788)


// Promise Helpers
void PromiseContinuation(ChakraObjectRef &&value) noexcept;
void PromiseRejectionTracker(ChakraObjectRef &&promise, ChakraObjectRef &&reason, bool handled);
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

); [](start = 96, length = 2)

should this be noexcept too? What about other functions? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually should not be noexcept. CharkCore API requires a pointer to a non-noexcept function. It is strange to me that this was able to compile.


In reply to: 345520983 [](ancestors = 345520983)

void PromiseRejectionTracker(ChakraObjectRef &&promise, ChakraObjectRef &&reason, bool handled);
static void CALLBACK PromiseContinuationCallback(JsValueRef funcRef, void *callbackState) noexcept;
static void CALLBACK
PromiseRejectionTrackerCallback(JsValueRef promise, JsValueRef reason, bool handled, void *callbackState);
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) can you reformat this to something like:
static void CALLBACK PromiseRejectionTrackerCallback(
JsValueRef promise, JsValueRef reason, bool handled, void *callbackState); #Resolved

static void CALLBACK
PromiseRejectionTrackerCallback(JsValueRef promise, JsValueRef reason, bool handled, void *callbackState);

std::shared_ptr<ChakraCoreRuntimeArgs> m_args{nullptr};
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) please add another private: here to denote start of listing of variables #Resolved


std::shared_ptr<ChakraCoreRuntimeArgs> m_args{nullptr};

std::shared_ptr<DebugProtocolHandler> m_debugProtocolHandler{nullptr};
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr [](start = 63, length = 7)

shared_ptr is null by default, right? so these should not be needed. #Resolved

@NickGerleman
Copy link
Collaborator

NickGerleman commented Nov 13, 2019 via email

std::shared_ptr<DebugProtocolHandler> m_debugProtocolHandler{nullptr};
std::unique_ptr<DebugService> m_debugService{nullptr};

std::shared_ptr<bool> m_runtimeIsAlive{nullptr};
Copy link

@NikoAri NikoAri Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared_ptr [](start = 7, length = 10)

Why do we need a shared_ptr for this? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When native promise is turned on, we schedule promise continuation callbacks onto the jsQueue. When those callbacks are invoked, we need to check that the ChakraCore runtime has not been disposed before calling the JS promise continuation function. We take a weak_ptr to this member and use it to perform the runtime aliveness check.


In reply to: 345521748 [](ancestors = 345521748)

/**
* TODO (yicyao)
*/
uint8_t *GetArrayBufferData(const ChakraObjectRef &arrBuf);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetArrayBufferData [](start = 9, length = 18)

This api should include getting length as well

* TODO (yicyao)
*/
class PreparedJavaScriptStore {
public:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public [](start = 1, length = 6)

I would recommend creating a small test which takes advantage of this Api. It could become much easier to spot which options should be exposed to the user.

Copy link

@NikoAri NikoAri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@ghost ghost added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Nov 13, 2019
@NikoAri
Copy link

NikoAri commented Nov 13, 2019 via email

@NickGerleman
Copy link
Collaborator

NickGerleman commented Nov 13, 2019 via email

@NikoAri
Copy link

NikoAri commented Nov 13, 2019 via email

@NikoAri
Copy link

NikoAri commented Nov 14, 2019 via email

@hansenyy hansenyy closed this Nov 15, 2019
@ghost ghost removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Nov 15, 2019
@hansenyy hansenyy deleted the PrepJsStorePr branch January 7, 2020 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants