本文整理汇总了C++中JSValueToNumber函数的典型用法代码示例。如果您正苦于以下问题:C++ JSValueToNumber函数的具体用法?C++ JSValueToNumber怎么用?C++ JSValueToNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSValueToNumber函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: JSStringCreateWithUTF8CString
bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException)
{
// it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf
// call getTime()
bool ok = false;
JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime");
JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException);
JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException);
JSStringRelease( jsString);
JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL;
if (result != NULL)
{
// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
double r = JSValueToNumber( inContext, result, outException);
sLONG8 n = (sLONG8) r;
if (n == r)
{
outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0);
outTime.AddMilliseconds( n);
ok = true;
}
else
{
outTime.SetNull( true);
}
}
else
{
outTime.SetNull( true);
}
return ok;
}
开发者ID:sanyaade-webdev,项目名称:core-XToolbox,代码行数:33,代码来源:JS4D.cpp
示例2: main
int main (int argc, char **argv) {
JSGlobalContextRef ctx;
JSStringRef script;
bool isOk;
JSValueRef result;
char *js;
if (argc <= 1) {
printf("Usage: JavaScript\n");
return 0;
}
js = argv[1];
ctx = JSGlobalContextCreate(NULL);
printf("Checking: %s\n", js);
script = JSStringCreateWithUTF8CString(js);
isOk = JSCheckScriptSyntax(ctx, script, NULL, 1, NULL);
printf("is ok? %s\n", isOk ? "TRUE" : "FALSE");
result = JSEvaluateScript(ctx, script, NULL, NULL, 1, NULL);
JSStringRelease(script);
printf("Value %.2f\n", JSValueToNumber(ctx, result, NULL));
JSGarbageCollect(ctx);
JSGlobalContextRelease(ctx);
printf("Ok\n");
return 0;
}
开发者ID:potyl,项目名称:perl-JavaScriptCore,代码行数:32,代码来源:jsc.c
示例3: getResourceDocumentNode
static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/)
{
JSValueRef undefined = JSValueMakeUndefined(ctx);
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!argumentCount || argumentCount > 1 || !controller)
return undefined;
JSValueRef identifierValue = arguments[0];
if (!JSValueIsNumber(ctx, identifierValue))
return undefined;
unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, 0));
RefPtr<InspectorResource> resource = controller->resources().get(identifier);
ASSERT(resource);
if (!resource)
return undefined;
FrameLoader* frameLoader = resource->loader->frameLoader();
if (!frameLoader)
return undefined;
Document* document = frameLoader->frame()->document();
if (!document)
return undefined;
if (document->isPluginDocument() || document->isImageDocument())
return undefined;
KJS::JSLock lock;
JSValueRef documentValue = toRef(toJS(toJS(controller->scriptContext()), document));
return documentValue;
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:33,代码来源:InspectorController.cpp
示例4: JSValueMakeUndefined
JSValueRef JSCExecutor::nativeRequire(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
if (argumentCount != 1) {
*exception = makeJSCException(ctx, "Got wrong number of args");
return JSValueMakeUndefined(ctx);
}
JSCExecutor *executor;
try {
executor = s_globalContextRefToJSCExecutor.at(JSContextGetGlobalContext(ctx));
} catch (std::out_of_range& e) {
*exception = makeJSCException(ctx, "Global JS context didn't map to a valid executor");
return JSValueMakeUndefined(ctx);
}
double moduleId = JSValueToNumber(ctx, arguments[0], exception);
if (moduleId <= (double) std::numeric_limits<uint32_t>::max() && moduleId >= 0.0) {
try {
executor->loadModule(moduleId);
} catch (JSModulesUnbundle::ModuleNotFound&) {
*exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception);
}
} else {
*exception = makeInvalidModuleIdJSCException(ctx, arguments[0], exception);
}
return JSValueMakeUndefined(ctx);
}
开发者ID:DYS1230,项目名称:react-native,代码行数:33,代码来源:JSCExecutor.cpp
示例5: JSValueToStringCopy
bool S_CCLabelTTF::initWithContext(JSContextRef ctx, JSObjectRef obj, size_t argumentCount, const JSValueRef arguments[])
{
bool result = true;
if (argumentCount == 3) {
char *buffText = (char *)malloc(128);
char *buffFont = (char *)malloc(128);
JSStringRef jsLabelText = JSValueToStringCopy(ctx, arguments[0], NULL);
JSStringRef jsFontName = JSValueToStringCopy(ctx, arguments[1], NULL);
float fontSize = JSValueToNumber(ctx, arguments[2], NULL);
JSStringGetUTF8CString(jsLabelText, buffText, 128);
JSStringGetUTF8CString(jsFontName, buffFont, 128);
if (!CCLabelTTF::initWithString(buffText, buffFont, fontSize)) {
return false;
}
free(buffText);
free(buffFont);
} else {
if (!CCLabelTTF::init()) {
result = false;
}
}
if (result) {
setUserData(obj);
}
return result;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:29,代码来源:S_CCLabel.cpp
示例6: if
JSValueRef JSCCharacterData::insertDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj);
if (false) {
} else if (argumentCount == 2 &&
JSValueIsNumber(ctx, arguments[0]) &&
JSValueIsString(ctx, arguments[1])) {
unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception);
JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[1], exception);
size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg);
char* localArgBuffer = new char[localArgMaxSize];
JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize);
std::string localArg(localArgBuffer);
JSStringRelease(stringReflocalArg);
free(localArgBuffer);
privData->nativeObj->insertData(localOffset, localArg);
JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
return jscRetVal;
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling insertData");
*exception = JSValueMakeString(ctx, exceptionString);
JSStringRelease(exceptionString);
return JSValueMakeUndefined(ctx);
}
开发者ID:bjqiwei,项目名称:uscxml,代码行数:29,代码来源:JSCCharacterData.cpp
示例7: MakeInstance
JSObjectRef MakeInstance (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
size_t length = 1;
if (argumentCount > 0)
{
*exception = nullptr;
if (!JSValueIsNumber(ctx,arguments[0]))
{
JSStringRef string = JSStringCreateWithUTF8CString("required first argument to be a number which is the size of the buffer requested");
JSValueRef message = JSValueMakeString(ctx, string);
JSStringRelease(string);
*exception = JSObjectMakeError(ctx, 1, &message, 0);
return nullptr;
}
length = JSValueToNumber(ctx, arguments[0], exception);
CHECK_BUF_EXCEPTION(nullptr);
}
JSBuffer *buffer = (JSBuffer *)malloc(sizeof(JSBuffer));
buffer->buffer = malloc(length);
buffer->length = length;
buffer->type = JSBufferTypePointer;
memset(buffer->buffer, 0, length);
// by default, let's set the value to NAN
float *p = (float*)buffer->buffer;
p[0] = NAN;
JSObjectRef object = MakeObjectForJSBuffer(ctx,buffer);
return object;
}
开发者ID:pec1985,项目名称:hyperloop,代码行数:28,代码来源:JSBuffer.cpp
示例8: continuousMouseScrollBy
static JSValueRef continuousMouseScrollBy(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
return JSValueMakeUndefined(context);
double deltaX = JSValueToNumber(context, arguments[0], exception);
double deltaY = 0;
if (argumentCount >= 2)
deltaY = JSValueToNumber(context, arguments[1], exception);
mouseScrollBy(deltaX, deltaY, true);
return JSValueMakeUndefined(context);
}
开发者ID:Comcast,项目名称:WebKitForWayland,代码行数:16,代码来源:EventSender.cpp
示例9: lengthPropertyName
bool TestRunner::findString(JSContextRef context, JSStringRef string, JSObjectRef optionsArray)
{
JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length"));
JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0);
if (!JSValueIsNumber(context, lengthValue))
return false;
QWebPage::FindFlags findFlags = QWebPage::FindCaseSensitively;
int length = static_cast<int>(JSValueToNumber(context, lengthValue, 0));
for (int i = 0; i < length; ++i) {
JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0);
if (!JSValueIsString(context, value))
continue;
JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0));
if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive"))
findFlags &= ~QWebPage::FindCaseSensitively;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts"))
findFlags |= QWebPage::FindAtWordBeginningsOnly;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart"))
findFlags |= QWebPage::TreatMedialCapitalAsWordBeginning;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards"))
findFlags |= QWebPage::FindBackward;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround"))
findFlags |= QWebPage::FindWrapsAroundDocument;
else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection"))
findFlags |= QWebPage::FindBeginsInSelection;
}
DumpRenderTree* drt = DumpRenderTree::instance();
return drt->webPage()->findText(JSStringCopyQString(string), findFlags);
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:33,代码来源:TestRunnerQt.cpp
示例10: JSObjectGetProperty
unsigned JSArray::length() {
JSValueRef val = JSObjectGetProperty(ctx_, instance_, JSString("length"), nullptr);
if (JSValueIsNumber(ctx_, val))
return static_cast<unsigned>(JSValueToNumber(ctx_, val, nullptr));
return 0;
}
开发者ID:FinnProjects,项目名称:ultralight,代码行数:7,代码来源:JSHelpers.cpp
示例11: function_set_exit_value
JSValueRef function_set_exit_value(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef* exception) {
if (argc == 1 && JSValueGetType (ctx, args[0]) == kJSTypeNumber) {
exit_value = JSValueToNumber(ctx, args[0], NULL);
}
return JSValueMakeNull(ctx);
}
开发者ID:gsnewmark,项目名称:planck,代码行数:7,代码来源:main.c
示例12: function_file_output_stream_write
JSValueRef function_file_output_stream_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef *exception) {
if (argc == 2
&& JSValueGetType(ctx, args[0]) == kJSTypeString
&& JSValueGetType(ctx, args[1]) == kJSTypeObject) {
char *descriptor = value_to_c_string(ctx, args[0]);
unsigned int count = (unsigned int) array_get_count(ctx, (JSObjectRef) args[1]);
uint8_t buf[count];
for (unsigned int i = 0; i < count; i++) {
JSValueRef v = array_get_value_at_index(ctx, (JSObjectRef) args[1], i);
if (JSValueIsNumber(ctx, v)) {
double n = JSValueToNumber(ctx, v, NULL);
if (0 <= n && n <= 255) {
buf[i] = (uint8_t) n;
} else {
fprintf(stderr, "Output stream value out of range %f", n);
}
} else {
fprintf(stderr, "Output stream value not a number");
}
}
file_write(descriptor_str_to_int(descriptor), count, buf);
free(descriptor);
}
return JSValueMakeNull(ctx);
}
开发者ID:mfikes,项目名称:planck,代码行数:31,代码来源:functions.c
示例13: mouseMoveToCallback
static JSValueRef mouseMoveToCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
if (!view)
return JSValueMakeUndefined(context);
if (argumentCount < 2)
return JSValueMakeUndefined(context);
lastMousePositionX = (int)JSValueToNumber(context, arguments[0], exception);
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
lastMousePositionY = (int)JSValueToNumber(context, arguments[1], exception);
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
GdkEvent event;
memset(&event, 0, sizeof(event));
event.type = GDK_MOTION_NOTIFY;
event.motion.x = lastMousePositionX;
event.motion.y = lastMousePositionY;
event.motion.time = GDK_CURRENT_TIME;
event.motion.window = GTK_WIDGET(view)->window;
event.motion.device = gdk_device_get_core_pointer();
int x_root, y_root;
#if GTK_CHECK_VERSION(2,17,3)
gdk_window_get_root_coords(GTK_WIDGET(view)->window, lastMousePositionX, lastMousePositionY, &x_root, &y_root);
#else
getRootCoords(GTK_WIDGET(view), &x_root, &y_root);
#endif
event.motion.x_root = x_root;
event.motion.y_root = y_root;
event.motion.state = getStateFlags();
if (dragMode && down && !replayingSavedEvents) {
msgQueue[endOfQueue].event = event;
msgQueue[endOfQueue++].isDragEvent = true;
} else {
webkit_web_frame_layout(mainFrame);
gboolean return_val;
g_signal_emit_by_name(view, "motion_notify_event", &event, &return_val);
}
return JSValueMakeUndefined(context);
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:47,代码来源:EventSender.cpp
示例14: childAtIndexCallback
static JSValueRef childAtIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
int indexNumber = -1;
if (argumentCount == 1)
indexNumber = JSValueToNumber(context, arguments[0], exception);
return AccessibilityUIElement::makeJSAccessibilityUIElement(context, toAXElement(thisObject)->getChildAtIndex(indexNumber));
}
开发者ID:acss,项目名称:owb-mirror,代码行数:8,代码来源:AccessibilityUIElement.cpp
示例15: arrayLength
static unsigned arrayLength(JSContextRef context, JSObjectRef array)
{
JSRetainPtr<JSStringRef> lengthString(Adopt, JSStringCreateWithUTF8CString("length"));
JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0);
if (!lengthValue)
return 0;
return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0));
}
开发者ID:sanyaade-webdev,项目名称:webkit,代码行数:8,代码来源:EventSendingController.cpp
示例16: lineForIndexCallback
static JSValueRef lineForIndexCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
int indexNumber = -1;
if (argumentCount == 1)
indexNumber = JSValueToNumber(context, arguments[0], exception);
return JSValueMakeNumber(context, toAXElement(thisObject)->lineForIndex(indexNumber));
}
开发者ID:acss,项目名称:owb-mirror,代码行数:8,代码来源:AccessibilityUIElement.cpp
示例17: mouseWheelToCallback
static JSValueRef mouseWheelToCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
if (!view)
return JSValueMakeUndefined(context);
if (argumentCount < 2)
return JSValueMakeUndefined(context);
int horizontal = (int)JSValueToNumber(context, arguments[0], exception);
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
int vertical = (int)JSValueToNumber(context, arguments[1], exception);
g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
// GTK+ doesn't support multiple direction scrolls in the same event!
g_return_val_if_fail((!vertical || !horizontal), JSValueMakeUndefined(context));
GdkEvent event;
event.type = GDK_SCROLL;
event.scroll.x = lastMousePositionX;
event.scroll.y = lastMousePositionY;
event.scroll.time = GDK_CURRENT_TIME;
event.scroll.window = GTK_WIDGET(view)->window;
if (horizontal < 0)
event.scroll.direction = GDK_SCROLL_LEFT;
else if (horizontal > 0)
event.scroll.direction = GDK_SCROLL_RIGHT;
else if (vertical < 0)
event.scroll.direction = GDK_SCROLL_UP;
else if (vertical > 0)
event.scroll.direction = GDK_SCROLL_DOWN;
else
g_assert_not_reached();
if (dragMode && down && !replayingSavedEvents) {
msgQueue[endOfQueue].event = event;
msgQueue[endOfQueue++].isDragEvent = true;
} else {
webkit_web_frame_layout(mainFrame);
gtk_main_do_event(&event);
}
return JSValueMakeUndefined(context);
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:45,代码来源:EventSender.cpp
示例18: leapForwardCallback
static JSValueRef leapForwardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount > 0) {
msgQueue[endOfQueue].delay = JSValueToNumber(context, arguments[0], exception);
ASSERT(!exception || !*exception);
}
return JSValueMakeUndefined(context);
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:9,代码来源:EventSender.cpp
示例19: JSStringCreateWithUTF8CString
size_t ArrayWrapper::GetSize()
{
JSStringRef strLength = JSStringCreateWithUTF8CString("length");
JSValueRef valLength = JSObjectGetProperty(g_ctx, m_arr, strLength, NULL);
size_t len = (size_t) JSValueToNumber(g_ctx, valLength, NULL);
JSStringRelease(strLength);
return len;
}
开发者ID:vnmc,项目名称:zephyros,代码行数:9,代码来源:jsbridge_webview.cpp
示例20: if
JSValueRef JSCArrayBuffer::sliceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {
struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj);
if (false) {
} else if (argumentCount == 2 &&
JSValueIsNumber(ctx, arguments[0]) &&
JSValueIsNumber(ctx, arguments[1])) {
long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);
long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception);
uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd));
JSClassRef retClass = JSCArrayBuffer::getTmpl();
struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
retPrivData->dom = privData->dom;
retPrivData->nativeObj = retVal;
JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
return retObj;
} else if (argumentCount == 1 &&
JSValueIsNumber(ctx, arguments[0])) {
long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception);
uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin));
JSClassRef retClass = JSCArrayBuffer::getTmpl();
struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate();
retPrivData->dom = privData->dom;
retPrivData->nativeObj = retVal;
JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
return retObj;
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling slice");
*exception = JSValueMakeString(ctx, exceptionString);
JSStringRelease(exceptionString);
return JSValueMakeUndefined(ctx);
}
开发者ID:bjqiwei,项目名称:uscxml,代码行数:44,代码来源:JSCArrayBuffer.cpp
注:本文中的JSValueToNumber函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论