加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 业界 > 正文

Safari信息泄漏裂痕说明

发布时间:2018-11-05 02:39:21 所属栏目:业界 来源:Alpha_h4ck
导读:媒介 Javascript中的数组和数组工具一向都是编程职员优化的首要方针,一样平常来说,数组只会包括一些根基范例数据,好比说32位整数或字符等等。因此,每个引擎城市对这些工具举办某些优化,并晋升差异元素范例的会见速率和麋集型暗示。 在JavaScriptCore中,J
副问题[/!--empirenews.page--]

媒介

Javascript中的数组和数组工具一向都是编程职员优化的首要方针,一样平常来说,数组只会包括一些根基范例数据,好比说32位整数或字符等等。因此,每个引擎城市对这些工具举办某些优化,并晋升差异元素范例的会见速率和麋集型暗示。

Safari信息泄漏裂痕说明

在JavaScriptCore中,JavaScript引擎是在WebKit中实现的,个中每一个存储在工具中的元素都代表着一个IndexingType值,一个8位整数代表一套Flag组合,详细的参数界说可以在IndexingType.h中找到。接下来,引擎会检测一个工具中indexing的范例,然后抉择行使哪一条快速路径,个中最重要的一种indexing范例就是ArrayWithUndecided,它暗示的是全部元素均为未界说(undefined),并且没有存储任何现实的值。在这种环境下,引擎为了晋升机能,会让这些元素保持未初始化。

说明

下面,我们一路看一看旧版本中实现Array.prototype.concat的代码(ArrayPrototype.cpp):

  1. EncodedJSValueJSC_HOST_CALL arrayProtoPrivateFuncConcatMemcpy(ExecState* exec)  
  2. {  
  3.     ...  
  4.     unsigned resultSize =checkedResultSize.unsafeGet();  
  5.     IndexingType firstType =firstArray->indexingType();  
  6.     IndexingType secondType =secondArray->indexingType();  
  7.     IndexingType type =firstArray->mergeIndexingTypeForCopying(secondType); // [[ 1 ]]  
  8.     if (type == NonArray ||!firstArray->canFastCopy(vm, secondArray) || resultSize >=MIN_SPARSE_ARRAY_INDEX) {  
  9.         ...  
  10.     }  
  11.     JSGlobalObject* lexicalGlobalObject =exec->lexicalGlobalObject();  
  12.     Structure* resultStructure =lexicalGlobalObject->arrayStructureForIndexingTypeDuringAllocation(type);  
  13.     if(UNLIKELY(hasAnyArrayStorage(resultStructure->indexingType())))  
  14.         return JSValue::encode(jsNull());  
  15.    ASSERT(!lexicalGlobalObject->isHavingABadTime());  
  16.     ObjectInitializationScopeinitializationScope(vm);  
  17.     JSArray* result =JSArray::tryCreateUninitializedRestricted(initializationScope, resultStructure,resultSize);  
  18.     if (UNLIKELY(!result)) {  
  19.         throwOutOfMemoryError(exec, scope);  
  20.         return encodedJSValue();  
  21.     }  
  22.     if (type == ArrayWithDouble) {  
  23.         [[ 2 ]]  
  24.         double* buffer =result->butterfly()->contiguousDouble().data();  
  25.         memcpy(buffer,firstButterfly->contiguousDouble().data(), sizeof(JSValue) *firstArraySize);  
  26.         memcpy(buffer + firstArraySize,secondButterfly->contiguousDouble().data(), sizeof(JSValue) *secondArraySize);  
  27.     } else if (type != ArrayWithUndecided) {  
  28. ... 

这个函数首要用来判定功效数组[[1]]的indexing范例,我们可以看到,假如indexing范例为ArrayWithDouble,它将会选择[[2]]作为快速路径。接下来,我们看一看:

mergeIndexingTypeForCopying的实当代码,这个函数首要认真在Array.prototype.concat被挪用时,判定功效数组的indexing范例:

  1. inlineIndexingType JSArray::mergeIndexingTypeForCopying(IndexingType other)  
  2. {  
  3.     IndexingType type = indexingType();  
  4.     if (!(type & IsArray && other& IsArray))  
  5.         return NonArray;  
  6.     if (hasAnyArrayStorage(type) ||hasAnyArrayStorage(other))  
  7.         return NonArray;  
  8.     if (type == ArrayWithUndecided)  
  9.         return other; [[ 3 ]]  
  10. ... 

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读