Skip to content

Commit

Permalink
Add HermesInternal.hasPromise
Browse files Browse the repository at this point in the history
Summary: Add HermesInternal.hasPromise() which always returns false (for now).

Reviewed By: dulinriley

Differential Revision: D23486049

fbshipit-source-id: 9a3fdc7fda6a92ec521219224410546a4a62c76b
  • Loading branch information
Huxpro authored and facebook-github-bot committed Oct 15, 2020
1 parent f8f9e6a commit 96006e5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/hermes/VM/NativeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ NATIVE_FUNCTION(hermesInternalGetInstrumentedStats)
NATIVE_FUNCTION(hermesInternalGetRuntimeProperties)
NATIVE_FUNCTION(hermesInternalGetWeakSize)
NATIVE_FUNCTION(hermesInternalIsProxy)
NATIVE_FUNCTION(hermesInternalHasPromise)
NATIVE_FUNCTION(hermesInternalTTIReached)
NATIVE_FUNCTION(hermesInternalTTRCReached)

Expand Down
1 change: 1 addition & 0 deletions include/hermes/VM/PredefinedStrings.def
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ STR(revoke, "revoke")
STR(HermesInternal, "HermesInternal")
STR(detachArrayBuffer, "detachArrayBuffer")
STR(createHeapSnapshot, "createHeapSnapshot")
STR(hasPromise, "hasPromise")
STR(getEpilogues, "getEpilogues")
STR(getWeakSize, "getWeakSize")
STR(silentSetPrototypeOf, "silentSetPrototypeOf")
Expand Down
6 changes: 6 additions & 0 deletions lib/VM/JSLib/HermesInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ hermesInternalIsProxy(void *, Runtime *runtime, NativeArgs args) {
return HermesValue::encodeBoolValue(obj && obj->isProxyObject());
}

CallResult<HermesValue>
hermesInternalHasPromise(void *, Runtime *runtime, NativeArgs args) {
return HermesValue::encodeBoolValue(false);
}

#ifdef HERMESVM_EXCEPTION_ON_OOM
/// Gets the current call stack as a JS String value. Intended (only)
/// to allow testing of Runtime::callStack() from JS code.
Expand Down Expand Up @@ -795,6 +800,7 @@ Handle<JSObject> createHermesInternalObject(
"Failed to set HermesInternal.concat.");
(void)putRes;

defineInternMethod(P::hasPromise, hermesInternalHasPromise);
defineInternMethod(
P::setPromiseRejectionTrackingHook,
hermesInternalSetPromiseRejectionTrackingHook);
Expand Down
3 changes: 2 additions & 1 deletion test/hermes/internal-test-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
// RUN: %hermes -Xhermes-internal-test-methods=false %s | %FileCheck --match-full-lines --check-prefix=CHKIMD %s

// concat
// hasPromise
// setPromiseRejectionTrackingHook
// enablePromiseRejectionTracker
var SAFE_FIELDS_COUNT = 3;
var SAFE_FIELDS_COUNT = 4;

// Check that we can disable unsafe fields of HermesInternal.
print(Object.getOwnPropertyNames(HermesInternal).length !== SAFE_FIELDS_COUNT);
Expand Down
18 changes: 18 additions & 0 deletions test/hermes/promise-disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// RUN: %hermes %s | %FileCheck --match-full-lines %s
// RUN: %hermesc -O -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s

print('promise-disable');
// CHECK-LABEL: promise-disable

print(HermesInternal.hasPromise());
// CHECK-NEXT: false

print(typeof Promise);
// CHECK-NEXT: undefined

0 comments on commit 96006e5

Please sign in to comment.